-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathcustom-cell-style.test.ts
More file actions
127 lines (112 loc) · 3.77 KB
/
custom-cell-style.test.ts
File metadata and controls
127 lines (112 loc) · 3.77 KB
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
// @ts-nocheck
import { CustomCellStylePlugin } from '../../src/plugins/custom-cell-style';
function createMockTable(colCount = 5000, rowCount = 5000) {
return {
colCount,
rowCount,
getCellRange: (col: number, row: number) => ({
start: { col, row },
end: { col, row }
}),
getCellValue: jest.fn(),
getCellOriginValue: jest.fn(),
getCellHeaderPaths: jest.fn(),
scenegraph: {
updateCellContent: jest.fn(),
updateNextFrame: jest.fn()
}
};
}
describe('CustomCellStylePlugin', () => {
test('apply and clear single cell style without shrinking array', () => {
const table = createMockTable();
const plugin = new CustomCellStylePlugin(
table as any,
[
{
id: 's1',
style: { bgColor: 'red' }
}
] as any,
[] as any
);
plugin.arrangeCustomCellStyle({ col: 1, row: 2 }, 's1');
expect(plugin.getCustomCellStyleIds(1, 2)).toEqual(['s1']);
expect(plugin.getCustomCellStyle(1, 2)).toEqual({ bgColor: 'red' });
const beforeClearLength = plugin.customCellStyleArrangement.length;
plugin.arrangeCustomCellStyle({ col: 1, row: 2 }, null);
expect(plugin.getCustomCellStyleIds(1, 2)).toEqual([]);
expect(plugin.getCustomCellStyle(1, 2)).toBeUndefined();
expect(plugin.customCellStyleArrangement.length).toBe(beforeClearLength);
expect((plugin as any)._customCellStyleArrangementTombstoneCount).toBe(1);
});
test('does not delete wrong cell when index map is stale', () => {
const table = createMockTable();
const plugin = new CustomCellStylePlugin(
table as any,
[
{ id: 'a', style: { bgColor: 'red' } },
{ id: 'b', style: { bgColor: 'blue' } }
] as any,
[] as any
);
plugin.arrangeCustomCellStyle({ col: 1, row: 1 }, 'a');
plugin.arrangeCustomCellStyle({ col: 2, row: 2 }, 'b');
const arr = plugin.customCellStyleArrangement;
const tmp = arr[0];
arr[0] = arr[1];
arr[1] = tmp;
plugin.arrangeCustomCellStyle({ col: 1, row: 1 }, null);
expect(plugin.getCustomCellStyleIds(1, 1)).toEqual([]);
expect(plugin.getCustomCellStyleIds(2, 2)).toEqual(['b']);
});
test('compacts tombstones during massive clears and keeps index consistent', () => {
const table = createMockTable(10000, 2);
const plugin = new CustomCellStylePlugin(
table as any,
[
{
id: 's',
style: { bgColor: 'yellow' }
}
] as any,
[] as any
);
const total = 3000;
const removed = 2500;
for (let i = 0; i < total; i++) {
plugin.arrangeCustomCellStyle({ col: i, row: 0 }, 's');
}
for (let i = 0; i < removed; i++) {
plugin.arrangeCustomCellStyle({ col: i, row: 0 }, null);
}
expect((plugin as any)._customCellStyleArrangementTombstoneCount).toBeLessThan(2048);
expect((plugin as any)._customCellStyleArrangementIndex.size).toBe(total - removed);
for (let i = 0; i < removed; i++) {
expect(plugin.getCustomCellStyleIds(i, 0)).toEqual([]);
}
for (let i = removed; i < total; i++) {
expect(plugin.getCustomCellStyleIds(i, 0)).toEqual(['s']);
}
});
test('uses fast update when style only touches cellStyleKeys', () => {
const table = createMockTable();
const plugin = new CustomCellStylePlugin(
table as any,
[
{
id: 's',
style: { bgColor: 'red', color: '#000' }
}
] as any,
[] as any
);
plugin.arrangeCustomCellStyle({ col: 3, row: 4 }, 's');
const calls = (table as any).scenegraph.updateCellContent.mock.calls;
expect(calls.length).toBeGreaterThan(0);
const lastCall = calls[calls.length - 1];
expect(lastCall[0]).toBe(3);
expect(lastCall[1]).toBe(4);
expect(lastCall[2]).toBe(true);
});
});