diff options
Diffstat (limited to 'test/settings/components')
-rw-r--r-- | test/settings/components/form/BlacklistForm.test.tsx | 38 | ||||
-rw-r--r-- | test/settings/components/form/KeymapsForm.test.tsx | 9 | ||||
-rw-r--r-- | test/settings/components/form/PropertiesForm.test.tsx | 18 | ||||
-rw-r--r-- | test/settings/components/form/SearchEngineForm.test.tsx | 24 | ||||
-rw-r--r-- | test/settings/components/ui/input.test.tsx | 32 |
5 files changed, 73 insertions, 48 deletions
diff --git a/test/settings/components/form/BlacklistForm.test.tsx b/test/settings/components/form/BlacklistForm.test.tsx index 4d79383..e34802a 100644 --- a/test/settings/components/form/BlacklistForm.test.tsx +++ b/test/settings/components/form/BlacklistForm.test.tsx @@ -6,6 +6,7 @@ import { expect } from "chai"; import BlacklistForm from "../../../../src/settings/components/form/BlacklistForm"; import Blacklist from "../../../../src/shared/settings/Blacklist"; +import AddButton from "../../../../src/settings/components/ui/AddButton"; describe("settings/form/BlacklistForm", () => { describe("render", () => { @@ -16,26 +17,32 @@ describe("settings/form/BlacklistForm", () => { /> ).root; - const children = root.children[0].children; - expect(children).to.have.lengthOf(3); - expect(children[0].children[0].props.value).to.equal("*.slack.com"); - expect(children[1].children[0].props.value).to.equal( - "www.google.com/maps" - ); - expect(children[2].props.name).to.equal("add"); + const rows = root.findAllByProps({ + className: "form-blacklist-form-row", + }); + expect(rows).to.have.lengthOf(2); + expect( + rows[0].findByProps({ className: "column-url" }).props.value + ).to.equal("*.slack.com"); + expect( + rows[1].findByProps({ className: "column-url" }).props.value + ).to.equal("www.google.com/maps"); + + expect(() => root.findByType(AddButton)).not.throw(); }); it("renders blank value", () => { const root = ReactTestRenderer.create(<BlacklistForm />).root; - const children = root.children[0].children; - expect(children).to.have.lengthOf(1); - expect(children[0].props.name).to.equal("add"); + const rows = root.findAllByProps({ + className: "form-blacklist-form-row", + }); + expect(rows).to.be.empty; }); }); describe("onChange", () => { - let container; + let container: HTMLDivElement; beforeEach(() => { container = document.createElement("div"); @@ -44,7 +51,6 @@ describe("settings/form/BlacklistForm", () => { afterEach(() => { document.body.removeChild(container); - container = null; }); it("invokes onChange event on edit", (done) => { @@ -65,7 +71,9 @@ describe("settings/form/BlacklistForm", () => { ); }); - const input = document.querySelectorAll("input[type=text]")[0]; + const input = document.querySelectorAll( + "input[type=text]" + )[0] as HTMLInputElement; input.value = "gitter.im"; ReactTestUtils.Simulate.change(input); }); @@ -104,7 +112,9 @@ describe("settings/form/BlacklistForm", () => { ); }); - const button = document.querySelector("input[type=button].ui-add-button"); + const button = document.querySelector( + "input[type=button].ui-add-button" + ) as HTMLButtonElement; ReactTestUtils.Simulate.click(button); }); }); diff --git a/test/settings/components/form/KeymapsForm.test.tsx b/test/settings/components/form/KeymapsForm.test.tsx index 0a88db5..1cec889 100644 --- a/test/settings/components/form/KeymapsForm.test.tsx +++ b/test/settings/components/form/KeymapsForm.test.tsx @@ -3,7 +3,7 @@ import ReactDOM from "react-dom"; import ReactTestRenderer from "react-test-renderer"; import ReactTestUtils from "react-dom/test-utils"; import KeymapsForm from "../../../../src/settings/components/form/KeymapsForm"; -import { FormKeymaps } from "shared/SettingData"; +import { FormKeymaps } from "../../../../src/shared/SettingData"; import { expect } from "chai"; describe("settings/form/KeymapsForm", () => { @@ -37,7 +37,7 @@ describe("settings/form/KeymapsForm", () => { }); describe("onChange event", () => { - let container; + let container: HTMLDivElement; beforeEach(() => { container = document.createElement("div"); @@ -46,7 +46,6 @@ describe("settings/form/KeymapsForm", () => { afterEach(() => { document.body.removeChild(container); - container = null; }); it("invokes onChange event on edit", (done) => { @@ -68,7 +67,9 @@ describe("settings/form/KeymapsForm", () => { ); }); - const input = document.getElementById('scroll.vertically?{"count":1}'); + const input = document.getElementById( + 'scroll.vertically?{"count":1}' + ) as HTMLInputElement; input.value = "jjj"; ReactTestUtils.Simulate.change(input); }); diff --git a/test/settings/components/form/PropertiesForm.test.tsx b/test/settings/components/form/PropertiesForm.test.tsx index 4dc00a2..acf02b8 100644 --- a/test/settings/components/form/PropertiesForm.test.tsx +++ b/test/settings/components/form/PropertiesForm.test.tsx @@ -2,7 +2,8 @@ import React from "react"; import ReactDOM from "react-dom"; import ReactTestRenderer from "react-test-renderer"; import ReactTestUtils from "react-dom/test-utils"; -import PropertiesForm from "settings/components/form/PropertiesForm"; +import PropertiesForm from "../../../../src/settings/components/form/PropertiesForm"; +import { expect } from "chai"; describe("settings/form/PropertiesForm", () => { describe("render", () => { @@ -38,7 +39,7 @@ describe("settings/form/PropertiesForm", () => { }); describe("onChange", () => { - let container; + let container: HTMLDivElement; beforeEach(() => { container = document.createElement("div"); @@ -47,7 +48,6 @@ describe("settings/form/PropertiesForm", () => { afterEach(() => { document.body.removeChild(container); - container = null; }); it("invokes onChange event on text changed", (done) => { @@ -65,7 +65,9 @@ describe("settings/form/PropertiesForm", () => { ); }); - const input = document.querySelector("input[name=myvalue]"); + const input = document.querySelector( + "input[name=myvalue]" + ) as HTMLInputElement; input.value = "abcd"; ReactTestUtils.Simulate.change(input); }); @@ -85,7 +87,9 @@ describe("settings/form/PropertiesForm", () => { ); }); - const input = document.querySelector("input[name=myvalue]"); + const input = document.querySelector( + "input[name=myvalue]" + ) as HTMLInputElement; input.value = "1234"; ReactTestUtils.Simulate.change(input); }); @@ -105,7 +109,9 @@ describe("settings/form/PropertiesForm", () => { ); }); - const input = document.querySelector("input[name=myvalue]"); + const input = document.querySelector( + "input[name=myvalue]" + ) as HTMLInputElement; input.checked = true; ReactTestUtils.Simulate.change(input); }); diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx index ccbd197..5f835cc 100644 --- a/test/settings/components/form/SearchEngineForm.test.tsx +++ b/test/settings/components/form/SearchEngineForm.test.tsx @@ -2,8 +2,9 @@ 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 SearchForm from "../../../../src/settings/components/form/SearchForm"; +import { FormSearch } from "../../../../src/shared/SettingData"; +import { expect } from "chai"; describe("settings/form/SearchForm", () => { describe("render", () => { @@ -33,7 +34,7 @@ describe("settings/form/SearchForm", () => { }); describe("onChange event", () => { - let container; + let container: HTMLDivElement; beforeEach(() => { container = document.createElement("div"); @@ -42,7 +43,6 @@ describe("settings/form/SearchForm", () => { afterEach(() => { document.body.removeChild(container); - container = null; }); it("invokes onChange event on edit", (done) => { @@ -71,10 +71,14 @@ describe("settings/form/SearchForm", () => { ); }); - 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]"); + const name = document.querySelector( + "input[name=name]" + ) as HTMLInputElement; name.value = "louvre"; ReactTestUtils.Simulate.change(name); @@ -105,7 +109,9 @@ describe("settings/form/SearchForm", () => { ); }); - const button = document.querySelector("input[type=button]"); + const button = document.querySelector( + "input[type=button]" + ) as HTMLInputElement; ReactTestUtils.Simulate.click(button); }); @@ -132,7 +138,9 @@ describe("settings/form/SearchForm", () => { ); }); - 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); }); }); diff --git a/test/settings/components/ui/input.test.tsx b/test/settings/components/ui/input.test.tsx index 2f2b075..191bfed 100644 --- a/test/settings/components/ui/input.test.tsx +++ b/test/settings/components/ui/input.test.tsx @@ -1,10 +1,11 @@ import React from "react"; import ReactDOM from "react-dom"; import ReactTestUtils from "react-dom/test-utils"; -import Input from "settings/components/ui/Input"; +import Input from "../../../../src/settings/components/ui/Input"; +import { expect } from "chai"; describe("settings/ui/Input", () => { - let container; + let container: HTMLDivElement; beforeEach(() => { container = document.createElement("div"); @@ -13,7 +14,6 @@ describe("settings/ui/Input", () => { afterEach(() => { document.body.removeChild(container); - container = null; }); context("type=text", () => { @@ -25,8 +25,8 @@ describe("settings/ui/Input", () => { ); }); - const label = document.querySelector("label"); - const input = document.querySelector("input"); + const label = document.querySelector("label")!!; + const input = document.querySelector("input")!!; expect(label.textContent).to.contain("myfield"); expect(input.type).to.contain("text"); expect(input.name).to.contain("myname"); @@ -42,7 +42,7 @@ describe("settings/ui/Input", () => { label="myfield" value="myvalue" onChange={(e) => { - expect(e.target.value).to.equal("newvalue"); + expect((e.target as HTMLInputElement).value).to.equal("newvalue"); done(); }} />, @@ -50,7 +50,7 @@ describe("settings/ui/Input", () => { ); }); - const input = document.querySelector("input"); + const input = document.querySelector("input")!!; input.value = "newvalue"; ReactTestUtils.Simulate.change(input); }); @@ -65,8 +65,8 @@ describe("settings/ui/Input", () => { ); }); - const label = document.querySelector("label"); - const input = document.querySelector("input"); + const label = document.querySelector("label")!!; + const input = document.querySelector("input")!!; expect(label.textContent).to.contain("myfield"); expect(input.type).to.contain("radio"); expect(input.name).to.contain("myname"); @@ -82,7 +82,7 @@ describe("settings/ui/Input", () => { label="myfield" value="myvalue" onChange={(e) => { - expect(e.target.checked).to.be.true; + expect((e.target as HTMLInputElement).checked).to.be.true; done(); }} />, @@ -90,7 +90,7 @@ describe("settings/ui/Input", () => { ); }); - const input = document.querySelector("input"); + const input = document.querySelector("input") as HTMLInputElement; input.checked = true; ReactTestUtils.Simulate.change(input); }); @@ -111,9 +111,9 @@ describe("settings/ui/Input", () => { ); }); - const label = document.querySelector("label"); - const textarea = document.querySelector("textarea"); - const error = document.querySelector(".settings-ui-input-error"); + const label = document.querySelector("label")!!; + const textarea = document.querySelector("textarea")!!; + const error = document.querySelector(".settings-ui-input-error")!!; expect(label.textContent).to.contain("myfield"); expect(textarea.nodeName).to.contain("TEXTAREA"); expect(textarea.name).to.contain("myname"); @@ -130,7 +130,7 @@ describe("settings/ui/Input", () => { label="myfield" value="myvalue" onChange={(e) => { - expect(e.target.value).to.equal("newvalue"); + expect((e.target as HTMLInputElement).value).to.equal("newvalue"); done(); }} />, @@ -138,7 +138,7 @@ describe("settings/ui/Input", () => { ); }); - const input = document.querySelector("textarea"); + const input = document.querySelector("textarea")!!; input.value = "newvalue"; ReactTestUtils.Simulate.change(input); }); |