2c00b6fd
oyv1cent
Add Affix compone...
|
1
2
3
4
5
6
7
8
9
10
|
import { createVue, destroyVM } from '../util';
describe('Affix.vue', () => {
let vm;
afterEach(() => {
destroyVM(vm);
});
it('should create a Affix component without slot', done => {
vm = createVue('<Affix></Affix>');
|
e1f6c928
oyv1cent
optimization
|
11
12
13
14
|
const affix = vm.$el.children[0];
expect(affix.tagName).to.equal('DIV');
expect(affix.className).to.equal('');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
15
16
17
|
done();
});
|
1bf44ee0
oyv1cent
better description
|
18
|
it('should create a Affix component contain slot', done => {
|
2c00b6fd
oyv1cent
Add Affix compone...
|
19
20
21
22
23
|
vm = createVue(`
<Affix>
<span class="demo-affix">Fixed at the top</span>
</Affix>
`);
|
e1f6c928
oyv1cent
optimization
|
24
25
26
27
|
const slot = vm.$el.children[0].children[0];
expect(slot.tagName).to.equal('SPAN');
expect(slot.className).to.equal('demo-affix');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
28
29
30
|
done();
});
|
1bf44ee0
oyv1cent
better description
|
31
|
it('only set offset-top props', done => {
|
2c00b6fd
oyv1cent
Add Affix compone...
|
32
33
34
35
36
37
38
39
|
vm = createVue(`
<div>
<Affix :offset-top="20">
<span class="demo-affix">Fixed at the top</span>
</Affix>
<div style="width: 100%; height: 2000px"></div>
</div>
`, true);
|
e1f6c928
oyv1cent
optimization
|
40
41
42
43
44
45
|
const affix = vm.$el.children[0].children[0];
const fakeBlock = vm.$el.children[0].children[1];
expect(affix.classList.contains('ivu-affix')).to.false;
expect(affix.style.top).to.equal('');
expect(fakeBlock.style.display).to.equal('none');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
46
47
|
window.scrollTo(0, 10000);
setTimeout(()=>{
|
e1f6c928
oyv1cent
optimization
|
48
49
50
|
expect(affix.classList.contains('ivu-affix')).to.true;
expect(affix.style.top).to.equal('20px');
expect(fakeBlock.style.display).to.equal('');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
51
52
53
54
|
done();
}, 100);
});
|
1bf44ee0
oyv1cent
better description
|
55
|
it('only set offset-bottom props', done => {
|
2c00b6fd
oyv1cent
Add Affix compone...
|
56
57
58
59
60
61
62
63
64
|
vm = createVue(`
<div>
<div style="width: 100%; height: 2000px"></div>
<Affix :offset-bottom="20">
<span class="demo-affix">Fixed at the top</span>
</Affix>
<div style="width: 100%; height: 2000px"></div>
</div>
`, true);
|
e1f6c928
oyv1cent
optimization
|
65
66
67
68
|
const affix = vm.$el.children[1].children[0];
expect(affix.classList.contains('ivu-affix')).to.false;
expect(affix.style.bottom).to.equal('');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
69
70
71
72
|
// Affix component haven't run handleScroll function when component mounted in real dom.
// use scrollTo() to trigger scroll event.
window.scrollTo(0, 100);
setTimeout(()=>{
|
e1f6c928
oyv1cent
optimization
|
73
74
|
expect(affix.classList.contains('ivu-affix')).to.true;
expect(affix.style.bottom).to.equal('20px');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
75
76
|
window.scrollTo(0, 10000);
setTimeout(()=>{
|
e1f6c928
oyv1cent
optimization
|
77
78
|
expect(affix.classList.contains('ivu-affix')).to.false;
expect(affix.style.bottom).to.equal('');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
done();
}, 100);
}, 100);
});
it('both props are set, only offset-bottom is valid', done => {
vm = createVue(`
<div>
<div style="width: 100%; height: 2000px"></div>
<Affix :offset-bottom="20" :offset-top="20">
<span class="demo-affix">Fixed at the top</span>
</Affix>
<div style="width: 100%; height: 2000px"></div>
</div>
`, true);
|
e1f6c928
oyv1cent
optimization
|
94
95
96
97
|
const affix = vm.$el.children[1].children[0];
expect(affix.classList.contains('ivu-affix')).to.false;
expect(affix.style.bottom).to.equal('');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
98
99
100
101
|
// Affix component haven't run handleScroll function when component mounted in real dom.
// use scrollTo() to trigger scroll event.
window.scrollTo(0, 100);
setTimeout(()=>{
|
e1f6c928
oyv1cent
optimization
|
102
103
|
expect(affix.classList.contains('ivu-affix')).to.true;
expect(affix.style.bottom).to.equal('20px');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
104
105
|
window.scrollTo(0, 10000);
setTimeout(()=>{
|
e1f6c928
oyv1cent
optimization
|
106
107
|
expect(affix.classList.contains('ivu-affix')).to.false;
expect(affix.style.bottom).to.equal('');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
108
109
110
111
112
|
done();
}, 100);
}, 100);
});
|
1bf44ee0
oyv1cent
better description
|
113
|
it('both props are not set, should fixed top and top equal 0px', done => {
|
2c00b6fd
oyv1cent
Add Affix compone...
|
114
115
116
117
118
119
120
121
|
vm = createVue(`
<div>
<Affix>
<span class="demo-affix">Fixed at the top</span>
</Affix>
<div style="width: 100%; height: 2000px"></div>
</div>
`, true);
|
e1f6c928
oyv1cent
optimization
|
122
123
124
125
126
127
|
const affix = vm.$el.children[0].children[0];
const fakeBlock = vm.$el.children[0].children[1];
expect(affix.classList.contains('ivu-affix')).to.false;
expect(affix.style.top).to.equal('');
expect(fakeBlock.style.display).to.equal('none');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
128
129
|
window.scrollTo(0, 10000);
setTimeout(()=>{
|
e1f6c928
oyv1cent
optimization
|
130
131
132
|
expect(affix.classList.contains('ivu-affix')).to.true;
expect(affix.style.top).to.equal('0px');
expect(fakeBlock.style.display).to.equal('');
|
2c00b6fd
oyv1cent
Add Affix compone...
|
133
134
135
136
137
|
done();
}, 100);
});
});
|