From 063ceb215f858a8e2a5bde85d8f9ca24240894c6 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 21 Sep 2020 15:20:41 +0900 Subject: Separate input component --- test/settings/components/ui/Radio.test.tsx | 56 ++++++++++ test/settings/components/ui/Text.test.tsx | 55 ++++++++++ test/settings/components/ui/TextArea.test.tsx | 63 +++++++++++ test/settings/components/ui/input.test.tsx | 146 -------------------------- 4 files changed, 174 insertions(+), 146 deletions(-) create mode 100644 test/settings/components/ui/Radio.test.tsx create mode 100644 test/settings/components/ui/Text.test.tsx create mode 100644 test/settings/components/ui/TextArea.test.tsx delete mode 100644 test/settings/components/ui/input.test.tsx (limited to 'test') diff --git a/test/settings/components/ui/Radio.test.tsx b/test/settings/components/ui/Radio.test.tsx new file mode 100644 index 0000000..f929ee3 --- /dev/null +++ b/test/settings/components/ui/Radio.test.tsx @@ -0,0 +1,56 @@ +import React from "react"; +import ReactDOM from "react-dom"; +import ReactTestUtils from "react-dom/test-utils"; +import Radio from "../../../../src/settings/components/ui/Radio"; +import { expect } from "chai"; + +describe("settings/ui/Radio", () => { + let container: HTMLDivElement; + + beforeEach(() => { + container = document.createElement("div"); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + }); + + it("renders radio button", () => { + ReactTestUtils.act(() => { + ReactDOM.render( + , + container + ); + }); + + 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("myradio"); + expect(input.value).to.contain("myvalue"); + }); + + it("invoke onChange", (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( + { + expect((e.target as HTMLInputElement).checked).to.be.true; + done(); + }} + />, + container + ); + }); + + const input = document.querySelector("input") as HTMLInputElement; + input.checked = true; + ReactTestUtils.Simulate.change(input); + }); +}); diff --git a/test/settings/components/ui/Text.test.tsx b/test/settings/components/ui/Text.test.tsx new file mode 100644 index 0000000..d5451bb --- /dev/null +++ b/test/settings/components/ui/Text.test.tsx @@ -0,0 +1,55 @@ +import React from "react"; +import ReactDOM from "react-dom"; +import ReactTestUtils from "react-dom/test-utils"; +import Text from "../../../../src/settings/components/ui/Text"; +import { expect } from "chai"; + +describe("settings/ui/Text", () => { + let container: HTMLDivElement; + + beforeEach(() => { + container = document.createElement("div"); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + }); + + it("renders text input", () => { + ReactTestUtils.act(() => { + ReactDOM.render( + , + container + ); + }); + + 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"); + expect(input.value).to.contain("myvalue"); + }); + + it("invoke onChange", (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( + { + expect((e.target as HTMLInputElement).value).to.equal("newvalue"); + done(); + }} + />, + container + ); + }); + + const input = document.querySelector("input")!; + input.value = "newvalue"; + ReactTestUtils.Simulate.change(input); + }); +}); diff --git a/test/settings/components/ui/TextArea.test.tsx b/test/settings/components/ui/TextArea.test.tsx new file mode 100644 index 0000000..50313cf --- /dev/null +++ b/test/settings/components/ui/TextArea.test.tsx @@ -0,0 +1,63 @@ +import React from "react"; +import ReactDOM from "react-dom"; +import ReactTestUtils from "react-dom/test-utils"; +import TextArea from "../../../../src/settings/components/ui/TextArea"; +import { expect } from "chai"; + +describe("settings/ui/TextArea", () => { + let container: HTMLDivElement; + + beforeEach(() => { + container = document.createElement("div"); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + }); + + it("renders textarea", () => { + ReactTestUtils.act(() => { + ReactDOM.render( +