forked from mitmproxy/mitmproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] Add tests for js/components/common/FileChooser.jsx & minor fix.
- Loading branch information
1 parent
9a7ac14
commit 782d564
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import FileChooser from '../../../components/common/FileChooser' | ||
|
||
describe('FileChooser Component', () => { | ||
let openFileFunc = jest.fn(), | ||
createNodeMock = () => { return { click: jest.fn() } }, | ||
fileChooser = renderer.create( | ||
<FileChooser className="foo" title="bar" onOpenFile={ openFileFunc }/> | ||
, { createNodeMock }) | ||
//[test refs with react-test-renderer](https://github.com/facebook/react/issues/7371) | ||
|
||
it('should render correctly', () => { | ||
let tree = fileChooser.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('should handle click action', () => { | ||
let tree = fileChooser.toJSON(), | ||
mockEvent = { | ||
preventDefault: jest.fn(), | ||
target: { | ||
files: [ "foo", "bar" ] | ||
} | ||
} | ||
tree.children[1].props.onChange(mockEvent) | ||
expect(openFileFunc).toBeCalledWith("foo") | ||
tree.props.onClick() | ||
// without files | ||
mockEvent = { | ||
...mockEvent, | ||
target: { files: [ ]} | ||
} | ||
openFileFunc.mockClear() | ||
tree.children[1].props.onChange(mockEvent) | ||
expect(openFileFunc).not.toBeCalled() | ||
}) | ||
}) |
19 changes: 19 additions & 0 deletions
19
web/src/js/__tests__/components/common/__snapshots__/FileChooserSpec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FileChooser Component should render correctly 1`] = ` | ||
<a | ||
className="foo" | ||
href="#" | ||
onClick={[Function]} | ||
title="bar" | ||
> | ||
<i | ||
className="fa fa-fw undefined" | ||
/> | ||
<input | ||
className="hidden" | ||
onChange={[Function]} | ||
type="file" | ||
/> | ||
</a> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters