From 3589ec2f583febe98c5aae52ebf0c4ed5024c1d9 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 23 Aug 2021 11:01:43 +0200 Subject: [PATCH] web: convert everything to TypeScript --- .../{EventListSpec.js => EventListSpec.tsx} | 0 ...istSpec.js.snap => EventListSpec.tsx.snap} | 0 ...TableHeadSpec.js => FlowTableHeadSpec.tsx} | 0 ...pec.js.snap => FlowTableHeadSpec.tsx.snap} | 0 .../{FileMenuSpec.js => FileMenuSpec.tsx} | 0 .../components/Header/FilterDocsSpec.js | 18 -- .../components/Header/FilterDocsSpec.tsx | 20 ++ ...FilterInputSpec.js => FilterInputSpec.tsx} | 7 +- .../{MainMenuSpec.js => MainMenuSpec.tsx} | 0 .../{MenuToggleSpec.js => MenuToggleSpec.tsx} | 0 .../{OptionMenuSpec.js => OptionMenuSpec.tsx} | 0 ...MenuSpec.js.snap => FileMenuSpec.tsx.snap} | 0 .../__snapshots__/FilterDocsSpec.js.snap | 7 - .../__snapshots__/FilterDocsSpec.tsx.snap | 51 +++++ ...tSpec.js.snap => FilterInputSpec.tsx.snap} | 1 + ...MenuSpec.js.snap => MainMenuSpec.tsx.snap} | 0 ...leSpec.js.snap => MenuToggleSpec.tsx.snap} | 0 ...nuSpec.js.snap => OptionMenuSpec.tsx.snap} | 0 ...OptionModalSpec.js => OptionModalSpec.tsx} | 0 .../Modal/{OptionSpec.js => OptionSpec.tsx} | 0 ...lSpec.js.snap => OptionModalSpec.tsx.snap} | 0 ...OptionSpec.js.snap => OptionSpec.tsx.snap} | 0 .../common/{ButtonSpec.js => ButtonSpec.tsx} | 2 +- .../{DocsLinkSpec.js => DocsLinkSpec.tsx} | 0 .../{SplitterSpec.js => SplitterSpec.tsx} | 18 +- ...ggleButtonSpec.js => ToggleButtonSpec.tsx} | 8 +- .../common/ToggleInputButtonSpec.js | 43 ---- ...ButtonSpec.js.snap => ButtonSpec.tsx.snap} | 2 +- ...LinkSpec.js.snap => DocsLinkSpec.tsx.snap} | 0 ...tterSpec.js.snap => SplitterSpec.tsx.snap} | 0 ...Spec.js.snap => ToggleButtonSpec.tsx.snap} | 0 .../ToggleInputButtonSpec.js.snap | 31 --- .../{AutoScrollSpec.js => AutoScrollSpec.tsx} | 0 ...ualScrollSpec.js => VirtualScrollSpec.tsx} | 2 +- .../{connectionSpec.js => connectionSpec.tsx} | 2 +- .../{eventLogSpec.js => eventLogSpec.tsx} | 0 .../ducks/{indexSpec.js => indexSpec.tsx} | 2 +- .../ducks/ui/{indexSpec.js => indexSpec.tsx} | 2 +- web/src/js/__tests__/ducks/ui/keyboardSpec.js | 164 --------------- .../js/__tests__/ducks/ui/keyboardSpec.tsx | 166 ++++++++++++++++ .../ducks/ui/{modalSpec.js => modalSpec.tsx} | 5 +- ...tionEditorSpec.js => optionEditorSpec.tsx} | 7 +- web/src/js/__tests__/ducks/utils/storeSpec.js | 170 ---------------- .../js/__tests__/ducks/utils/storeSpec.tsx | 188 ++++++++++++++++++ .../flow/{utilsSpec.js => utilsSpec.tsx} | 36 ++-- .../{urlStateSpec.js => urlStateSpec.tsx} | 18 +- .../__tests__/{utilsSpec.js => utilsSpec.tsx} | 18 +- web/src/js/backends/static.js | 32 --- web/src/js/backends/static.tsx | 37 ++++ .../backends/{websocket.js => websocket.tsx} | 21 +- web/src/js/components/CommandBar.tsx | 10 +- .../EventLog/{EventList.jsx => EventList.tsx} | 22 +- web/src/js/components/Header/FilterInput.tsx | 3 +- web/src/js/components/Modal/Option.jsx | 56 +++--- .../components/common/ToggleInputButton.tsx | 55 ----- .../{useContent.ts => useContent.tsx} | 0 web/src/js/components/editors/ValueEditor.tsx | 8 +- .../helpers/{AutoScroll.js => AutoScroll.tsx} | 2 +- .../{VirtualScroll.js => VirtualScroll.tsx} | 18 +- web/src/js/ducks/commandBar.ts | 7 +- web/src/js/ducks/conf.ts | 4 +- web/src/js/ducks/connection.ts | 5 +- web/src/js/ducks/eventLog.ts | 2 +- web/src/js/ducks/flows.ts | 4 +- web/src/js/ducks/options.ts | 6 +- web/src/js/ducks/ui/flow.ts | 6 +- .../js/ducks/ui/{keyboard.js => keyboard.tsx} | 97 ++++----- web/src/js/ducks/utils/store.ts | 2 +- web/src/js/utils.ts | 24 +-- 69 files changed, 679 insertions(+), 730 deletions(-) rename web/src/js/__tests__/components/EventLog/{EventListSpec.js => EventListSpec.tsx} (100%) rename web/src/js/__tests__/components/EventLog/__snapshots__/{EventListSpec.js.snap => EventListSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/FlowTable/{FlowTableHeadSpec.js => FlowTableHeadSpec.tsx} (100%) rename web/src/js/__tests__/components/FlowTable/__snapshots__/{FlowTableHeadSpec.js.snap => FlowTableHeadSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/Header/{FileMenuSpec.js => FileMenuSpec.tsx} (100%) delete mode 100644 web/src/js/__tests__/components/Header/FilterDocsSpec.js create mode 100644 web/src/js/__tests__/components/Header/FilterDocsSpec.tsx rename web/src/js/__tests__/components/Header/{FilterInputSpec.js => FilterInputSpec.tsx} (93%) rename web/src/js/__tests__/components/Header/{MainMenuSpec.js => MainMenuSpec.tsx} (100%) rename web/src/js/__tests__/components/Header/{MenuToggleSpec.js => MenuToggleSpec.tsx} (100%) rename web/src/js/__tests__/components/Header/{OptionMenuSpec.js => OptionMenuSpec.tsx} (100%) rename web/src/js/__tests__/components/Header/__snapshots__/{FileMenuSpec.js.snap => FileMenuSpec.tsx.snap} (100%) delete mode 100644 web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.js.snap create mode 100644 web/src/js/__tests__/components/Header/__snapshots__/FilterDocsSpec.tsx.snap rename web/src/js/__tests__/components/Header/__snapshots__/{FilterInputSpec.js.snap => FilterInputSpec.tsx.snap} (97%) rename web/src/js/__tests__/components/Header/__snapshots__/{MainMenuSpec.js.snap => MainMenuSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/Header/__snapshots__/{MenuToggleSpec.js.snap => MenuToggleSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/Header/__snapshots__/{OptionMenuSpec.js.snap => OptionMenuSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/Modal/{OptionModalSpec.js => OptionModalSpec.tsx} (100%) rename web/src/js/__tests__/components/Modal/{OptionSpec.js => OptionSpec.tsx} (100%) rename web/src/js/__tests__/components/Modal/__snapshots__/{OptionModalSpec.js.snap => OptionModalSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/Modal/__snapshots__/{OptionSpec.js.snap => OptionSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/common/{ButtonSpec.js => ButtonSpec.tsx} (95%) rename web/src/js/__tests__/components/common/{DocsLinkSpec.js => DocsLinkSpec.tsx} (100%) rename web/src/js/__tests__/components/common/{SplitterSpec.js => SplitterSpec.tsx} (82%) rename web/src/js/__tests__/components/common/{ToggleButtonSpec.js => ToggleButtonSpec.tsx} (84%) delete mode 100644 web/src/js/__tests__/components/common/ToggleInputButtonSpec.js rename web/src/js/__tests__/components/common/__snapshots__/{ButtonSpec.js.snap => ButtonSpec.tsx.snap} (95%) rename web/src/js/__tests__/components/common/__snapshots__/{DocsLinkSpec.js.snap => DocsLinkSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/common/__snapshots__/{SplitterSpec.js.snap => SplitterSpec.tsx.snap} (100%) rename web/src/js/__tests__/components/common/__snapshots__/{ToggleButtonSpec.js.snap => ToggleButtonSpec.tsx.snap} (100%) delete mode 100644 web/src/js/__tests__/components/common/__snapshots__/ToggleInputButtonSpec.js.snap rename web/src/js/__tests__/components/helpers/{AutoScrollSpec.js => AutoScrollSpec.tsx} (100%) rename web/src/js/__tests__/components/helpers/{VirtualScrollSpec.js => VirtualScrollSpec.tsx} (90%) rename web/src/js/__tests__/ducks/{connectionSpec.js => connectionSpec.tsx} (94%) rename web/src/js/__tests__/ducks/{eventLogSpec.js => eventLogSpec.tsx} (100%) rename web/src/js/__tests__/ducks/{indexSpec.js => indexSpec.tsx} (86%) rename web/src/js/__tests__/ducks/ui/{indexSpec.js => indexSpec.tsx} (79%) delete mode 100644 web/src/js/__tests__/ducks/ui/keyboardSpec.js create mode 100644 web/src/js/__tests__/ducks/ui/keyboardSpec.tsx rename web/src/js/__tests__/ducks/ui/{modalSpec.js => modalSpec.tsx} (76%) rename web/src/js/__tests__/ducks/ui/{optionEditorSpec.js => optionEditorSpec.tsx} (76%) delete mode 100644 web/src/js/__tests__/ducks/utils/storeSpec.js create mode 100644 web/src/js/__tests__/ducks/utils/storeSpec.tsx rename web/src/js/__tests__/flow/{utilsSpec.js => utilsSpec.tsx} (53%) rename web/src/js/__tests__/{urlStateSpec.js => urlStateSpec.tsx} (84%) rename web/src/js/__tests__/{utilsSpec.js => utilsSpec.tsx} (77%) delete mode 100644 web/src/js/backends/static.js create mode 100644 web/src/js/backends/static.tsx rename web/src/js/backends/{websocket.js => websocket.tsx} (85%) rename web/src/js/components/EventLog/{EventList.jsx => EventList.tsx} (81%) delete mode 100644 web/src/js/components/common/ToggleInputButton.tsx rename web/src/js/components/contentviews/{useContent.ts => useContent.tsx} (100%) rename web/src/js/components/helpers/{AutoScroll.js => AutoScroll.tsx} (94%) rename web/src/js/components/helpers/{VirtualScroll.js => VirtualScroll.tsx} (85%) rename web/src/js/ducks/ui/{keyboard.js => keyboard.tsx} (53%) 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`] = `