forked from Happy-Coding-Clans/vue-easytable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathve-table-cell-style.spec.js
132 lines (122 loc) · 3.48 KB
/
ve-table-cell-style.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { mount } from "@vue/test-utils";
import veTable from "@/ve-table";
import { later } from "../util";
describe("veTable cell style", () => {
const TABLE_DATA = [
{
name: "John",
date: "1900-05-20",
hobby: "coding",
address: "No.1 Century Avenue, Shanghai",
},
{
name: "Dickerson",
date: "1910-06-20",
hobby: "coding",
address: "No.1 Century Avenue, Beijing",
},
{
name: "Larsen",
date: "2000-07-20",
hobby: "coding and coding repeat",
address: "No.1 Century Avenue, Chongqing",
},
{
name: "Geneva",
date: "2010-08-20",
hobby: "coding and coding repeat",
address: "No.1 Century Avenue, Xiamen",
},
{
name: "Jami",
date: "2020-09-20",
hobby: "coding and coding repeat",
address: "No.1 Century Avenue, Shenzhen",
},
];
const FOOTER_DATA = [
{
rowkey: 0,
name: "平均值",
date: 213,
hobby: 355,
address: 189,
},
{
rowkey: 1,
name: "汇总值",
date: 1780,
hobby: 890,
address: 2988,
},
];
const COLUMNS = [
{
field: "name",
key: "a",
title: "Name",
align: "left",
},
{
field: "date",
key: "b",
title: "Date",
align: "left",
},
{
field: "hobby",
key: "c",
title: "Hobby",
align: "left",
},
{
field: "address",
key: "d",
title: "Address",
width: "",
align: "left",
},
];
const wrapper = mount(veTable, {
propsData: {
columns: COLUMNS,
tableData: TABLE_DATA,
footerData: FOOTER_DATA,
rowKeyFieldName: "rowkey",
cellStyleOption: {
headerCellClass: ({ column, rowIndex }) => {
if (column.field === "hobby") {
return "table-header-cell-class";
}
},
bodyCellClass: ({ row, column, rowIndex }) => {
if (column.field === "hobby") {
return "table-body-cell-class1";
}
if (column.field === "name" && rowIndex === 2) {
return "table-body-cell-class2";
}
},
footerCellClass: ({ row, column, rowIndex }) => {
if (column.field === "address") {
return "table-footer-cell-class1";
}
if (column.field === "date" && rowIndex === 1) {
return "table-footer-cell-class2";
}
},
},
},
});
it("render", () => {
expect(wrapper.html()).toMatchSnapshot();
});
it("cell style", () => {
// header
expect(wrapper.find(".table-header-cell-class").exists()).toBe(true);
// body
expect(wrapper.find(".table-body-cell-class2").exists()).toBe(true);
// footer
expect(wrapper.find(".table-footer-cell-class2").exists()).toBe(true);
});
});