forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-spec.js
192 lines (170 loc) · 6.09 KB
/
index-spec.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import assert from 'power-assert';
import co from 'co';
import { dom, env } from '../../src/util';
import Animate from '../../src/animate';
import './index-spec.scss';
/* eslint-disable react/jsx-filename-extension, react/no-multi-comp, react/prop-types, react/prefer-stateless-function */
/* global describe, it, beforeEach, afterEach */
const { hasClass, getStyle } = dom;
const { ieVersion } = env;
class Demo extends React.Component {
static propTypes = {
visible: PropTypes.bool,
expand: PropTypes.bool,
};
static defaultProps = {
visible: false,
expand: false,
};
constructor(props) {
super(props);
this.state = { visible: props.visible };
this.handleToggle = this.handleToggle.bind(this);
}
handleToggle() {
this.setState({
visible: !this.state.visible,
});
}
render() {
// eslint-disable-next-line
const { visible, expand, ...others } = this.props;
const A = expand ? Animate.Expand : Animate;
return (
<div>
<button onClick={this.handleToggle}>Toggle visible</button>
<A animation="my-zoom" {...others}>
{this.state.visible ? (
<div className="basic-demo">Next Animate</div>
) : null}
</A>
</div>
);
}
}
const delay = time => new Promise(resolve => setTimeout(resolve, time));
describe('Animate', () => {
let mountNode;
beforeEach(() => {
mountNode = document.createElement('div');
document.body.appendChild(mountNode);
});
afterEach(() => {
ReactDOM.unmountComponentAtNode(mountNode);
document.body.removeChild(mountNode);
});
if (ieVersion === 9) {
it('should visible and hide immediately', () => {
ReactDOM.render(<Demo visible />, mountNode);
assert(document.querySelector('.basic-demo'));
const btn = document.querySelector('button');
btn.click();
assert(!document.querySelector('.basic-demo'));
btn.click();
assert(document.querySelector('.basic-demo'));
});
return;
}
it('should play appear animation', () => {
return co(function*() {
ReactDOM.render(<Demo visible />, mountNode);
const demo = document.querySelector('.basic-demo');
assert(hasClass(demo, 'my-zoom-appear'));
yield delay(15);
assert(hasClass(demo, 'my-zoom-appear-active'));
yield delay(600);
assert(!hasClass(demo, 'my-zoom-appear'));
assert(!hasClass(demo, 'my-zoom-appear-active'));
});
});
it('should not play appear animation if set animationAppear to false', () => {
return co(function*() {
ReactDOM.render(
<Demo visible animationAppear={false} />,
mountNode
);
const demo = document.querySelector('.basic-demo');
assert(!hasClass(demo, 'my-zoom-appear'));
yield delay(15);
assert(!hasClass(demo, 'my-zoom-appear-active'));
});
});
it('should play enter animation', () => {
return co(function*() {
ReactDOM.render(<Demo />, mountNode);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
assert(hasClass(demo, 'my-zoom-enter'));
yield delay(15);
assert(hasClass(demo, 'my-zoom-enter-active'));
yield delay(600);
assert(!hasClass(demo, 'my-zoom-enter'));
assert(!hasClass(demo, 'my-zoom-enter-active'));
});
});
it('should play leave animation', () => {
return co(function*() {
ReactDOM.render(
<Demo visible animationAppear={false} />,
mountNode
);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
assert(hasClass(demo, 'my-zoom-leave'));
yield delay(15);
assert(hasClass(demo, 'my-zoom-leave-active'));
yield delay(600);
assert(!document.querySelector('.basic-demo'));
});
});
it('should support passing object to animation property', () => {
return co(function*() {
ReactDOM.render(
<Demo
animation={{
enter: 'my-zoom-in',
leave: 'my-zoom-out',
}}
/>,
mountNode
);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
assert(hasClass(demo, 'my-zoom-in'));
yield delay(15);
assert(hasClass(demo, 'my-zoom-in-active'));
yield delay(600);
assert(!hasClass(demo, 'my-zoom-in'));
assert(!hasClass(demo, 'my-zoom-in-active'));
btn.click();
assert(hasClass(demo, 'my-zoom-out'));
yield delay(15);
assert(hasClass(demo, 'my-zoom-out-active'));
yield delay(600);
assert(!document.querySelector('.basic-demo'));
});
});
it('should play expand animation', () => {
return co(function*() {
ReactDOM.render(
<Demo visible={false} expand animation="expand" />,
mountNode
);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
assert(getStyle(demo, 'height') === 0);
yield delay(500);
assert(getStyle(demo, 'height') === 200);
btn.click();
yield delay(500);
assert(!document.querySelector('.basic-demo'));
});
});
});