forked from Happy-Coding-Clans/vue-easytable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathve-table-row-radio.spec.js
218 lines (197 loc) · 5.69 KB
/
ve-table-row-radio.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import { mount } from "@vue/test-utils";
import veTable from "@/ve-table";
import { later } from "../util";
describe("veTable row radio", () => {
const TABLE_DATA = [
{
rowKey: 1001,
name: "John",
date: "1900-05-20",
hobby: "coding",
address: "No.1 Century Avenue, Shanghai",
},
{
rowKey: 1002,
name: "Dickerson",
date: "1910-06-20",
hobby: "coding",
address: "No.1 Century Avenue, Beijing",
},
{
rowKey: 1003,
name: "Larsen",
date: "2000-07-20",
hobby: "coding and coding repeat",
address: "No.1 Century Avenue, Chongqing",
},
{
rowKey: 1004,
name: "Geneva",
date: "2010-08-20",
hobby: "coding and coding repeat",
address: "No.1 Century Avenue, Xiamen",
},
{
rowKey: 1005,
name: "Jami",
date: "2020-09-20",
hobby: "coding and coding repeat",
address: "No.1 Century Avenue, Shenzhen",
},
];
const COLUMNS = [
{
field: "",
key: "a",
// type=radio
type: "radio",
title: "",
width: 50,
align: "center",
},
{
field: "name",
key: "b",
title: "Name",
width: 200,
align: "left",
},
{
field: "hobby",
key: "c",
title: "Hobby",
width: 300,
align: "left",
},
{
field: "address",
key: "d",
title: "Address",
width: "",
align: "left",
},
];
it("render", () => {
const wrapper = mount(veTable, {
propsData: {
columns: COLUMNS,
tableData: TABLE_DATA,
radioOption: {
// 行选择改变事件
selectedRowChange: ({ row }) => {},
},
rowKeyFieldName: "rowKey",
},
});
expect(wrapper.html()).toMatchSnapshot();
});
it("has radio", () => {
const wrapper = mount(veTable, {
propsData: {
columns: COLUMNS,
tableData: TABLE_DATA,
radioOption: {
// 行选择改变事件
selectedRowChange: ({ row }) => {},
},
rowKeyFieldName: "rowKey",
},
});
expect(wrapper.find(".ve-radio").exists()).toBe(true);
});
it("check default selected key", () => {
const wrapper = mount(veTable, {
propsData: {
columns: COLUMNS,
tableData: TABLE_DATA,
radioOption: {
defaultSelectedRowKey: 1003,
// 行选择改变事件
selectedRowChange: ({ row }) => {},
},
rowKeyFieldName: "rowKey",
},
});
expect(
wrapper
.findAll(".ve-table-body-tr")
.at(2)
.find(".ve-radio-checked")
.exists(),
).toBe(true);
});
it("check disable selected keys", () => {
const wrapper = mount(veTable, {
propsData: {
columns: COLUMNS,
tableData: TABLE_DATA,
radioOption: {
defaultSelectedRowKey: 1003,
disableSelectedRowKeys: [1003, 1005],
// 行选择改变事件
selectedRowChange: ({ row }) => {},
},
rowKeyFieldName: "rowKey",
},
});
expect(
wrapper
.findAll(".ve-table-body-tr")
.at(2)
.find(".ve-radio-checked.ve-radio-disabled")
.exists(),
).toBe(true);
expect(
wrapper
.findAll(".ve-table-body-tr")
.at(4)
.find(".ve-radio-disabled")
.exists(),
).toBe(true);
});
it("controllable attr selectedRowKey", async () => {
const wrapper = mount(veTable, {
propsData: {
columns: COLUMNS,
tableData: TABLE_DATA,
radioOption: {
selectedRowKey: "",
},
rowKeyFieldName: "rowKey",
},
});
expect(wrapper.find(".ve-radio-checked").exists()).toBe(false);
wrapper.setProps({
radioOption: {
selectedRowKey: 1003,
},
});
await later();
expect(wrapper.find(".ve-radio-checked").exists()).toBe(true);
});
it("radioOption selectedRowChange event", async () => {
const mockFn = jest.fn();
const wrapper = mount(veTable, {
propsData: {
columns: COLUMNS,
tableData: TABLE_DATA,
radioOption: {
selectedRowChange: ({ row }) => {
mockFn(row);
},
},
rowKeyFieldName: "rowKey",
},
});
wrapper
.findAll(".ve-table-body-tr")
.at(0)
.findAll(".ve-table-body-td")
.at(0)
.find(".ve-radio")
.trigger("click");
await later();
expect(mockFn).toHaveBeenCalled();
expect(mockFn).toHaveBeenCalledWith(TABLE_DATA[0]);
});
});