diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-05-02 17:25:56 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-02 17:25:56 +0900 |
commit | 5df0537bcf65a341e79852b1b30379c73318529c (patch) | |
tree | aee5efe52412855f620cb514a13a2c14373f27b7 /test/settings/components/form/SearchEngineForm.test.tsx | |
parent | 685f2b7b69218b06b5bb676069e35f79c5048c9b (diff) | |
parent | 75abd90ecb8201ad845b266f96220d8adfe19b2d (diff) |
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'test/settings/components/form/SearchEngineForm.test.tsx')
-rw-r--r-- | test/settings/components/form/SearchEngineForm.test.tsx | 177 |
1 files changed, 107 insertions, 70 deletions
diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx index b918203..5f835cc 100644 --- a/test/settings/components/form/SearchEngineForm.test.tsx +++ b/test/settings/components/form/SearchEngineForm.test.tsx @@ -1,109 +1,146 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import ReactTestRenderer from 'react-test-renderer'; -import ReactTestUtils from 'react-dom/test-utils'; -import SearchForm from 'settings/components/form/SearchForm' -import { FormSearch } from 'shared/SettingData'; +import React from "react"; +import ReactDOM from "react-dom"; +import ReactTestRenderer from "react-test-renderer"; +import ReactTestUtils from "react-dom/test-utils"; +import SearchForm from "../../../../src/settings/components/form/SearchForm"; +import { FormSearch } from "../../../../src/shared/SettingData"; +import { expect } from "chai"; describe("settings/form/SearchForm", () => { - describe('render', () => { - it('renders SearchForm', () => { - const root = ReactTestRenderer.create(<SearchForm value={FormSearch.fromJSON({ - default: 'google', - engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']], - })} />).root; + describe("render", () => { + it("renders SearchForm", () => { + const root = ReactTestRenderer.create( + <SearchForm + value={FormSearch.fromJSON({ + default: "google", + engines: [ + ["google", "google.com"], + ["yahoo", "yahoo.com"], + ], + })} + /> + ).root; - const names = root.findAllByProps({ name: 'name' }); + const names = root.findAllByProps({ name: "name" }); expect(names).to.have.lengthOf(2); - expect(names[0].props.value).to.equal('google'); - expect(names[1].props.value).to.equal('yahoo'); + expect(names[0].props.value).to.equal("google"); + expect(names[1].props.value).to.equal("yahoo"); - const urls = root.findAllByProps({ name: 'url' }); + const urls = root.findAllByProps({ name: "url" }); expect(urls).to.have.lengthOf(2); - expect(urls[0].props.value).to.equal('google.com'); - expect(urls[1].props.value).to.equal('yahoo.com'); + expect(urls[0].props.value).to.equal("google.com"); + expect(urls[1].props.value).to.equal("yahoo.com"); }); }); - describe('onChange event', () => { - let container; + describe("onChange event", () => { + let container: HTMLDivElement; beforeEach(() => { - container = document.createElement('div'); + container = document.createElement("div"); document.body.appendChild(container); }); afterEach(() => { document.body.removeChild(container); - container = null; }); - it('invokes onChange event on edit', (done) => { + it("invokes onChange event on edit", (done) => { ReactTestUtils.act(() => { - ReactDOM.render(<SearchForm - value={FormSearch.fromJSON({ - default: 'google', - engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']] - })} - onChange={value => { - const json = value.toJSON(); - expect(json.default).to.equal('louvre'); - expect(json.engines).to.have.lengthOf(2) - expect(json.engines).to.have.deep.members( - [['louvre', 'google.com'], ['yahoo', 'yahoo.com']] - ); - done(); - }} />, container); + ReactDOM.render( + <SearchForm + value={FormSearch.fromJSON({ + default: "google", + engines: [ + ["google", "google.com"], + ["yahoo", "yahoo.com"], + ], + })} + onChange={(value) => { + const json = value.toJSON(); + expect(json.default).to.equal("louvre"); + expect(json.engines).to.have.lengthOf(2); + expect(json.engines).to.have.deep.members([ + ["louvre", "google.com"], + ["yahoo", "yahoo.com"], + ]); + done(); + }} + />, + container + ); }); - const radio = document.querySelectorAll('input[type=radio]'); + const radio = document.querySelector( + "input[type=radio]" + ) as HTMLInputElement; radio.checked = true; - const name = document.querySelector('input[name=name]'); - name.value = 'louvre'; + const name = document.querySelector( + "input[name=name]" + ) as HTMLInputElement; + name.value = "louvre"; ReactTestUtils.Simulate.change(name); }); - it('invokes onChange event on delete', (done) => { + it("invokes onChange event on delete", (done) => { ReactTestUtils.act(() => { - ReactDOM.render(<SearchForm value={FormSearch.fromJSON({ - default: 'yahoo', - engines: [['louvre', 'google.com'], ['yahoo', 'yahoo.com']] - })} - onChange={value => { - const json = value.toJSON(); - expect(json.default).to.equal('yahoo'); - expect(json.engines).to.have.lengthOf(1) - expect(json.engines).to.have.deep.members( - [['yahoo', 'yahoo.com']] - ); - done(); - }} />, container); + ReactDOM.render( + <SearchForm + value={FormSearch.fromJSON({ + default: "yahoo", + engines: [ + ["louvre", "google.com"], + ["yahoo", "yahoo.com"], + ], + })} + onChange={(value) => { + const json = value.toJSON(); + expect(json.default).to.equal("yahoo"); + expect(json.engines).to.have.lengthOf(1); + expect(json.engines).to.have.deep.members([ + ["yahoo", "yahoo.com"], + ]); + done(); + }} + />, + container + ); }); - const button = document.querySelector('input[type=button]'); + const button = document.querySelector( + "input[type=button]" + ) as HTMLInputElement; ReactTestUtils.Simulate.click(button); }); - it('invokes onChange event on add', (done) => { + it("invokes onChange event on add", (done) => { ReactTestUtils.act(() => { - ReactDOM.render(<SearchForm value={FormSearch.fromJSON({ - default: 'yahoo', - engines: [['google', 'google.com']] - })} - onChange={value => { - const json = value.toJSON(); - expect(json.default).to.equal('yahoo'); - expect(json.engines).to.have.lengthOf(2) - expect(json.engines).to.have.deep.members( - [['google', 'google.com'], ['', '']], - ); - done(); - }} />, container); + ReactDOM.render( + <SearchForm + value={FormSearch.fromJSON({ + default: "yahoo", + engines: [["google", "google.com"]], + })} + onChange={(value) => { + const json = value.toJSON(); + expect(json.default).to.equal("yahoo"); + expect(json.engines).to.have.lengthOf(2); + expect(json.engines).to.have.deep.members([ + ["google", "google.com"], + ["", ""], + ]); + done(); + }} + />, + container + ); }); - const button = document.querySelector('input[type=button].ui-add-button'); + const button = document.querySelector( + "input[type=button].ui-add-button" + ) as HTMLInputElement; ReactTestUtils.Simulate.click(button); }); }); |