Skip to content

Commit 842663f

Browse files
committed
tests for staggering transitions
1 parent 93a10b5 commit 842663f

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
var Vue = require('../../../src/vue')
2+
var _ = Vue.util
3+
4+
describe('Staggering Transitions', function () {
5+
6+
var el
7+
var amount = 50
8+
beforeEach(function () {
9+
el = document.createElement('div')
10+
document.body.appendChild(el)
11+
})
12+
13+
afterEach(function () {
14+
document.body.removeChild(el)
15+
})
16+
17+
it('as attribute', function (done) {
18+
var vm = new Vue({
19+
el: el,
20+
template: '<div v-repeat="list" v-transition="stagger" stagger="' + amount + '">{{a}}</div>',
21+
data: {
22+
list: []
23+
},
24+
transitions: {
25+
stagger: {
26+
enter: function (el, done) {
27+
_.nextTick(done)
28+
},
29+
leave: function (el, done) {
30+
_.nextTick(done)
31+
}
32+
}
33+
}
34+
})
35+
assertStagger(vm, done)
36+
})
37+
38+
it('as hook', function (done) {
39+
var vm = new Vue({
40+
el: el,
41+
template: '<div v-repeat="list" v-transition="stagger">{{a}}</div>',
42+
data: {
43+
list: []
44+
},
45+
transitions: {
46+
stagger: {
47+
stagger: function (i) {
48+
return i * amount
49+
},
50+
enter: function (el, done) {
51+
_.nextTick(done)
52+
},
53+
leave: function (el, done) {
54+
_.nextTick(done)
55+
}
56+
}
57+
}
58+
})
59+
assertStagger(vm, done)
60+
})
61+
62+
it('remove while staggered', function (done) {
63+
var vm = new Vue({
64+
el: el,
65+
template: '<div v-repeat="list" v-transition="stagger" stagger="' + amount + '">{{a}}</div>',
66+
data: {
67+
list: []
68+
},
69+
transitions: {
70+
stagger: {
71+
enter: function (el, done) {
72+
_.nextTick(done)
73+
},
74+
leave: function (el, done) {
75+
_.nextTick(done)
76+
}
77+
}
78+
}
79+
})
80+
vm.list = [{a: 1}, {a: 2}]
81+
expect(el.innerHTML).toBe('')
82+
_.nextTick(function () {
83+
expect(el.innerHTML).toBe('<div class="stagger-transition stagger-enter">1</div>')
84+
vm.list = [vm.list[0]] // remove second
85+
setTimeout(function () {
86+
// should have only one
87+
expect(el.innerHTML).toBe('<div class="stagger-transition">1</div>')
88+
done()
89+
}, amount + 10)
90+
})
91+
})
92+
93+
it('reorder while staggered', function (done) {
94+
var vm = new Vue({
95+
el: el,
96+
template: '<div v-repeat="list" v-transition="stagger" stagger="' + amount + '">{{a}}</div>',
97+
data: {
98+
list: []
99+
},
100+
transitions: {
101+
stagger: {
102+
enter: function (el, done) {
103+
_.nextTick(done)
104+
},
105+
leave: function (el, done) {
106+
_.nextTick(done)
107+
}
108+
}
109+
}
110+
})
111+
vm.list = [{a: 1}, {a: 2}]
112+
expect(el.innerHTML).toBe('')
113+
_.nextTick(function () {
114+
expect(el.innerHTML).toBe('<div class="stagger-transition stagger-enter">1</div>')
115+
vm.list = [vm.list[1], vm.list[0]] // reorder
116+
setTimeout(function () {
117+
// should have correct order
118+
expect(el.innerHTML).toBe(
119+
'<div class="stagger-transition">2</div>' +
120+
'<div class="stagger-transition">1</div>'
121+
)
122+
done()
123+
}, amount + 10)
124+
})
125+
})
126+
127+
function assertStagger (vm, done) {
128+
vm.list = [{a:1}, {a:2}]
129+
expect(el.innerHTML).toBe('')
130+
_.nextTick(function () {
131+
expect(el.innerHTML).toBe('<div class="stagger-transition stagger-enter">1</div>')
132+
_.nextTick(function () {
133+
expect(el.innerHTML).toBe('<div class="stagger-transition">1</div>')
134+
setTimeout(function () {
135+
expect(el.innerHTML).toBe(
136+
'<div class="stagger-transition">1</div>' +
137+
'<div class="stagger-transition">2</div>'
138+
)
139+
vm.list = []
140+
_.nextTick(function () {
141+
expect(el.innerHTML).toBe(
142+
'<div class="stagger-transition stagger-leave">1</div>' +
143+
'<div class="stagger-transition">2</div>'
144+
)
145+
_.nextTick(function () {
146+
expect(el.innerHTML).toBe('<div class="stagger-transition">2</div>')
147+
setTimeout(function () {
148+
expect(el.innerHTML).toBe('')
149+
done()
150+
}, amount + 10)
151+
})
152+
})
153+
}, amount + 10)
154+
})
155+
})
156+
}
157+
158+
})

0 commit comments

Comments
 (0)