forked from Happy-Coding-Clans/vue-easytable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathve-select.spec.js
101 lines (85 loc) · 2.61 KB
/
ve-select.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { mount } from "@vue/test-utils";
import veSelect from "@/ve-select";
import { later } from "../util";
describe("veSelect", () => {
// select items
const SELECT_ITEMS = [
{ value: 0, label: "Apple" },
{ value: 1, label: "Orange", selected: true },
{ value: 2, label: "Banana" },
];
it("render by value prop", () => {
const wrapper = mount({
render() {
return <veSelect value={SELECT_ITEMS} placeholder="姓名" />;
},
});
expect(wrapper.html()).toMatchSnapshot();
});
it("render by isMultiple prop", () => {
const wrapper = mount({
render() {
return (
<veSelect
value={SELECT_ITEMS}
placeholder="姓名"
isMultiple
/>
);
},
});
expect(wrapper.html()).toMatchSnapshot();
});
it("render by isInput prop", () => {
const wrapper = mount({
render() {
return (
<veSelect value={SELECT_ITEMS} placeholder="姓名" isInput />
);
},
});
expect(wrapper.html()).toMatchSnapshot();
});
it("width prop", () => {
const wrapper = mount(veSelect, {
propsData: {
value: SELECT_ITEMS,
width: 120,
},
});
expect(
wrapper.find(".ve-dropdown-dt-selected").attributes("style"),
).toBe("width: 120px;");
});
it("isMultiple prop", () => {
const wrapper = mount(veSelect, {
propsData: {
value: SELECT_ITEMS,
isMultiple: true,
},
});
expect(wrapper.findAll(".ve-dropdown-items-multiple").length).toBe(3);
});
it("isInput prop", () => {
const wrapper = mount(veSelect, {
propsData: {
value: SELECT_ITEMS,
isInput: true,
},
});
expect(wrapper.find(".ve-select-input").exists()).toBe(true);
});
it("on-select-change emit event", async () => {
const wrapper = mount(veSelect, {
propsData: {
value: SELECT_ITEMS,
},
});
wrapper.findAll(".ve-dropdown-items-li").at(1).trigger("click");
expect(wrapper.emitted("on-select-change").length).toEqual(1);
expect(
wrapper.emitted("on-select-change")[0][0].find((x) => x.selected)
.label,
).toBe("Orange");
});
});