Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dropdown test #624

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions test/unit/specs/dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { createVue, triggerEvent } from '../util';

describe('Dropdown', () => {
it('create', done => {
const vm = createVue({
template: `
<el-dropdown>
<span class="el-dropdown-link">
下拉菜单<i class="el-icon-caret-bottom el-icon-right"></i>
</span>
<el-dropdown-menu slot="dropdown" class="dropdown-test-creat">
<el-dropdown-item>黄金糕</el-dropdown-item>
<el-dropdown-item>狮子头</el-dropdown-item>
<el-dropdown-item>螺蛳粉</el-dropdown-item>
<el-dropdown-item>双皮奶</el-dropdown-item>
<el-dropdown-item>蚵仔煎</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
`
}, true);
let dropdownElm = vm.$el;
let triggerElm = dropdownElm.children[0];

triggerEvent(triggerElm, 'mouseenter');
setTimeout(_ => {
var dropdownMenu = document.querySelector('.dropdown-test-creat');
expect(dropdownMenu.style.display).to.not.ok;

triggerEvent(triggerElm, 'mouseleave');
setTimeout(_ => {
expect(dropdownMenu.style.display).to.be.equal('none');
done();
}, 600);
}, 400);
});
it('menu click', done => {
const vm = createVue({
template: `
<el-dropdown>
<span class="el-dropdown-link">
下拉菜单<i class="el-icon-caret-bottom el-icon-right"></i>
</span>
<el-dropdown-menu slot="dropdown" class="dropdown-test-menu-click">
<el-dropdown-item>黄金糕</el-dropdown-item>
<el-dropdown-item @click.native="handleClick">狮子头</el-dropdown-item>
<el-dropdown-item>螺蛳粉</el-dropdown-item>
<el-dropdown-item>双皮奶</el-dropdown-item>
<el-dropdown-item>蚵仔煎</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
`,
data() {
return {
clickedItem: ''
};
},
methods: {
handleClick(ev) {
this.clickedItem = ev.target.innerText;
}
}
}, true);
let dropdownElm = vm.$el;
let triggerElm = dropdownElm.children[0];

triggerEvent(triggerElm, 'mouseenter');
setTimeout(_ => {
let dropdownMenu = document.querySelector('.dropdown-test-menu-click');
dropdownMenu.children[1].click();
setTimeout(_ => {
expect(dropdownMenu.style.display).to.be.equal('none');
expect(vm.clickedItem).to.be.equal('狮子头');
done();
}, 600);
}, 400);
});
it('trigger', done => {
const vm = createVue({
template: `
<el-dropdown trigger="click" ref="dropdown">
<span class="el-dropdown-link">
下拉菜单trigger click<i class="el-icon-caret-bottom el-icon-right"></i>
</span>
<el-dropdown-menu slot="dropdown" class="dropdown-test-menu-click">
<el-dropdown-item>黄金糕</el-dropdown-item>
<el-dropdown-item @click.native="handleClick">狮子头</el-dropdown-item>
<el-dropdown-item>螺蛳粉</el-dropdown-item>
<el-dropdown-item>双皮奶</el-dropdown-item>
<el-dropdown-item>蚵仔煎</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
`,
data() {
return {
clickedItem: ''
};
},
methods: {
handleClick(ev) {
this.clickedItem = ev.target.innerText;
}
}
}, true);
let dropdownElm = vm.$el;
let dropdown = vm.$refs.dropdown;
let triggerElm = dropdownElm.children[0];

triggerEvent(triggerElm, 'mouseenter');
dropdown.$nextTick(_ => {
expect(dropdown.visible).to.not.true;

dropdownElm.children[0].click();
dropdown.$nextTick(_ => {
expect(dropdown.visible).to.be.true;
done();
});
});
});
it('split button', done => {
const vm = createVue({
template: `
<el-dropdown split-button type="primary" @click="handleClick" ref="dropdown">
更多菜单
<el-dropdown-menu slot="dropdown" class="dropdown-test-split-button">
<el-dropdown-item>黄金糕</el-dropdown-item>
<el-dropdown-item>狮子头</el-dropdown-item>
<el-dropdown-item>螺蛳粉</el-dropdown-item>
<el-dropdown-item>双皮奶</el-dropdown-item>
<el-dropdown-item>蚵仔煎</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
`,
data() {
return {
btnClicked: false
};
},
methods: {
handleClick(ev) {
this.btnClicked = true;
}
}
}, true);

let dropdown = vm.$refs.dropdown;
let dropdownElm = dropdown.$el;
let triggerElm = dropdownElm.querySelector('.el-dropdown__caret-button');

triggerEvent(triggerElm, 'mouseenter');
setTimeout(_ => {
expect(dropdown.visible).to.be.true;

triggerEvent(triggerElm, 'mouseleave');
setTimeout(_ => {
expect(dropdown.visible).to.not.true;
done();
}, 400);
}, 400);
});
});