aboutsummaryrefslogtreecommitdiff
path: root/test/settings/components/ui/Text.test.tsx
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-09-22 11:03:07 +0900
committerGitHub <noreply@github.com>2020-09-22 11:03:07 +0900
commitd956b9e976c01db3944643e2260cb23e23b08221 (patch)
treed953d4d629bd31f5ba1b248133ee1f77cdf470ac /test/settings/components/ui/Text.test.tsx
parent5d82441ce3d12301bb8f04b78b79fffb04121a37 (diff)
parent7257406df196a29c0f172ee68ca8dbe50a72d21f (diff)
Merge pull request #838 from ueokande/form-styled-components
Use styled-components instead of vanilla CSS/SCSS in option
Diffstat (limited to 'test/settings/components/ui/Text.test.tsx')
-rw-r--r--test/settings/components/ui/Text.test.tsx55
1 files changed, 55 insertions, 0 deletions
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(
+ <Text name="myname" label="myfield" value="myvalue" />,
+ 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(
+ <Text
+ name="myname"
+ label="myfield"
+ value="myvalue"
+ onChange={(e) => {
+ expect((e.target as HTMLInputElement).value).to.equal("newvalue");
+ done();
+ }}
+ />,
+ container
+ );
+ });
+
+ const input = document.querySelector("input")!;
+ input.value = "newvalue";
+ ReactTestUtils.Simulate.change(input);
+ });
+});