This repository was archived by the owner on Apr 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcsstransitiongroup.spec.tsx
192 lines (162 loc) · 6.06 KB
/
csstransitiongroup.spec.tsx
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 * as React from "react";
import { assert } from "chai";
import { ShallowWrapper, shallow } from "enzyme";
import { SinonSpy, spy } from "sinon";
import {
CSSTransitionGroup, CSSTransitionGroupProps,
CSSTransitionGroupChild, CSSTransitionGroupChildProps,
} from "./csstransitiongroup";
const Element = (_props: any): any => { return null; };
describe("csstransitiongroup.tsx", () => {
describe("<CSSTransitionGroup>", () => {
let getWrapper: (props?: CSSTransitionGroupProps) => ShallowWrapper<CSSTransitionGroupProps, {}>;
before(() => {
getWrapper = (props?) => shallow(
<CSSTransitionGroup {...props} />,
);
});
it("should pass down unknown props", () => {
const wrapper = getWrapper(
{ id: "abc", children: <span key="child" /> },
);
const { id } = wrapper.find("TransitionGroup").props();
assert.strictEqual(id, "abc");
});
it("should wrap children in CSSTransitionGroupChild", () => {
const wrapper = getWrapper(
{ id: "abc", children: [<span />, <span />] },
);
assert.lengthOf(wrapper.find("CSSTransitionGroupChild"), 2);
});
it("should pass transitionAppear to CSSTransitionGroupChild", () => {
const wrapper = getWrapper(
{ transitionAppear: true, id: "abc", children: [<span />] },
);
assert.isTrue((wrapper.find("CSSTransitionGroupChild").props() as any).transitionAppear);
});
it("should set mounted=false on CSSTransitionGroupChild", () => {
const wrapper = getWrapper(
{ id: "abc", children: [<span />] },
);
assert.isFalse((wrapper.find("CSSTransitionGroupChild").props() as any).mounted);
});
it("should set mounted=true on added CSSTransitionGroupChild", () => {
const wrapper = getWrapper(
{ id: "abc", children: [] },
);
(wrapper.instance() as any).componentDidMount();
wrapper.setProps({ children: [<span />] });
assert.isTrue((wrapper.find("CSSTransitionGroupChild").props() as any).mounted);
});
it("should set key of CSSTransitionGroupChild to match keys of children", () => {
const wrapper = getWrapper(
{ id: "abc", children: [<span key="mykey" />] },
);
assert.strictEqual((wrapper.find("CSSTransitionGroupChild").key()), ".$mykey");
});
});
describe("<CSSTransitionGroupChild>", () => {
let getWrapper: (props?: CSSTransitionGroupChildProps) => ShallowWrapper<CSSTransitionGroupChildProps, {}>;
before(() => {
getWrapper = (props?) => shallow(
<CSSTransitionGroupChild {...props} />,
);
});
it("should pass transitionAppear to child", () => {
const wrapper = getWrapper(
{ transitionAppear: true, children: <Element /> },
);
assert.isTrue((wrapper.find(Element).props() as any).transitionAppear);
});
it("should pass transitionAppear=true when mounted=true", () => {
const wrapper = getWrapper(
{ mounted: true, children: <Element /> },
);
assert.isTrue((wrapper.find(Element).props() as any).transitionAppear);
});
it("should set transitionAppear=false when mounted=false", () => {
const wrapper = getWrapper(
{ mounted: false, children: <Element /> },
);
assert.isFalse((wrapper.find(Element).props() as any).transitionAppear);
});
it("should set active=true", () => {
const wrapper = getWrapper(
{ children: <Element /> },
);
assert.isTrue((wrapper.find(Element).props() as any).active);
});
it("should inmediately call callback on componentWillAppear()", () => {
const wrapper = getWrapper(
{ children: <Element /> },
);
const done = spy();
(wrapper.instance() as any).componentWillAppear(done);
assert.isTrue(done.calledOnce);
});
it("should inmediately call callback on componentWillEnter()", () => {
const wrapper = getWrapper(
{ children: <Element /> },
);
const done = spy();
(wrapper.instance() as any).componentWillEnter(done);
assert.isTrue(done.calledOnce);
});
describe("onComponentWillLeave", () => {
let onTransitionComplete: SinonSpy;
let done: SinonSpy;
let wrapper: ShallowWrapper<CSSTransitionGroupChildProps, {}>;
before(() => {
onTransitionComplete = spy();
done = spy();
wrapper = getWrapper(
{
children: <Element onTransitionComplete={onTransitionComplete} />,
},
);
(wrapper.instance() as any).componentWillLeave(done);
});
it("should set active=false", () => {
assert.isFalse((wrapper.find(Element).props() as any).active);
});
it("should not inmediately call callback", () => {
assert.isFalse(done.calledOnce);
});
it("should call callback after transition completed", () => {
wrapper.simulate("transitionComplete");
assert.isTrue(done.calledOnce);
});
it("should call user onTransitionComplete", () => {
assert.isTrue(onTransitionComplete.calledOnce);
});
});
describe("revert leaving", () => {
let onTransitionComplete: SinonSpy;
let leaveDone: SinonSpy;
let enterDone: SinonSpy;
let wrapper: ShallowWrapper<CSSTransitionGroupChildProps, {}>;
before(() => {
onTransitionComplete = spy();
leaveDone = spy();
enterDone = spy();
wrapper = getWrapper(
{
children: <Element onTransitionComplete={onTransitionComplete} />,
},
);
(wrapper.instance() as any).componentWillLeave(leaveDone);
(wrapper.instance() as any).componentWillEnter(enterDone);
});
it("should set active=true", () => {
assert.isTrue((wrapper.find(Element).props() as any).active);
});
it("should inmediately call enter done callback", () => {
assert.isTrue(enterDone.calledOnce);
});
it("should not call leave done callback", () => {
wrapper.simulate("transitionComplete");
assert.isTrue(leaveDone.notCalled);
});
});
});
});