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 => {
|
||||
vm = createVue('<Affix></Affix>');
|
||||
expect(vm.$el.children[0].tagName).to.equal('DIV');
|
||||
expect(vm.$el.children[0].className).to.equal('');
|
||||
const affix = vm.$el.children[0];
|
||||
|
||||
expect(affix.tagName).to.equal('DIV');
|
||||
expect(affix.className).to.equal('');
|
||||
done();
|
||||
});
|
||||
|
||||
|
@ -19,8 +21,10 @@ describe('Affix.vue', () => {
|
|||
<span class="demo-affix">Fixed at the top</span>
|
||||
</Affix>
|
||||
`);
|
||||
expect(vm.$el.children[0].children[0].tagName).to.equal('SPAN');
|
||||
expect(vm.$el.children[0].children[0].className).to.equal('demo-affix');
|
||||
const slot = vm.$el.children[0].children[0];
|
||||
|
||||
expect(slot.tagName).to.equal('SPAN');
|
||||
expect(slot.className).to.equal('demo-affix');
|
||||
done();
|
||||
});
|
||||
|
||||
|
@ -33,14 +37,17 @@ describe('Affix.vue', () => {
|
|||
<div style="width: 100%; height: 2000px"></div>
|
||||
</div>
|
||||
`, true);
|
||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.false;
|
||||
expect(vm.$el.children[0].children[0].style.top).to.equal('');
|
||||
expect(vm.$el.children[0].children[1].style.display).to.equal('none');
|
||||
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');
|
||||
window.scrollTo(0, 10000);
|
||||
setTimeout(()=>{
|
||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.true;
|
||||
expect(vm.$el.children[0].children[0].style.top).to.equal('20px');
|
||||
expect(vm.$el.children[0].children[1].style.display).to.equal('');
|
||||
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||
expect(affix.style.top).to.equal('20px');
|
||||
expect(fakeBlock.style.display).to.equal('');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
@ -55,18 +62,20 @@ describe('Affix.vue', () => {
|
|||
<div style="width: 100%; height: 2000px"></div>
|
||||
</div>
|
||||
`, true);
|
||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('');
|
||||
const affix = vm.$el.children[1].children[0];
|
||||
|
||||
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.
|
||||
// use scrollTo() to trigger scroll event.
|
||||
window.scrollTo(0, 100);
|
||||
setTimeout(()=>{
|
||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.true;
|
||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('20px');
|
||||
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||
expect(affix.style.bottom).to.equal('20px');
|
||||
window.scrollTo(0, 10000);
|
||||
setTimeout(()=>{
|
||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
||||
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('');
|
||||
done();
|
||||
}, 100);
|
||||
}, 100);
|
||||
|
@ -82,18 +91,20 @@ describe('Affix.vue', () => {
|
|||
<div style="width: 100%; height: 2000px"></div>
|
||||
</div>
|
||||
`, true);
|
||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('');
|
||||
const affix = vm.$el.children[1].children[0];
|
||||
|
||||
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.
|
||||
// use scrollTo() to trigger scroll event.
|
||||
window.scrollTo(0, 100);
|
||||
setTimeout(()=>{
|
||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.true;
|
||||
expect(vm.$el.children[1].children[0].style.bottom).to.equal('20px');
|
||||
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||
expect(affix.style.bottom).to.equal('20px');
|
||||
window.scrollTo(0, 10000);
|
||||
setTimeout(()=>{
|
||||
expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false;
|
||||
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('');
|
||||
done();
|
||||
}, 100);
|
||||
}, 100);
|
||||
|
@ -108,14 +119,17 @@ describe('Affix.vue', () => {
|
|||
<div style="width: 100%; height: 2000px"></div>
|
||||
</div>
|
||||
`, true);
|
||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.false;
|
||||
expect(vm.$el.children[0].children[0].style.top).to.equal('');
|
||||
expect(vm.$el.children[0].children[1].style.display).to.equal('none');
|
||||
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');
|
||||
window.scrollTo(0, 10000);
|
||||
setTimeout(()=>{
|
||||
expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.true;
|
||||
expect(vm.$el.children[0].children[0].style.top).to.equal('0px');
|
||||
expect(vm.$el.children[0].children[1].style.display).to.equal('');
|
||||
expect(affix.classList.contains('ivu-affix')).to.true;
|
||||
expect(affix.style.top).to.equal('0px');
|
||||
expect(fakeBlock.style.display).to.equal('');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue