Skip to content

Commit 4a7fc42

Browse files
committed
add column hidden unit test
1 parent 3bc9ad3 commit 4a7fc42

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { mount } from "@vue/test-utils";
2+
import { later } from "../util";
3+
import veTable from "@/ve-table";
4+
5+
describe("veTable column hidden", () => {
6+
const TABLE_DATA = [
7+
{
8+
col1: "col1-1",
9+
col2: "col2-1",
10+
col3: "col3-1",
11+
col4: "col4-1",
12+
col5: "col5-1",
13+
col6: "col6-1",
14+
col7: "col7-1",
15+
col8: "col8-1",
16+
},
17+
];
18+
19+
const COLUMNS = [
20+
{ field: "col1", key: "col1", title: "col1", width: "10%" },
21+
{
22+
title: "col2-col3",
23+
children: [
24+
{
25+
field: "col2",
26+
key: "col2",
27+
title: "col2",
28+
width: 100,
29+
},
30+
{
31+
field: "col3",
32+
key: "col3",
33+
title: "col3",
34+
width: 110,
35+
},
36+
],
37+
},
38+
{
39+
title: "col4-col5-col6",
40+
children: [
41+
{
42+
title: "col4-col5",
43+
children: [
44+
{
45+
field: "col4",
46+
key: "col4",
47+
title: "col4",
48+
width: 130,
49+
},
50+
{
51+
field: "col5",
52+
key: "col5",
53+
title: "col5",
54+
width: 140,
55+
},
56+
],
57+
},
58+
{
59+
title: "col6",
60+
field: "col6",
61+
key: "col6",
62+
width: 140,
63+
},
64+
],
65+
},
66+
{ field: "col7", key: "col7", title: "col7", width: 150 },
67+
{ field: "col8", key: "col8", title: "col8", width: 160 },
68+
];
69+
70+
it("columnHiddenOption defaultHiddenColumnKeys prop", () => {
71+
const wrapper = mount(veTable, {
72+
propsData: {
73+
columns: COLUMNS,
74+
tableData: TABLE_DATA,
75+
columnHiddenOption: {
76+
// default hidden column keys
77+
defaultHiddenColumnKeys: ["col8"],
78+
},
79+
},
80+
});
81+
82+
expect(wrapper.vm.hiddenColumns).toEqual(["col8"]);
83+
84+
const firstHeaderTr = wrapper.findAll(
85+
".ve-table-header .ve-table-header-tr",
86+
);
87+
88+
const Ths = firstHeaderTr.at(0).findAll(".ve-table-header-th");
89+
90+
expect(Ths.at(Ths.length - 1).text()).toEqual("col7");
91+
});
92+
93+
it("instance method hideColumnsByKeys", async () => {
94+
const wrapper = mount(veTable, {
95+
propsData: {
96+
columns: COLUMNS,
97+
tableData: TABLE_DATA,
98+
columnHiddenOption: {
99+
// default hidden column keys
100+
defaultHiddenColumnKeys: ["col8"],
101+
},
102+
},
103+
});
104+
105+
wrapper.vm.hideColumnsByKeys(["col1", "col2"]);
106+
107+
expect(wrapper.vm.hiddenColumns).toEqual(["col8", "col1", "col2"]);
108+
});
109+
110+
it("instance method showColumnsByKeys", async () => {
111+
const wrapper = mount(veTable, {
112+
propsData: {
113+
columns: COLUMNS,
114+
tableData: TABLE_DATA,
115+
columnHiddenOption: {
116+
// default hidden column keys
117+
defaultHiddenColumnKeys: ["col8", "col1", "col2"],
118+
},
119+
},
120+
});
121+
122+
wrapper.vm.showColumnsByKeys(["col1", "col2"]);
123+
124+
expect(wrapper.vm.hiddenColumns).toEqual(["col8"]);
125+
});
126+
});

0 commit comments

Comments
 (0)