forked from Happy-Coding-Clans/vue-easytable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathve-table-common.spec.js
105 lines (93 loc) · 3.16 KB
/
ve-table-common.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
102
103
104
105
/*
表格通用单元测试
*/
import { mount } from "@vue/test-utils";
import veTable from "@/ve-table";
import {
later,
mockElementMeasurement,
clearMockElementMeasurement,
} from "../util";
describe("veTable common", () => {
afterEach(() => {
clearMockElementMeasurement("scrollWidth");
clearMockElementMeasurement("clientWidth");
});
it("horizontal scroll effect", async () => {
mockElementMeasurement("scrollWidth", 1200);
mockElementMeasurement("clientWidth", 900);
const COLUMNS = [
{ field: "col1", key: "a", title: "Title1" },
{ field: "col2", key: "b", title: "Title2" },
{ field: "col3", key: "c", title: "Title3" },
{ field: "col4", key: "d", title: "Title4" },
{ field: "col5", key: "e", title: "Title5" },
{ field: "col6", key: "f", title: "Title6" },
{ field: "col7", key: "g", title: "Title7" },
{ field: "col8", key: "h", title: "Title8" },
{ field: "col9", key: "i", title: "Title9" },
{ field: "col10", key: "j", title: "Title10" },
];
const COLUMNS2 = [
{ field: "col1", key: "a", title: "Title1", fixed: "left" },
{ field: "col2", key: "b", title: "Title2", fixed: "left" },
{ field: "col3", key: "c", title: "Title3" },
{ field: "col4", key: "d", title: "Title4" },
{ field: "col5", key: "e", title: "Title5" },
{ field: "col6", key: "f", title: "Title6" },
{ field: "col7", key: "g", title: "Title7" },
{ field: "col8", key: "h", title: "Title8" },
{ field: "col9", key: "i", title: "Title9" },
{ field: "col10", key: "j", title: "Title10", fixed: "right" },
];
const TABLE_DATA = [
{
col1: "1",
col2: "2",
col3: "3",
col4: "4",
col5: "5",
col6: "6",
col7: "7",
col8: "8",
col9: "9",
col10: "10",
},
];
const ParentComp = {
template: `
<veTable
style="width:900px"
:scrollWidth="1200"
:columns="columns"
:tableData="tableData"
/>
`,
props: {
columns: {
type: Array,
required: true,
},
},
data() {
return {
tableData: TABLE_DATA,
};
},
components: {
veTable,
},
};
await later();
const parentWrapper = mount(ParentComp, {
propsData: {
columns: COLUMNS,
},
});
const wrapper = parentWrapper.findComponent(veTable);
expect(wrapper.vm.isRightScrolling).toBe(false);
// 只能通过父组件设置
await parentWrapper.setProps({ columns: COLUMNS2 });
expect(wrapper.vm.isRightScrolling).toBe(true);
});
});