Skip to content

Commit ef7e1a0

Browse files
committed
主干同步到分支
tag/v2.6.1
1 parent 43c3d30 commit ef7e1a0

File tree

3 files changed

+143
-3
lines changed

3 files changed

+143
-3
lines changed

packages/ve-table/src/index.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,15 @@ export default {
410410
},
411411
columns: {
412412
handler(newVal, oldVal) {
413-
if (newVal != oldVal) {
414-
this.columnsOptionResetTime++;
415-
}
416413
this.initColumns();
417414
this.initGroupColumns();
415+
416+
// 排除首次
417+
if (newVal != oldVal && oldVal) {
418+
this.columnsOptionResetTime++;
419+
// 需要等待 initColumns 和 initGroupColumns 先执行
420+
this.initScrolling();
421+
}
418422
},
419423
immediate: true,
420424
},
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
表格通用单元测试
3+
*/
4+
5+
import { mount } from "@vue/test-utils";
6+
import veTable from "@/ve-table";
7+
import {
8+
later,
9+
mockElementMeasurement,
10+
clearMockElementMeasurement,
11+
} from "../util";
12+
13+
describe("veTable common", () => {
14+
afterEach(() => {
15+
clearMockElementMeasurement("scrollWidth");
16+
clearMockElementMeasurement("clientWidth");
17+
});
18+
19+
it("horizontal scroll effect", async () => {
20+
mockElementMeasurement("scrollWidth", 1200);
21+
mockElementMeasurement("clientWidth", 900);
22+
23+
const COLUMNS = [
24+
{ field: "col1", key: "a", title: "Title1" },
25+
{ field: "col2", key: "b", title: "Title2" },
26+
{ field: "col3", key: "c", title: "Title3" },
27+
{ field: "col4", key: "d", title: "Title4" },
28+
{ field: "col5", key: "e", title: "Title5" },
29+
{ field: "col6", key: "f", title: "Title6" },
30+
{ field: "col7", key: "g", title: "Title7" },
31+
{ field: "col8", key: "h", title: "Title8" },
32+
{ field: "col9", key: "i", title: "Title9" },
33+
{ field: "col10", key: "j", title: "Title10" },
34+
];
35+
36+
const COLUMNS2 = [
37+
{ field: "col1", key: "a", title: "Title1", fixed: "left" },
38+
{ field: "col2", key: "b", title: "Title2", fixed: "left" },
39+
{ field: "col3", key: "c", title: "Title3" },
40+
{ field: "col4", key: "d", title: "Title4" },
41+
{ field: "col5", key: "e", title: "Title5" },
42+
{ field: "col6", key: "f", title: "Title6" },
43+
{ field: "col7", key: "g", title: "Title7" },
44+
{ field: "col8", key: "h", title: "Title8" },
45+
{ field: "col9", key: "i", title: "Title9" },
46+
{ field: "col10", key: "j", title: "Title10", fixed: "right" },
47+
];
48+
49+
const TABLE_DATA = [
50+
{
51+
col1: "1",
52+
col2: "2",
53+
col3: "3",
54+
col4: "4",
55+
col5: "5",
56+
col6: "6",
57+
col7: "7",
58+
col8: "8",
59+
col9: "9",
60+
col10: "10",
61+
},
62+
];
63+
64+
const ParentComp = {
65+
template: `
66+
<veTable
67+
style="width:900px"
68+
:scrollWidth="1200"
69+
:columns="columns"
70+
:tableData="tableData"
71+
/>
72+
`,
73+
props: {
74+
columns: {
75+
type: Array,
76+
required: true,
77+
},
78+
},
79+
data() {
80+
return {
81+
tableData: TABLE_DATA,
82+
};
83+
},
84+
components: {
85+
veTable,
86+
},
87+
};
88+
89+
await later();
90+
91+
const parentWrapper = mount(ParentComp, {
92+
propsData: {
93+
columns: COLUMNS,
94+
},
95+
});
96+
97+
const wrapper = parentWrapper.findComponent(veTable);
98+
99+
expect(wrapper.vm.isRightScrolling).toBe(false);
100+
101+
// 只能通过父组件设置
102+
await parentWrapper.setProps({ columns: COLUMNS2 });
103+
expect(wrapper.vm.isRightScrolling).toBe(true);
104+
});
105+
});

tests/unit/util.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,34 @@ export function mockScrollTo() {
2323
Element.prototype.scrollTo = fn;
2424
return fn;
2525
}
26+
27+
/*
28+
* @mockElementMeasurement
29+
* @desc mock element measurement
30+
*/
31+
export function mockElementMeasurement(key, value) {
32+
Object.defineProperty(HTMLElement.prototype, key, {
33+
configurable: true,
34+
value: value,
35+
});
36+
}
37+
38+
/*
39+
* @clearMockElementMeasurement
40+
* @desc clear mock element measurement
41+
*/
42+
export function clearMockElementMeasurement(key) {
43+
// const originalValue = Object.getOwnPropertyDescriptor(
44+
// HTMLElement.prototype,
45+
// key,
46+
// );
47+
48+
const originalValue = {
49+
value: 1200,
50+
writable: false,
51+
enumerable: false,
52+
configurable: true,
53+
};
54+
55+
Object.defineProperty(HTMLElement.prototype, key, originalValue);
56+
}

0 commit comments

Comments
 (0)