-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2365 from MatthewShao/jest-dev
[WIP][web] Add tests for components/ContentView
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
web/src/js/__tests__/components/ContentView/CodeEditorSpec.js
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,26 @@ | ||
jest.mock('react-codemirror') | ||
import React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import CodeEditor from '../../../components/ContentView/CodeEditor' | ||
|
||
describe('CodeEditor Component', () => { | ||
let content = "foo content", | ||
changeFn = jest.fn(), | ||
codeEditor = renderer.create( | ||
<CodeEditor content={content} onChange={changeFn}/> | ||
), | ||
tree = codeEditor.toJSON() | ||
|
||
it('should render correctly', () => { | ||
// This actually does not render properly, but getting a full CodeMirror rendering | ||
// is cumbersome. This is hopefully good enough. | ||
// see: https://github.com/mitmproxy/mitmproxy/pull/2365#discussion_r119766850 | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('should handle key down', () => { | ||
let mockEvent = { stopPropagation: jest.fn() } | ||
tree.props.onKeyDown(mockEvent) | ||
expect(mockEvent.stopPropagation).toBeCalled() | ||
}) | ||
}) |
20 changes: 20 additions & 0 deletions
20
web/src/js/__tests__/components/ContentView/ContentViewOptionsSpec.js
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,20 @@ | ||
import React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import ContentViewOptions from '../../../components/ContentView/ContentViewOptions' | ||
import { Provider } from 'react-redux' | ||
import { TFlow, TStore } from '../../ducks/tutils' | ||
import { uploadContent } from '../../../ducks/flows' | ||
|
||
let tflow = new TFlow() | ||
|
||
describe('ContentViewOptions Component', () => { | ||
let store = TStore() | ||
it('should render correctly', () => { | ||
let provider = renderer.create( | ||
<Provider store={store}> | ||
<ContentViewOptions flow={tflow} message={tflow.response} uploadContent={uploadContent}/> | ||
</Provider>), | ||
tree = provider.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
}) |
8 changes: 8 additions & 0 deletions
8
web/src/js/__tests__/components/ContentView/__snapshots__/CodeEditorSpec.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,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CodeEditor Component should render correctly 1`] = ` | ||
<div | ||
className="codeeditor" | ||
onKeyDown={[Function]} | ||
/> | ||
`; |
41 changes: 41 additions & 0 deletions
41
web/src/js/__tests__/components/ContentView/__snapshots__/ContentViewOptionsSpec.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,41 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ContentViewOptions Component should render correctly 1`] = ` | ||
<div | ||
className="view-options" | ||
> | ||
<span> | ||
<b> | ||
View: | ||
</b> | ||
edit | ||
</span> | ||
<a | ||
className="btn btn-default btn-xs" | ||
href="/flows/d91165be-ca1f-4612-88a9-c0f8696f3e29/response/content" | ||
title="Download the content of the flow." | ||
> | ||
<i | ||
className="fa fa-download" | ||
/> | ||
</a> | ||
<a | ||
className="btn btn-default btn-xs" | ||
href="#" | ||
onClick={[Function]} | ||
title="Upload a file to replace the content." | ||
> | ||
<i | ||
className="fa fa-fw fa-upload" | ||
/> | ||
<input | ||
className="hidden" | ||
onChange={[Function]} | ||
type="file" | ||
/> | ||
</a> | ||
</div> | ||
`; |