forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-button.js
More file actions
140 lines (104 loc) · 3.67 KB
/
test-button.js
File metadata and controls
140 lines (104 loc) · 3.67 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* MUI test react appbar library
* @module test/react-tests/test-appbar
*/
import assert from 'assert';
import React from 'react';
import ReactUtils from 'react-addons-test-utils';
import ReactDOM from 'react-dom';
import Button from '../../src/react/button';
import { getShallowRendererOutput } from '../lib/react-helpers';
describe('react/button', function() {
it('renders properly', function() {
let result = getShallowRendererOutput(<Button>test</Button>);
assert.equal(result.type, 'button');
assert.equal(/\bmui-btn\b/.test(result.props.className), true);
assert.equal(result.props.children[0], 'test');
});
it('renders properly with addtional classNames', function () {
let result = getShallowRendererOutput(
<Button className="additional">
test
</Button>
);
assert.equal(/\badditional\b/.test(result.props.className), true)
})
it('renders properly with additional styles', function() {
let result = getShallowRendererOutput(
<Button style={{additonal: 'style'}}>
test
</Button>
);
assert.equal(result.props.style.additonal, 'style');
});
it('supports colors', function() {
let result = getShallowRendererOutput(
<Button color="primary">test</Button>
);
assert.equal(/mui-btn--primary/.test(result.props.className), true);
});
it('supports variants', function() {
let result = getShallowRendererOutput(
<Button variant="raised">test</Button>
);
assert.equal(/mui-btn--raised/.test(result.props.className), true);
});
it('supports sizes', function() {
let result = getShallowRendererOutput(<Button size="large">test</Button>);
assert.equal(/mui-btn--large/.test(result.props.className), true);
});
it('supports type attribute', function() {
// check default
let result = getShallowRendererOutput(<Button>test</Button>);
assert.equal(result.props.type, null);
// check 'button' type
result = getShallowRendererOutput(
<Button type="button">
test
</Button>
);
assert.equal(result.props.type, 'button');
});
it('supports click callbacks', function(done) {
// define callback
let fn = function() {
done();
}
let node = ReactUtils.renderIntoDocument(
<Button onClick={ fn }>test</Button>
);
// click on button
ReactUtils.Simulate.click(node.refs.buttonEl);
});
it('renders ripples on click', function() {
let node = ReactUtils.renderIntoDocument(<Button>test</Button>);
let buttonEl = node.refs.buttonEl;
// check state before ripple
assert.equal(Object.keys(node.state.ripples).length, 0);
assert.equal(buttonEl.children.length, 0);
// trigger ripple
ReactUtils.Simulate.mouseDown(buttonEl);
// check state after ripple
assert.equal(Object.keys(node.state.ripples).length, 1);
assert.equal(buttonEl.children.length, 1);
assert.equal(buttonEl.children[0].className, 'mui-ripple-effect');
// add another ripple
ReactUtils.Simulate.mouseDown(node.refs.buttonEl);
assert.equal(Object.keys(node.state.ripples).length, 2);
});
it('removes ripples after two seconds', function(done) {
this.timeout(2050);
let node = ReactUtils.renderIntoDocument(<Button>test</Button>);
ReactUtils.Simulate.mouseDown(node.refs.buttonEl);
assert.equal(Object.keys(node.state.ripples).length, 1);
setTimeout(function() {
// check that ripple is still there
assert.equal(Object.keys(node.state.ripples).length, 1);
}, 1000);
setTimeout(function() {
// check that ripple has been removed
assert.equal(Object.keys(node.state.ripples).length, 0);
done();
}, 2001);
});
});