Skip to content

Commit aaefbf1

Browse files
committed
test: fix
1 parent c38b6dd commit aaefbf1

File tree

2 files changed

+51
-33
lines changed

2 files changed

+51
-33
lines changed

packages/s2-core/__tests__/unit/utils/hide-columns-spec.ts

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getContainer } from 'tests/util/helpers';
12
import { RootInteraction } from '@/interaction/root';
23
import { Node } from '@/facet/layout/node';
34
import {
@@ -18,11 +19,11 @@ describe('hide-columns test', () => {
1819
let sheet: SpreadSheet;
1920
let mockSpreadSheetInstance: PivotSheet;
2021
const initColumnNodes: Partial<Node>[] = [
21-
{ field: '1', colIndex: 1 },
22-
{ field: '2', colIndex: 2 },
23-
{ field: '3', colIndex: 3 },
24-
{ field: '4', colIndex: 4 },
25-
{ field: '5', colIndex: 5 },
22+
{ field: '1', id: 'id-1', colIndex: 1 },
23+
{ field: '2', id: 'id-2', colIndex: 2 },
24+
{ field: '3', id: 'id-3', colIndex: 3 },
25+
{ field: '4', id: 'id-4', colIndex: 4 },
26+
{ field: '5', id: 'id-5', colIndex: 5 },
2627
];
2728
beforeEach(() => {
2829
sheet = {
@@ -31,7 +32,7 @@ describe('hide-columns test', () => {
3132
} as PivotSheet;
3233

3334
mockSpreadSheetInstance = new PivotSheet(
34-
document.createElement('div'),
35+
getContainer(),
3536
{
3637
fields: {
3738
rows: [],
@@ -59,9 +60,9 @@ describe('hide-columns test', () => {
5960

6061
test('should return hidden column list', () => {
6162
expect(getHiddenColumnNodes(sheet, ['1', '2', '3'])).toEqual([
62-
{ field: '1', colIndex: 1 },
63-
{ field: '2', colIndex: 2 },
64-
{ field: '3', colIndex: 3 },
63+
{ field: '1', id: 'id-1', colIndex: 1 },
64+
{ field: '2', id: 'id-2', colIndex: 2 },
65+
{ field: '3', id: 'id-3', colIndex: 3 },
6566
]);
6667
});
6768

@@ -70,10 +71,12 @@ describe('hide-columns test', () => {
7071
expect(getHiddenColumnDisplaySiblingNode(sheet, ['3'])).toEqual({
7172
prev: {
7273
field: '2',
74+
id: 'id-2',
7375
colIndex: 2,
7476
},
7577
next: {
7678
field: '4',
79+
id: 'id-4',
7780
colIndex: 4,
7881
},
7982
});
@@ -82,10 +85,12 @@ describe('hide-columns test', () => {
8285
expect(getHiddenColumnDisplaySiblingNode(sheet, ['3', '4'])).toEqual({
8386
prev: {
8487
field: '2',
88+
id: 'id-2',
8589
colIndex: 2,
8690
},
8791
next: {
8892
field: '5',
93+
id: 'id-5',
8994
colIndex: 5,
9095
},
9196
});
@@ -96,6 +101,7 @@ describe('hide-columns test', () => {
96101
expect(getHiddenColumnDisplaySiblingNode(sheet, ['5'])).toEqual({
97102
prev: {
98103
field: '4',
104+
id: 'id-4',
99105
colIndex: 4,
100106
},
101107
next: null,
@@ -105,6 +111,7 @@ describe('hide-columns test', () => {
105111
prev: null,
106112
next: {
107113
field: '2',
114+
id: 'id-2',
108115
colIndex: 2,
109116
},
110117
});
@@ -113,6 +120,7 @@ describe('hide-columns test', () => {
113120
expect(getHiddenColumnDisplaySiblingNode(sheet, ['3', '4', '5'])).toEqual({
114121
prev: {
115122
field: '2',
123+
id: 'id-2',
116124
colIndex: 2,
117125
},
118126
next: null,
@@ -168,10 +176,10 @@ describe('hide-columns test', () => {
168176
expect(mockSpreadSheetInstance.store.get('hiddenColumnsDetail')).toEqual([
169177
{
170178
displaySiblingNode: {
171-
prev: { field: '2', colIndex: 2 },
172-
next: { field: '4', colIndex: 4 },
179+
prev: { field: '2', id: 'id-2', colIndex: 2 },
180+
next: { field: '4', id: 'id-4', colIndex: 4 },
173181
},
174-
hideColumnNodes: [{ field: '3', colIndex: 3 }],
182+
hideColumnNodes: [{ field: '3', id: 'id-3', colIndex: 3 }],
175183
},
176184
]);
177185
// reset interaction
@@ -185,8 +193,11 @@ describe('hide-columns test', () => {
185193

186194
expect(mockSpreadSheetInstance.store.get('hiddenColumnsDetail')).toEqual([
187195
{
188-
displaySiblingNode: { next: null, prev: { field: '4', colIndex: 4 } },
189-
hideColumnNodes: [{ field: '5', colIndex: 5 }],
196+
displaySiblingNode: {
197+
next: null,
198+
prev: { field: '4', id: 'id-4', colIndex: 4 },
199+
},
200+
hideColumnNodes: [{ field: '5', id: 'id-5', colIndex: 5 }],
190201
},
191202
]);
192203
});
@@ -201,14 +212,20 @@ describe('hide-columns test', () => {
201212
expect(columnsHidden).toHaveBeenCalledWith(
202213
// current hidden column infos
203214
{
204-
displaySiblingNode: { next: null, prev: { colIndex: 4, field: '4' } },
205-
hideColumnNodes: [{ colIndex: 5, field: '5' }],
215+
displaySiblingNode: {
216+
next: null,
217+
prev: { colIndex: 4, id: 'id-4', field: '4' },
218+
},
219+
hideColumnNodes: [{ colIndex: 5, id: 'id-5', field: '5' }],
206220
},
207221
// hidden columns detail
208222
[
209223
{
210-
displaySiblingNode: { next: null, prev: { colIndex: 4, field: '4' } },
211-
hideColumnNodes: [{ colIndex: 5, field: '5' }],
224+
displaySiblingNode: {
225+
next: null,
226+
prev: { colIndex: 4, id: 'id-4', field: '4' },
227+
},
228+
hideColumnNodes: [{ colIndex: 5, id: 'id-5', field: '5' }],
212229
},
213230
],
214231
);
@@ -228,12 +245,12 @@ describe('hide-columns test', () => {
228245
expect(mockSpreadSheetInstance.store.get('hiddenColumnsDetail')).toEqual([
229246
{
230247
displaySiblingNode: {
231-
prev: { field: '1', colIndex: 1 },
232-
next: { field: '4', colIndex: 4 },
248+
prev: { field: '1', id: 'id-1', colIndex: 1 },
249+
next: { field: '4', id: 'id-4', colIndex: 4 },
233250
},
234251
hideColumnNodes: [
235-
{ field: '2', colIndex: 2 },
236-
{ field: '3', colIndex: 3 },
252+
{ field: '2', id: 'id-2', colIndex: 2 },
253+
{ field: '3', id: 'id-3', colIndex: 3 },
237254
],
238255
},
239256
]);
@@ -246,16 +263,16 @@ describe('hide-columns test', () => {
246263
{
247264
displaySiblingNode: {
248265
prev: null,
249-
next: { field: '2', colIndex: 2 },
266+
next: { field: '2', id: 'id-2', colIndex: 2 },
250267
},
251-
hideColumnNodes: [{ field: '1', colIndex: 1 }],
268+
hideColumnNodes: [{ field: '1', id: 'id-1', colIndex: 1 }],
252269
},
253270
{
254271
displaySiblingNode: {
255-
prev: { field: '2', colIndex: 2 },
256-
next: { field: '4', colIndex: 4 },
272+
prev: { field: '2', id: 'id-2', colIndex: 2 },
273+
next: { field: '4', id: 'id-4', colIndex: 4 },
257274
},
258-
hideColumnNodes: [{ field: '3', colIndex: 3 }],
275+
hideColumnNodes: [{ field: '3', id: 'id-3', colIndex: 3 }],
259276
},
260277
]);
261278
});
@@ -300,9 +317,9 @@ describe('hide-columns test', () => {
300317
expect(
301318
getValidDisplaySiblingNodeId({ next: null, prev: prevNode }),
302319
).toEqual(prevNode.id);
303-
expect(getValidDisplaySiblingNodeId({ next: null, prev: null })).toEqual(
304-
null,
305-
);
320+
expect(
321+
getValidDisplaySiblingNodeId({ next: null, prev: null }),
322+
).toBeUndefined();
306323
});
307324

308325
test('should get is equal display sibling node id', () => {

packages/s2-core/src/utils/hide-columns.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { compact, isEmpty, isEqual, last, uniq } from 'lodash';
1+
import { compact, get, isEmpty, isEqual, last, uniq } from 'lodash';
22
import { HiddenColumnsInfo } from '@/common/interface/store';
33
import { SpreadSheet } from '@/sheet-type';
44
import { ID_SEPARATOR, S2Event } from '@/common/constant';
@@ -169,10 +169,11 @@ export const isLastColumnAfterHidden = (
169169
) => {
170170
const columnNodes = spreadsheet.getColumnNodes();
171171
const initColumnNodes = spreadsheet.getInitColumnNodes();
172+
const fieldKey = getHiddenColumnFieldKey(columnField);
172173

173174
return (
174-
last(columnNodes).id === columnField &&
175-
last(initColumnNodes).id !== columnField
175+
get(last(columnNodes), fieldKey) === columnField &&
176+
get(last(initColumnNodes), fieldKey) !== columnField
176177
);
177178
};
178179

0 commit comments

Comments
 (0)