A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.5 KiB
112 lines
3.5 KiB
6 years ago
|
import React from 'react';
|
||
|
import ReactDOM from 'react-dom';
|
||
|
import ReactTestUtils from 'react-dom/test-utils';
|
||
|
import Input from 'settings/components/ui/Input'
|
||
7 years ago
|
|
||
|
describe("settings/ui/Input", () => {
|
||
6 years ago
|
let container;
|
||
|
|
||
7 years ago
|
beforeEach(() => {
|
||
6 years ago
|
container = document.createElement('div');
|
||
|
document.body.appendChild(container);
|
||
|
});
|
||
|
|
||
|
afterEach(() => {
|
||
|
document.body.removeChild(container);
|
||
|
container = null;
|
||
7 years ago
|
});
|
||
|
|
||
|
context("type=text", () => {
|
||
|
it('renders text input', () => {
|
||
6 years ago
|
ReactTestUtils.act(() => {
|
||
|
ReactDOM.render(
|
||
|
<Input type='text' name='myname' label='myfield' value='myvalue'/>,
|
||
|
container);
|
||
|
});
|
||
7 years ago
|
|
||
|
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) => {
|
||
6 years ago
|
ReactTestUtils.act(() => {
|
||
|
ReactDOM.render(<Input type='text' name='myname' label='myfield' value='myvalue' onChange={(e) => {
|
||
|
expect(e.target.value).to.equal('newvalue');
|
||
|
done();
|
||
|
}}/>, container);
|
||
|
});
|
||
7 years ago
|
|
||
|
let input = document.querySelector('input');
|
||
|
input.value = 'newvalue';
|
||
6 years ago
|
ReactTestUtils.Simulate.change(input);
|
||
7 years ago
|
});
|
||
|
});
|
||
|
|
||
|
context("type=radio", () => {
|
||
|
it('renders radio button', () => {
|
||
6 years ago
|
ReactTestUtils.act(() => {
|
||
|
ReactDOM.render(
|
||
|
<Input type='radio' name='myname' label='myfield' value='myvalue'/>,
|
||
|
container);
|
||
|
});
|
||
7 years ago
|
|
||
|
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) => {
|
||
6 years ago
|
ReactTestUtils.act(() => {
|
||
|
ReactDOM.render(<Input type='text' name='radio' label='myfield' value='myvalue' onChange={(e) => {
|
||
|
expect(e.target.checked).to.be.true;
|
||
|
done();
|
||
|
}}/>,
|
||
|
container);
|
||
|
});
|
||
7 years ago
|
|
||
|
let input = document.querySelector('input');
|
||
|
input.checked = true;
|
||
6 years ago
|
ReactTestUtils.Simulate.change(input);
|
||
7 years ago
|
});
|
||
|
});
|
||
|
|
||
|
context("type=textarea", () => {
|
||
|
it('renders textarea button', () => {
|
||
6 years ago
|
ReactTestUtils.act(() => {
|
||
|
ReactDOM.render(
|
||
|
<Input type='textarea' name='myname' label='myfield' value='myvalue' error='myerror' />,
|
||
|
container);
|
||
|
});
|
||
7 years ago
|
|
||
|
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) => {
|
||
6 years ago
|
ReactTestUtils.act(() => {
|
||
|
ReactDOM.render(<Input type='textarea' name='myname' label='myfield' value='myvalue' onChange={(e) => {
|
||
|
expect(e.target.value).to.equal('newvalue');
|
||
|
done();
|
||
|
}}/>, container);
|
||
|
});
|
||
7 years ago
|
|
||
|
let input = document.querySelector('textarea');
|
||
|
input.value = 'newvalue'
|
||
6 years ago
|
ReactTestUtils.Simulate.change(input);
|
||
7 years ago
|
});
|
||
|
});
|
||
|
});
|