-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathboolean-test.js
94 lines (79 loc) · 2.34 KB
/
boolean-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* eslint-disable react/prop-types */
import React from 'react';
import TestUtils from 'react-dom/test-utils';
import { boolean } from '../src';
describe('edit.boolean', function () {
it('renders given value', function () {
const testValue = false;
const Boolean = boolean();
const result = TestUtils.renderIntoDocument(
<Wrapper>
<Boolean value={testValue} onValue={() => {}} />
</Wrapper>
);
const renderedButtons = TestUtils.scryRenderedDOMComponentsWithTag(
result, 'button'
);
expect(renderedButtons.length).toEqual(2);
expect(renderedButtons[0].disabled).toEqual(testValue);
expect(renderedButtons[1].disabled).toEqual(!testValue);
});
it('triggers onValue when value is false', function () {
let changedValue = false;
const Boolean = boolean();
const result = TestUtils.renderIntoDocument(
<Wrapper>
<Boolean
value={false}
onValue={() => {
changedValue = true;
}}
/>
</Wrapper>
);
const renderedButtons = TestUtils.scryRenderedDOMComponentsWithTag(
result, 'button'
);
TestUtils.Simulate.click(renderedButtons[0]);
expect(changedValue).toEqual(true);
});
it('triggers onValue when value is true', function () {
let changedValue = false;
const Boolean = boolean();
const result = TestUtils.renderIntoDocument(
<Wrapper>
<Boolean
value
onValue={() => {
changedValue = false;
}}
/>
</Wrapper>
);
const renderedButtons = TestUtils.scryRenderedDOMComponentsWithTag(
result, 'button'
);
TestUtils.Simulate.click(renderedButtons[1]);
expect(changedValue).toEqual(false);
});
it('accepts custom props', function () {
const testClassName = 'demo';
const Boolean = boolean({
props: { className: testClassName }
});
const result = TestUtils.renderIntoDocument(
<Wrapper>
<Boolean value={'name'} onValue={() => {}} />
</Wrapper>
);
const renderedDiv = TestUtils.findRenderedDOMComponentWithClass(
result, testClassName
);
expect(renderedDiv).toBeDefined();
});
});
class Wrapper extends React.Component { // eslint-disable-line max-len, react/prefer-stateless-function
render() {
return <div>{this.props.children}</div>;
}
}