diff --git a/web/src/js/__tests__/components/EventLog/EventListSpec.js b/web/src/js/__tests__/components/EventLog/EventListSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/EventLog/EventListSpec.js rename to web/src/js/__tests__/components/EventLog/EventListSpec.tsx diff --git a/web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.js.snap b/web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.js.snap rename to web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.tsx.snap diff --git a/web/src/js/__tests__/components/FlowTable/FlowTableHeadSpec.js b/web/src/js/__tests__/components/FlowTable/FlowTableHeadSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/FlowTable/FlowTableHeadSpec.js rename to web/src/js/__tests__/components/FlowTable/FlowTableHeadSpec.tsx diff --git a/web/src/js/__tests__/components/FlowTable/__snapshots__/FlowTableHeadSpec.js.snap b/web/src/js/__tests__/components/FlowTable/__snapshots__/FlowTableHeadSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/FlowTable/__snapshots__/FlowTableHeadSpec.js.snap rename to web/src/js/__tests__/components/FlowTable/__snapshots__/FlowTableHeadSpec.tsx.snap diff --git a/web/src/js/__tests__/components/Header/FileMenuSpec.js b/web/src/js/__tests__/components/Header/FileMenuSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/Header/FileMenuSpec.js rename to web/src/js/__tests__/components/Header/FileMenuSpec.tsx diff --git a/web/src/js/__tests__/components/Header/FilterDocsSpec.js b/web/src/js/__tests__/components/Header/FilterDocsSpec.js deleted file mode 100644 index 697bffcc4..000000000 --- a/web/src/js/__tests__/components/Header/FilterDocsSpec.js +++ /dev/null @@ -1,18 +0,0 @@ -import * as React from "react" -import renderer from 'react-test-renderer' -import FilterDocs from '../../../components/Header/FilterDocs' - -describe('FilterDocs Component', () => { - let mockResponse = { json: - () => { return { commands: [['cmd1', 'foo'], ['cmd2', 'bar']]}} - }, - promise = Promise.resolve(mockResponse) - global.fetch = r => { return promise } - - let filterDocs = renderer.create(), - tree = filterDocs.toJSON() - - it('should render correctly when fetch success', () => { - expect(tree).toMatchSnapshot() - }) -}) diff --git a/web/src/js/__tests__/components/Header/FilterDocsSpec.tsx b/web/src/js/__tests__/components/Header/FilterDocsSpec.tsx new file mode 100644 index 000000000..4feff94be --- /dev/null +++ b/web/src/js/__tests__/components/Header/FilterDocsSpec.tsx @@ -0,0 +1,20 @@ +import * as React from "react" +import FilterDocs from '../../../components/Header/FilterDocs' +import {enableFetchMocks} from "jest-fetch-mock"; +import {render, screen, waitFor} from "../../test-utils"; + +enableFetchMocks(); + +test("FilterDocs Component", async () => { + + fetchMock.mockOnceIf("./filter-help", JSON.stringify({ + commands: [['cmd1', 'foo'], ['cmd2', 'bar']] + })) + + const {asFragment} = render( 0}/>); + + expect(asFragment()).toMatchSnapshot(); + await waitFor(() => screen.getByText("cmd1")); + expect(asFragment()).toMatchSnapshot(); + +}) diff --git a/web/src/js/__tests__/components/Header/FilterInputSpec.js b/web/src/js/__tests__/components/Header/FilterInputSpec.tsx similarity index 93% rename from web/src/js/__tests__/components/Header/FilterInputSpec.js rename to web/src/js/__tests__/components/Header/FilterInputSpec.tsx index f5d94e600..9dc324cdb 100644 --- a/web/src/js/__tests__/components/Header/FilterInputSpec.js +++ b/web/src/js/__tests__/components/Header/FilterInputSpec.tsx @@ -4,11 +4,12 @@ import FilterInput from '../../../components/Header/FilterInput' import FilterDocs from '../../../components/Header/FilterDocs' import TestUtil from 'react-dom/test-utils' import ReactDOM from 'react-dom' -import { Key } from '../../../utils' describe('FilterInput Component', () => { it('should render correctly', () => { - let filterInput = renderer.create(), + let filterInput = renderer.create( + undefined} value="42"/> + ), tree = filterInput.toJSON() expect(tree).toMatchSnapshot() }) @@ -69,7 +70,7 @@ describe('FilterInput Component', () => { it('should handle keyDown', () => { input.blur = jest.fn() let mockEvent = { - keyCode: Key.ESC, + key: "Escape", stopPropagation: jest.fn() } filterInput.onKeyDown(mockEvent) diff --git a/web/src/js/__tests__/components/Header/MainMenuSpec.js b/web/src/js/__tests__/components/Header/MainMenuSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/Header/MainMenuSpec.js rename to web/src/js/__tests__/components/Header/MainMenuSpec.tsx diff --git a/web/src/js/__tests__/components/Header/MenuToggleSpec.js b/web/src/js/__tests__/components/Header/MenuToggleSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/Header/MenuToggleSpec.js rename to web/src/js/__tests__/components/Header/MenuToggleSpec.tsx diff --git a/web/src/js/__tests__/components/Header/OptionMenuSpec.js b/web/src/js/__tests__/components/Header/OptionMenuSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/Header/OptionMenuSpec.js rename to web/src/js/__tests__/components/Header/OptionMenuSpec.tsx diff --git a/web/src/js/__tests__/components/Header/__snapshots__/FileMenuSpec.js.snap b/web/src/js/__tests__/components/Header/__snapshots__/FileMenuSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/Header/__snapshots__/FileMenuSpec.js.snap rename to web/src/js/__tests__/components/Header/__snapshots__/FileMenuSpec.tsx.snap diff --git a/web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.js.snap b/web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.js.snap deleted file mode 100644 index cd0c9ddab..000000000 --- a/web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`FilterDocs Component should render correctly when fetch success 1`] = ` - -`; diff --git a/web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.tsx.snap b/web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.tsx.snap new file mode 100644 index 000000000..b573d8b51 --- /dev/null +++ b/web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.tsx.snap @@ -0,0 +1,51 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FilterDocs Component 1`] = ` + + + +`; + +exports[`FilterDocs Component 2`] = ` + + + + + + + + + + + + + + + +
+ cmd1 + + foo +
+ cmd2 + + bar +
+ + +   mitmproxy docs + +
+
+`; diff --git a/web/src/js/__tests__/components/Header/__snapshots__/FilterInputSpec.js.snap b/web/src/js/__tests__/components/Header/__snapshots__/FilterInputSpec.tsx.snap similarity index 97% rename from web/src/js/__tests__/components/Header/__snapshots__/FilterInputSpec.js.snap rename to web/src/js/__tests__/components/Header/__snapshots__/FilterInputSpec.tsx.snap index 2afe05f16..b668521d8 100644 --- a/web/src/js/__tests__/components/Header/__snapshots__/FilterInputSpec.js.snap +++ b/web/src/js/__tests__/components/Header/__snapshots__/FilterInputSpec.tsx.snap @@ -24,6 +24,7 @@ exports[`FilterInput Component should render correctly 1`] = ` onKeyDown={[Function]} placeholder="bar" type="text" + value="42" /> `; diff --git a/web/src/js/__tests__/components/Header/__snapshots__/MainMenuSpec.js.snap b/web/src/js/__tests__/components/Header/__snapshots__/MainMenuSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/Header/__snapshots__/MainMenuSpec.js.snap rename to web/src/js/__tests__/components/Header/__snapshots__/MainMenuSpec.tsx.snap diff --git a/web/src/js/__tests__/components/Header/__snapshots__/MenuToggleSpec.js.snap b/web/src/js/__tests__/components/Header/__snapshots__/MenuToggleSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/Header/__snapshots__/MenuToggleSpec.js.snap rename to web/src/js/__tests__/components/Header/__snapshots__/MenuToggleSpec.tsx.snap diff --git a/web/src/js/__tests__/components/Header/__snapshots__/OptionMenuSpec.js.snap b/web/src/js/__tests__/components/Header/__snapshots__/OptionMenuSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/Header/__snapshots__/OptionMenuSpec.js.snap rename to web/src/js/__tests__/components/Header/__snapshots__/OptionMenuSpec.tsx.snap diff --git a/web/src/js/__tests__/components/Modal/OptionModalSpec.js b/web/src/js/__tests__/components/Modal/OptionModalSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/Modal/OptionModalSpec.js rename to web/src/js/__tests__/components/Modal/OptionModalSpec.tsx diff --git a/web/src/js/__tests__/components/Modal/OptionSpec.js b/web/src/js/__tests__/components/Modal/OptionSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/Modal/OptionSpec.js rename to web/src/js/__tests__/components/Modal/OptionSpec.tsx diff --git a/web/src/js/__tests__/components/Modal/__snapshots__/OptionModalSpec.js.snap b/web/src/js/__tests__/components/Modal/__snapshots__/OptionModalSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/Modal/__snapshots__/OptionModalSpec.js.snap rename to web/src/js/__tests__/components/Modal/__snapshots__/OptionModalSpec.tsx.snap diff --git a/web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.js.snap b/web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.tsx.snap similarity index 100% rename from web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.js.snap rename to web/src/js/__tests__/components/Modal/__snapshots__/OptionSpec.tsx.snap diff --git a/web/src/js/__tests__/components/common/ButtonSpec.js b/web/src/js/__tests__/components/common/ButtonSpec.tsx similarity index 95% rename from web/src/js/__tests__/components/common/ButtonSpec.js rename to web/src/js/__tests__/components/common/ButtonSpec.tsx index 898e1e5af..661b4d553 100644 --- a/web/src/js/__tests__/components/common/ButtonSpec.js +++ b/web/src/js/__tests__/components/common/ButtonSpec.tsx @@ -16,7 +16,7 @@ describe('Button Component', () => { it('should be able to be disabled', () => { let button = renderer.create( - ), diff --git a/web/src/js/__tests__/components/common/DocsLinkSpec.js b/web/src/js/__tests__/components/common/DocsLinkSpec.tsx similarity index 100% rename from web/src/js/__tests__/components/common/DocsLinkSpec.js rename to web/src/js/__tests__/components/common/DocsLinkSpec.tsx diff --git a/web/src/js/__tests__/components/common/SplitterSpec.js b/web/src/js/__tests__/components/common/SplitterSpec.tsx similarity index 82% rename from web/src/js/__tests__/components/common/SplitterSpec.js rename to web/src/js/__tests__/components/common/SplitterSpec.tsx index f781f9ad5..f2adffe7a 100644 --- a/web/src/js/__tests__/components/common/SplitterSpec.js +++ b/web/src/js/__tests__/components/common/SplitterSpec.tsx @@ -7,12 +7,12 @@ import TestUtils from 'react-dom/test-utils'; describe('Splitter Component', () => { it('should render correctly', () => { - let splitter = renderer.create(), + let splitter = renderer.create(), tree = splitter.toJSON() expect(tree).toMatchSnapshot() }) - let splitter = TestUtils.renderIntoDocument(), + let splitter = TestUtils.renderIntoDocument(), dom = ReactDOM.findDOMNode(splitter), previousElementSibling = { offsetHeight: 0, @@ -25,7 +25,7 @@ describe('Splitter Component', () => { it('should handle mouseDown ', () => { window.addEventListener = jest.fn() - splitter.onMouseDown({ pageX: 1, pageY: 2}) + splitter.onMouseDown({pageX: 1, pageY: 2}) expect(splitter.state.startX).toEqual(1) expect(splitter.state.startY).toEqual(2) expect(window.addEventListener).toBeCalledWith('mousemove', splitter.onMouseMove) @@ -44,9 +44,9 @@ describe('Splitter Component', () => { it('should handle mouseUp', () => { - Object.defineProperty(dom, 'previousElementSibling', { value: previousElementSibling }) - Object.defineProperty(dom, 'nextElementSibling', { value: nextElementSibling }) - splitter.onMouseUp({ pageX: 3, pageY: 4 }) + Object.defineProperty(dom, 'previousElementSibling', {value: previousElementSibling}) + Object.defineProperty(dom, 'nextElementSibling', {value: nextElementSibling}) + splitter.onMouseUp({pageX: 3, pageY: 4}) expect(splitter.state.applied).toBeTruthy() expect(nextElementSibling.style.flex).toEqual('1 1 auto') expect(previousElementSibling.style.flex).toEqual('0 0 2px') @@ -56,15 +56,15 @@ describe('Splitter Component', () => { splitter.onMouseMove({pageX: 10, pageY: 10}) expect(dom.style.transform).toEqual("translate(9px, 0px)") - let splitterY = TestUtils.renderIntoDocument() + let splitterY = TestUtils.renderIntoDocument() splitterY.onMouseMove({pageX: 10, pageY: 10}) expect(ReactDOM.findDOMNode(splitterY).style.transform).toEqual("translate(0px, 10px)") }) it('should handle resize', () => { - window.setTimeout = jest.fn((event, time) => event()) + let x = jest.spyOn(window, 'setTimeout'); splitter.onResize() - expect(window.setTimeout).toHaveBeenCalled() + expect(x).toHaveBeenCalled() }) it('should handle componentWillUnmount', () => { diff --git a/web/src/js/__tests__/components/common/ToggleButtonSpec.js b/web/src/js/__tests__/components/common/ToggleButtonSpec.tsx similarity index 84% rename from web/src/js/__tests__/components/common/ToggleButtonSpec.js rename to web/src/js/__tests__/components/common/ToggleButtonSpec.tsx index 2fed0b378..23378f539 100644 --- a/web/src/js/__tests__/components/common/ToggleButtonSpec.js +++ b/web/src/js/__tests__/components/common/ToggleButtonSpec.tsx @@ -7,18 +7,14 @@ describe('ToggleButton Component', () => { it('should render correctly', () => { let checkedButton = renderer.create( - - text - ), + ), tree = checkedButton.toJSON() expect(tree).toMatchSnapshot() }) it('should handle click action', () => { let uncheckButton = renderer.create( - - text - ), + ), tree = uncheckButton.toJSON() tree.props.onClick() expect(mockFunc).toBeCalled() diff --git a/web/src/js/__tests__/components/common/ToggleInputButtonSpec.js b/web/src/js/__tests__/components/common/ToggleInputButtonSpec.js deleted file mode 100644 index 7d6d96282..000000000 --- a/web/src/js/__tests__/components/common/ToggleInputButtonSpec.js +++ /dev/null @@ -1,43 +0,0 @@ -import * as React from "react" -import renderer from 'react-test-renderer' -import ToggleInputButton from '../../../components/common/ToggleInputButton' -import { Key } from '../../../utils' - -describe('ToggleInputButton Component', () => { - let mockFunc = jest.fn(), - toggleInputButton = undefined, - tree = undefined - - it('should render correctly', () => { - toggleInputButton = renderer.create( - text) - tree = toggleInputButton.toJSON() - expect(tree).toMatchSnapshot() - }) - - it('should handle keydown and click action', () => { - toggleInputButton = renderer.create( - text) - tree = toggleInputButton.toJSON() - let mockEvent = { - keyCode: Key.ENTER, - stopPropagation: jest.fn() - } - - tree.children[1].props.onKeyDown(mockEvent) - expect(mockFunc).toBeCalledWith("txt") - - tree.children[0].props.onClick() - expect(mockFunc).toBeCalledWith("txt") - }) - - it('should update state onChange', () => { - // trigger onChange - tree.children[1].props.onChange({ target: { value: "foo" }}) - // update the tree - tree = toggleInputButton.toJSON() - expect(tree.children[1].props.value).toEqual("foo") - }) -}) diff --git a/web/src/js/__tests__/components/common/__snapshots__/ButtonSpec.js.snap b/web/src/js/__tests__/components/common/__snapshots__/ButtonSpec.tsx.snap similarity index 95% rename from web/src/js/__tests__/components/common/__snapshots__/ButtonSpec.js.snap rename to web/src/js/__tests__/components/common/__snapshots__/ButtonSpec.tsx.snap index 0fe239b6f..ea5dcb27b 100644 --- a/web/src/js/__tests__/components/common/__snapshots__/ButtonSpec.js.snap +++ b/web/src/js/__tests__/components/common/__snapshots__/ButtonSpec.tsx.snap @@ -3,7 +3,7 @@ exports[`Button Component should be able to be disabled 1`] = `