diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-05-01 15:51:40 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-05-01 15:51:40 +0900 |
commit | 9da2f5fd786ff7ef64eca0a86efb1c0b9a164244 (patch) | |
tree | b888349817d0016dc1499932671bbe6cd95efdaa /test/settings/components/ui | |
parent | f9889b7f2b634bfe5a540633d8952f4a6f900658 (diff) | |
parent | 89d6afecfd257ff4fc62748f771abf37ef3a2852 (diff) |
Merge remote-tracking branch 'origin/master' into patch-1
Diffstat (limited to 'test/settings/components/ui')
-rw-r--r-- | test/settings/components/ui/input.test.jsx | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/settings/components/ui/input.test.jsx b/test/settings/components/ui/input.test.jsx new file mode 100644 index 0000000..98f2cef --- /dev/null +++ b/test/settings/components/ui/input.test.jsx @@ -0,0 +1,83 @@ +import { expect } from 'chai'; +import { h, render } from 'preact'; +import Input from 'settings/components/ui/input' + +describe("settings/ui/Input", () => { + beforeEach(() => { + document.body.innerHTML = ''; + }); + + context("type=text", () => { + it('renders text input', () => { + render(<Input type='text' name='myname' label='myfield' value='myvalue'/>, document.body) + + let label = document.querySelector('label'); + let 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) => { + render(<Input type='text' name='myname' label='myfield' value='myvalue' onChange={(e) => { + expect(e.target.value).to.equal('newvalue'); + done(); + }}/>, document.body); + + let input = document.querySelector('input'); + input.value = 'newvalue'; + input.dispatchEvent(new Event('change')) + }); + }); + + context("type=radio", () => { + it('renders radio button', () => { + render(<Input type='radio' name='myname' label='myfield' value='myvalue'/>, document.body) + + let label = document.querySelector('label'); + let input = document.querySelector('input'); + expect(label.textContent).to.contain('myfield'); + expect(input.type).to.contain('radio'); + expect(input.name).to.contain('myname'); + expect(input.value).to.contain('myvalue'); + }); + + it('invoke onChange', (done) => { + render(<Input type='text' name='radio' label='myfield' value='myvalue' onChange={(e) => { + expect(e.target.checked).to.be.true; + done(); + }}/>, document.body); + + let input = document.querySelector('input'); + input.checked = true; + input.dispatchEvent(new Event('change')) + }); + }); + + context("type=textarea", () => { + it('renders textarea button', () => { + render(<Input type='textarea' name='myname' label='myfield' value='myvalue' error='myerror' />, document.body) + + let label = document.querySelector('label'); + let textarea = document.querySelector('textarea'); + let 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'); + expect(textarea.value).to.contain('myvalue'); + expect(error.textContent).to.contain('myerror'); + }); + + it('invoke onChange', (done) => { + render(<Input type='textarea' name='myname' label='myfield' value='myvalue' onChange={(e) => { + expect(e.target.value).to.equal('newvalue'); + done(); + }}/>, document.body); + + let input = document.querySelector('textarea'); + input.value = 'newvalue' + input.dispatchEvent(new Event('change')) + }); + }); +}); |