aboutsummaryrefslogtreecommitdiff
path: root/test/settings/components/form/PropertiesForm.test.tsx
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-05-02 17:25:56 +0900
committerGitHub <noreply@github.com>2020-05-02 17:25:56 +0900
commit5df0537bcf65a341e79852b1b30379c73318529c (patch)
treeaee5efe52412855f620cb514a13a2c14373f27b7 /test/settings/components/form/PropertiesForm.test.tsx
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
parent75abd90ecb8201ad845b266f96220d8adfe19b2d (diff)
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'test/settings/components/form/PropertiesForm.test.tsx')
-rw-r--r--test/settings/components/form/PropertiesForm.test.tsx131
1 files changed, 73 insertions, 58 deletions
diff --git a/test/settings/components/form/PropertiesForm.test.tsx b/test/settings/components/form/PropertiesForm.test.tsx
index 4a0e25a..acf02b8 100644
--- a/test/settings/components/form/PropertiesForm.test.tsx
+++ b/test/settings/components/form/PropertiesForm.test.tsx
@@ -1,102 +1,117 @@
-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 React from "react";
+import ReactDOM from "react-dom";
+import ReactTestRenderer from "react-test-renderer";
+import ReactTestUtils from "react-dom/test-utils";
+import PropertiesForm from "../../../../src/settings/components/form/PropertiesForm";
+import { expect } from "chai";
describe("settings/form/PropertiesForm", () => {
- describe('render', () => {
- it('renders PropertiesForm', () => {
+ describe("render", () => {
+ it("renders PropertiesForm", () => {
const types = {
- mystr: 'string',
- mynum: 'number',
- mybool: 'boolean',
- empty: 'string',
- }
+ mystr: "string",
+ mynum: "number",
+ mybool: "boolean",
+ empty: "string",
+ };
const values = {
- mystr: 'abc',
+ mystr: "abc",
mynum: 123,
mybool: true,
};
const root = ReactTestRenderer.create(
- <PropertiesForm types={types} value={values} />,
- ).root
+ <PropertiesForm types={types} value={values} />
+ ).root;
- let input = root.findByProps({ name: 'mystr' });
- expect(input.props.type).to.equals('text');
- expect(input.props.value).to.equal('abc');
+ let input = root.findByProps({ name: "mystr" });
+ expect(input.props.type).to.equals("text");
+ expect(input.props.value).to.equal("abc");
- input = root.findByProps({ name: 'mynum' });
- expect(input.props.type).to.equals('number');
+ input = root.findByProps({ name: "mynum" });
+ expect(input.props.type).to.equals("number");
expect(input.props.value).to.equal(123);
- input = root.findByProps({ name: 'mybool' });
- expect(input.props.type).to.equals('checkbox');
+ input = root.findByProps({ name: "mybool" });
+ expect(input.props.type).to.equals("checkbox");
expect(input.props.value).to.equal(true);
});
});
- describe('onChange', () => {
- let container;
+ describe("onChange", () => {
+ 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 text changed', (done) => {
+ it("invokes onChange event on text changed", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<PropertiesForm
- types={{ 'myvalue': 'string' }}
- value={{ 'myvalue': 'abc' }}
- onChange={value => {
- expect(value).to.have.property('myvalue', 'abcd');
- done();
- }}
- />, container);
+ ReactDOM.render(
+ <PropertiesForm
+ types={{ myvalue: "string" }}
+ value={{ myvalue: "abc" }}
+ onChange={(value) => {
+ expect(value).to.have.property("myvalue", "abcd");
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input[name=myvalue]');
- input.value = 'abcd'
+ const input = document.querySelector(
+ "input[name=myvalue]"
+ ) as HTMLInputElement;
+ input.value = "abcd";
ReactTestUtils.Simulate.change(input);
});
- it('invokes onChange event on number changeed', (done) => {
+ it("invokes onChange event on number changeed", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<PropertiesForm
- types={{ 'myvalue': 'number' }}
- value={{ '': 123 }}
- onChange={value => {
- expect(value).to.have.property('myvalue', 1234);
- done();
- }}
- />, container);
+ ReactDOM.render(
+ <PropertiesForm
+ types={{ myvalue: "number" }}
+ value={{ "": 123 }}
+ onChange={(value) => {
+ expect(value).to.have.property("myvalue", 1234);
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input[name=myvalue]');
- input.value = '1234'
+ const input = document.querySelector(
+ "input[name=myvalue]"
+ ) as HTMLInputElement;
+ input.value = "1234";
ReactTestUtils.Simulate.change(input);
});
- it('invokes onChange event on checkbox changed', (done) => {
+ it("invokes onChange event on checkbox changed", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<PropertiesForm
- types={{ 'myvalue': 'boolean' }}
- value={{ 'myvalue': false }}
- onChange={value => {
- expect(value).to.have.property('myvalue', true);
- done();
- }}
- />, container);
+ ReactDOM.render(
+ <PropertiesForm
+ types={{ myvalue: "boolean" }}
+ value={{ myvalue: false }}
+ onChange={(value) => {
+ expect(value).to.have.property("myvalue", true);
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input[name=myvalue]');
+ const input = document.querySelector(
+ "input[name=myvalue]"
+ ) as HTMLInputElement;
input.checked = true;
ReactTestUtils.Simulate.change(input);
});