optimization
This commit is contained in:
parent
1bf44ee08c
commit
e1f6c92819
1 changed files with 42 additions and 28 deletions
|
@ -8,8 +8,10 @@ describe('Affix.vue', () => {
|
||||||
|
|
||||||
it('should create a Affix component without slot', done => {
|
it('should create a Affix component without slot', done => {
|
||||||
vm = createVue('<Affix></Affix>');
|
vm = createVue('<Affix></Affix>');
|
||||||
expect(vm.$el.children[0].tagName).to.equal('DIV');
|
const affix = vm.$el.children[0];
|
||||||
expect(vm.$el.children[0].className).to.equal('');
|
|
||||||
|
expect(affix.tagName).to.equal('DIV');
|
||||||
|
expect(affix.className).to.equal('');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,8 +21,10 @@ describe('Affix.vue', () => {
|
||||||
<span class="demo-affix">Fixed at the top</span>
|
<span class="demo-affix">Fixed at the top</span>
|
||||||
</Affix>
|
</Affix>
|
||||||
`);
|
`);
|
||||||
expect(vm.$el.children[0].children[0].tagName).to.equal('SPAN');
|
const slot = vm.$el.children[0].children[0];
|
||||||
expect(vm.$el.children[0].children[0].className).to.equal('demo-affix');
|
|
||||||
|
expect(slot.tagName).to.equal('SPAN');
|
||||||
|
expect(slot.className).to.equal('demo-affix');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,14 +37,17 @@ describe('Affix.vue', () => {
|
||||||
<div style="width: 100%; height: 2000px"></div>
|
<div style="width: 100%; height: 2000px"></div>
|
||||||
</div>
|
</div>
|
||||||
`, true);
|
`, true);
|
||||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.false;
|
const affix = vm.$el.children[0].children[0];
|
||||||
expect(vm.$el.children[0].children[0].style.top).to.equal('');
|
const fakeBlock = vm.$el.children[0].children[1];
|
||||||
expect(vm.$el.children[0].children[1].style.display).to.equal('none');
|
|
||||||
|
expect(affix.classList.contains('ivu-affix')).to.false;
|
||||||
|
expect(affix.style.top).to.equal('');
|
||||||
|
expect(fakeBlock.style.display).to.equal('none');
|
||||||
window.scrollTo(0, 10000);
|
window.scrollTo(0, 10000);
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.true;
|
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||||
expect(vm.$el.children[0].children[0].style.top).to.equal('20px');
|
expect(affix.style.top).to.equal('20px');
|
||||||
expect(vm.$el.children[0].children[1].style.display).to.equal('');
|
expect(fakeBlock.style.display).to.equal('');
|
||||||
done();
|
done();
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
@ -55,18 +62,20 @@ describe('Affix.vue', () => {
|
||||||
<div style="width: 100%; height: 2000px"></div>
|
<div style="width: 100%; height: 2000px"></div>
|
||||||
</div>
|
</div>
|
||||||
`, true);
|
`, true);
|
||||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
const affix = vm.$el.children[1].children[0];
|
||||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('');
|
|
||||||
|
expect(affix.classList.contains('ivu-affix')).to.false;
|
||||||
|
expect(affix.style.bottom).to.equal('');
|
||||||
// Affix component haven't run handleScroll function when component mounted in real dom.
|
// Affix component haven't run handleScroll function when component mounted in real dom.
|
||||||
// use scrollTo() to trigger scroll event.
|
// use scrollTo() to trigger scroll event.
|
||||||
window.scrollTo(0, 100);
|
window.scrollTo(0, 100);
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.true;
|
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('20px');
|
expect(affix.style.bottom).to.equal('20px');
|
||||||
window.scrollTo(0, 10000);
|
window.scrollTo(0, 10000);
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
expect(affix.classList.contains('ivu-affix')).to.false;
|
||||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('');
|
expect(affix.style.bottom).to.equal('');
|
||||||
done();
|
done();
|
||||||
}, 100);
|
}, 100);
|
||||||
}, 100);
|
}, 100);
|
||||||
|
@ -82,18 +91,20 @@ describe('Affix.vue', () => {
|
||||||
<div style="width: 100%; height: 2000px"></div>
|
<div style="width: 100%; height: 2000px"></div>
|
||||||
</div>
|
</div>
|
||||||
`, true);
|
`, true);
|
||||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
const affix = vm.$el.children[1].children[0];
|
||||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('');
|
|
||||||
|
expect(affix.classList.contains('ivu-affix')).to.false;
|
||||||
|
expect(affix.style.bottom).to.equal('');
|
||||||
// Affix component haven't run handleScroll function when component mounted in real dom.
|
// Affix component haven't run handleScroll function when component mounted in real dom.
|
||||||
// use scrollTo() to trigger scroll event.
|
// use scrollTo() to trigger scroll event.
|
||||||
window.scrollTo(0, 100);
|
window.scrollTo(0, 100);
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.true;
|
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('20px');
|
expect(affix.style.bottom).to.equal('20px');
|
||||||
window.scrollTo(0, 10000);
|
window.scrollTo(0, 10000);
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
expect(affix.classList.contains('ivu-affix')).to.false;
|
||||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('');
|
expect(affix.style.bottom).to.equal('');
|
||||||
done();
|
done();
|
||||||
}, 100);
|
}, 100);
|
||||||
}, 100);
|
}, 100);
|
||||||
|
@ -108,14 +119,17 @@ describe('Affix.vue', () => {
|
||||||
<div style="width: 100%; height: 2000px"></div>
|
<div style="width: 100%; height: 2000px"></div>
|
||||||
</div>
|
</div>
|
||||||
`, true);
|
`, true);
|
||||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.false;
|
const affix = vm.$el.children[0].children[0];
|
||||||
expect(vm.$el.children[0].children[0].style.top).to.equal('');
|
const fakeBlock = vm.$el.children[0].children[1];
|
||||||
expect(vm.$el.children[0].children[1].style.display).to.equal('none');
|
|
||||||
|
expect(affix.classList.contains('ivu-affix')).to.false;
|
||||||
|
expect(affix.style.top).to.equal('');
|
||||||
|
expect(fakeBlock.style.display).to.equal('none');
|
||||||
window.scrollTo(0, 10000);
|
window.scrollTo(0, 10000);
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.true;
|
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||||
expect(vm.$el.children[0].children[0].style.top).to.equal('0px');
|
expect(affix.style.top).to.equal('0px');
|
||||||
expect(vm.$el.children[0].children[1].style.display).to.equal('');
|
expect(fakeBlock.style.display).to.equal('');
|
||||||
done();
|
done();
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue