diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-09-21 23:27:44 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-09-21 23:27:44 +0900 |
commit | 1f014295a54f1e16b8bd94da729fb0afd143f7fe (patch) | |
tree | e120a8f58403e6a24477ea5e1ab1b19a630fa43b | |
parent | b88c0db89d439fe7c4385d5a6f087012557d4c47 (diff) |
Fix component test
-rw-r--r-- | src/settings/components/form/BlacklistForm.tsx | 4 | ||||
-rw-r--r-- | src/settings/components/ui/TextArea.tsx | 4 | ||||
-rw-r--r-- | test/settings/components/form/BlacklistForm.test.tsx | 20 | ||||
-rw-r--r-- | test/settings/components/form/SearchEngineForm.test.tsx | 10 | ||||
-rw-r--r-- | test/settings/components/ui/TextArea.test.tsx | 2 |
5 files changed, 23 insertions, 17 deletions
diff --git a/src/settings/components/form/BlacklistForm.tsx b/src/settings/components/form/BlacklistForm.tsx index 4d794f4..d301f2c 100644 --- a/src/settings/components/form/BlacklistForm.tsx +++ b/src/settings/components/form/BlacklistForm.tsx @@ -40,13 +40,13 @@ class BlacklistForm extends React.Component<Props> { render() { return ( <> - <Grid> + <Grid role="list"> {this.props.value.items.map((item, index) => { if (item.partial) { return null; } return ( - <GridRow key={index}> + <GridRow role="listitem" key={index}> <GridCell> <Input data-index={index} diff --git a/src/settings/components/ui/TextArea.tsx b/src/settings/components/ui/TextArea.tsx index 58b7bd3..9dcd5be 100644 --- a/src/settings/components/ui/TextArea.tsx +++ b/src/settings/components/ui/TextArea.tsx @@ -46,7 +46,9 @@ const TextArea: React.FC<Props> = (props) => { <Container> <Label htmlFor={props.id}>{props.label}</Label> <ErrorableTextArea hasError={hasError} onChange={onChange} {...pp} /> - {hasError ? <ErrorMessage>{props.error}</ErrorMessage> : null} + {hasError ? ( + <ErrorMessage role="alert">{props.error}</ErrorMessage> + ) : null} </Container> ); }; diff --git a/test/settings/components/form/BlacklistForm.test.tsx b/test/settings/components/form/BlacklistForm.test.tsx index e34802a..8727c59 100644 --- a/test/settings/components/form/BlacklistForm.test.tsx +++ b/test/settings/components/form/BlacklistForm.test.tsx @@ -17,16 +17,16 @@ describe("settings/form/BlacklistForm", () => { /> ).root; - const rows = root.findAllByProps({ - className: "form-blacklist-form-row", - }); + const rows = root + .findAllByType("div") + .filter((instance) => instance.props.role === "listitem"); 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(rows[0].findByProps({ name: "url" }).props.value).to.equal( + "*.slack.com" + ); + expect(rows[1].findByProps({ name: "url" }).props.value).to.equal( + "www.google.com/maps" + ); expect(() => root.findByType(AddButton)).not.throw(); }); @@ -113,7 +113,7 @@ describe("settings/form/BlacklistForm", () => { }); const button = document.querySelector( - "input[type=button].ui-add-button" + "input[type=button][name=add]" ) as HTMLButtonElement; ReactTestUtils.Simulate.click(button); }); diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx index 5f835cc..7b10274 100644 --- a/test/settings/components/form/SearchEngineForm.test.tsx +++ b/test/settings/components/form/SearchEngineForm.test.tsx @@ -21,12 +21,16 @@ describe("settings/form/SearchForm", () => { /> ).root; - const names = root.findAllByProps({ name: "name" }); + const names = root + .findAllByType("input") + .filter((instance) => instance.props.name === "name"); expect(names).to.have.lengthOf(2); 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 + .findAllByType("input") + .filter((instance) => instance.props.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"); @@ -139,7 +143,7 @@ describe("settings/form/SearchForm", () => { }); const button = document.querySelector( - "input[type=button].ui-add-button" + "input[type=button][name=add]" ) as HTMLInputElement; ReactTestUtils.Simulate.click(button); }); diff --git a/test/settings/components/ui/TextArea.test.tsx b/test/settings/components/ui/TextArea.test.tsx index 50313cf..232c7c0 100644 --- a/test/settings/components/ui/TextArea.test.tsx +++ b/test/settings/components/ui/TextArea.test.tsx @@ -32,7 +32,7 @@ describe("settings/ui/TextArea", () => { const label = document.querySelector("label")!; const textarea = document.querySelector("textarea")!; - const error = document.querySelector(".settings-ui-input-error")!; + const error = document.querySelector("[role=alert]")!; expect(label.textContent).to.contain("myfield"); expect(textarea.nodeName).to.contain("TEXTAREA"); expect(textarea.name).to.contain("myname"); |