@svgrid/grid 2.2.27 → 2.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -199
- package/dist/FlexRender.svelte +96 -96
- package/dist/GridFooter.svelte +179 -179
- package/dist/GridMenus.svelte +782 -734
- package/dist/SvAutoComplete.svelte +165 -165
- package/dist/SvCalendar.svelte +503 -503
- package/dist/SvCarousel.svelte +141 -141
- package/dist/SvCheckBox.svelte +101 -101
- package/dist/SvColorInput.svelte +181 -181
- package/dist/SvComboBox.svelte +275 -275
- package/dist/SvContextMenu.svelte +116 -116
- package/dist/SvCountryInput.svelte +160 -160
- package/dist/SvDrawer.svelte +254 -250
- package/dist/SvDropDownList.svelte +374 -374
- package/dist/SvDurationInput.svelte +126 -126
- package/dist/SvField.svelte +293 -293
- package/dist/SvForm.svelte +437 -437
- package/dist/SvGrid.controller.svelte.d.ts +14 -1
- package/dist/SvGrid.controller.svelte.js +112 -28
- package/dist/SvGrid.css +2704 -2723
- package/dist/SvGrid.svelte +3361 -3333
- package/dist/SvGrid.types.d.ts +20 -5
- package/dist/SvGridChart.svelte +1724 -1724
- package/dist/SvGridChartPanel.svelte +485 -485
- package/dist/SvGridChartView.svelte +70 -70
- package/dist/SvGridDropdown.svelte +696 -696
- package/dist/SvGridSelect.svelte +259 -259
- package/dist/SvGroupCell.svelte +109 -109
- package/dist/SvListBox.svelte +326 -287
- package/dist/SvListBox.svelte.d.ts +10 -1
- package/dist/SvMaskedInput.svelte +122 -122
- package/dist/SvMenu.svelte +124 -124
- package/dist/SvMenuList.svelte +146 -146
- package/dist/SvMultiSelect.svelte +281 -281
- package/dist/SvNumberInput.svelte +168 -168
- package/dist/SvOtpInput.svelte +158 -158
- package/dist/SvPasswordInput.svelte +151 -151
- package/dist/SvPhoneInput.svelte +133 -131
- package/dist/SvPopover.svelte +197 -197
- package/dist/SvRadioGroup.svelte +107 -107
- package/dist/SvRowGroupPanel.svelte +170 -170
- package/dist/SvScrollArea.svelte +61 -61
- package/dist/SvSlider.svelte +200 -200
- package/dist/SvSwitchButton.svelte +107 -107
- package/dist/SvTagsInput.svelte +112 -112
- package/dist/SvTextInput.svelte +147 -147
- package/dist/SvTimePicker.svelte +245 -245
- package/dist/SvToaster.svelte +159 -159
- package/dist/SvToggleButton.svelte +85 -85
- package/dist/SvTooltip.svelte +161 -161
- package/dist/SvTour.svelte +204 -204
- package/dist/SvTree.svelte +437 -437
- package/dist/SvTreeSelect.svelte +233 -233
- package/dist/cdn/GridMenus-Da_p7SKS.js +486 -0
- package/dist/cdn/GridMenus-Ds3OpzZT.js +490 -0
- package/dist/cdn/{SvDateTimePicker-B1sDc9Pz.js → SvDateTimePicker-B8GopjhC.js} +2 -2
- package/dist/cdn/{SvDateTimePicker-Bh0FTs1E.js → SvDateTimePicker-DB0aIEk8.js} +2 -2
- package/dist/cdn/{SvGridChart-Bgk4hDs8.js → SvGridChart-BcLCYvw9.js} +1 -1
- package/dist/cdn/{SvGridChart-BKQsO5fZ.js → SvGridChart-BhnFdLd0.js} +1 -1
- package/dist/cdn/{SvGridChartPanel-DkCc2Z7b.js → SvGridChartPanel-Cmx9DHAS.js} +1 -1
- package/dist/cdn/{SvGridChartPanel-DSkHIQDd.js → SvGridChartPanel-DvjwxLvK.js} +1 -1
- package/dist/cdn/{SvGridChartView-BrbVaELm.js → SvGridChartView-B40DTJSX.js} +1 -1
- package/dist/cdn/{SvGridChartView-i9rWvSKg.js → SvGridChartView-PwqI4s02.js} +1 -1
- package/dist/cdn/{SvGridDropdown-D08sVmAy.js → SvGridDropdown-DjALc_4f.js} +1 -1
- package/dist/cdn/{SvGridDropdown-CGxxopQ4.js → SvGridDropdown-hpnHvOGt.js} +1 -1
- package/dist/cdn/{src-cgs1wcUS.js → src-BLJfdyL0.js} +4034 -3889
- package/dist/cdn/{src-Cw8d9U8j.js → src-DYDCiC0D.js} +7053 -6908
- package/dist/cdn/svgrid.js +9 -9
- package/dist/cdn/svgrid.svelte-external.js +9 -9
- package/dist/chart-export.js +8 -8
- package/dist/column-groups.js +8 -10
- package/dist/column-id.d.ts +9 -0
- package/dist/column-id.js +25 -0
- package/dist/core.js +2 -1
- package/dist/createListbox.svelte.d.ts +15 -2
- package/dist/createListbox.svelte.js +27 -6
- package/dist/editing.d.ts +1 -0
- package/dist/editing.js +45 -10
- package/dist/filtering/excel-filters.d.ts +30 -10
- package/dist/filtering/excel-filters.js +96 -15
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/menus.d.ts +2 -0
- package/dist/menus.js +25 -0
- package/dist/row-resize.js +40 -0
- package/dist/selection.js +1 -1
- package/package.json +10 -10
- package/src/FlexRender.svelte +96 -96
- package/src/GridFooter.svelte +179 -179
- package/src/GridMenus.svelte +782 -734
- package/src/SvAutoComplete.svelte +165 -165
- package/src/SvCalendar.svelte +503 -503
- package/src/SvCalendar.test.ts +226 -226
- package/src/SvCarousel.svelte +141 -141
- package/src/SvCheckBox.svelte +101 -101
- package/src/SvColorInput.svelte +181 -181
- package/src/SvComboBox.svelte +275 -275
- package/src/SvContextMenu.svelte +116 -116
- package/src/SvCountryInput.svelte +160 -160
- package/src/SvDrawer.svelte +254 -250
- package/src/SvDrawer.test.ts +18 -1
- package/src/SvDropDownList.svelte +374 -374
- package/src/SvDurationInput.svelte +126 -126
- package/src/SvField.svelte +293 -293
- package/src/SvForm.svelte +437 -437
- package/src/SvForm.test.ts +411 -411
- package/src/SvGrid.controller.svelte.ts +3335 -3239
- package/src/SvGrid.css +2704 -2723
- package/src/SvGrid.svelte +3361 -3333
- package/src/SvGrid.types.ts +1628 -1613
- package/src/SvGridChart.svelte +1724 -1724
- package/src/SvGridChartPanel.svelte +485 -485
- package/src/SvGridChartView.svelte +70 -70
- package/src/SvGridDropdown.svelte +696 -696
- package/src/SvGridSelect.svelte +259 -259
- package/src/SvGroupCell.svelte +109 -109
- package/src/SvListBox.svelte +326 -287
- package/src/SvMaskedInput.svelte +122 -122
- package/src/SvMenu.svelte +124 -124
- package/src/SvMenu.test.ts +97 -97
- package/src/SvMenuList.svelte +146 -146
- package/src/SvMultiSelect.svelte +281 -281
- package/src/SvNavPane.test.ts +15 -4
- package/src/SvNumberInput.svelte +168 -168
- package/src/SvOtpInput.svelte +158 -158
- package/src/SvPasswordInput.svelte +151 -151
- package/src/SvPhoneInput.svelte +133 -131
- package/src/SvPopover.svelte +197 -197
- package/src/SvRadioGroup.svelte +107 -107
- package/src/SvRowGroupPanel.svelte +170 -170
- package/src/SvScrollArea.svelte +61 -61
- package/src/SvSlider.svelte +200 -200
- package/src/SvSwitchButton.svelte +107 -107
- package/src/SvTagsInput.svelte +112 -112
- package/src/SvTextInput.svelte +147 -147
- package/src/SvTimePicker.svelte +245 -245
- package/src/SvToaster.svelte +159 -159
- package/src/SvToaster.test.ts +95 -95
- package/src/SvToggleButton.svelte +85 -85
- package/src/SvTooltip.svelte +161 -161
- package/src/SvTour.svelte +204 -204
- package/src/SvTree.svelte +437 -437
- package/src/SvTreeSelect.svelte +233 -233
- package/src/a11y/dismissable.test.ts +119 -119
- package/src/a11y/dismissable.ts +114 -114
- package/src/a11y.contract.test.ts +49 -49
- package/src/a11y.test.ts +59 -59
- package/src/a11y.ts +61 -61
- package/src/ai.test.ts +502 -502
- package/src/ai.ts +1391 -1391
- package/src/build-api.coverage.test.ts +633 -633
- package/src/build-api.ts +895 -895
- package/src/builtin-editors.grid.test.ts +85 -85
- package/src/cell-formatting.ts +169 -169
- package/src/cell-render.ts +469 -469
- package/src/chart-export.ts +201 -201
- package/src/chart-view.svelte.ts +36 -36
- package/src/chart.ts +2296 -2296
- package/src/collaboration.test.ts +104 -104
- package/src/collaboration.ts +167 -167
- package/src/column-groups.test.ts +48 -0
- package/src/column-groups.ts +8 -10
- package/src/column-id.ts +30 -0
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1112 -1111
- package/src/createAutocomplete.svelte.ts +132 -132
- package/src/createCombobox.svelte.ts +191 -191
- package/src/createCountryInput.svelte.ts +157 -157
- package/src/createDropdownList.svelte.ts +168 -168
- package/src/createForm.svelte.ts +386 -386
- package/src/createGrid.svelte.ts +42 -42
- package/src/createGrid.test.ts +10 -10
- package/src/createGridState.svelte.ts +17 -17
- package/src/createListbox.svelte.ts +39 -7
- package/src/createMenu.svelte.ts +225 -225
- package/src/createPopoverSelect.svelte.ts +213 -213
- package/src/createSlider.svelte.ts +191 -191
- package/src/createTooltip.svelte.ts +144 -144
- package/src/createTree.svelte.ts +319 -319
- package/src/editing.test.ts +949 -859
- package/src/editing.ts +709 -675
- package/src/editor-contract.ts +157 -157
- package/src/export-data-api.test.ts +126 -126
- package/src/export-format.test.ts +107 -107
- package/src/export-format.ts +598 -598
- package/src/filter-operators.ts +157 -157
- package/src/filtering/excel-filters.test.ts +44 -1
- package/src/filtering/excel-filters.ts +91 -14
- package/src/flex-render.ts +3 -3
- package/src/form-field.ts +127 -127
- package/src/index.ts +715 -713
- package/src/js-scroller.svelte.ts +173 -173
- package/src/keyboard.test.ts +59 -59
- package/src/keyboard.ts +97 -97
- package/src/list-nav.test.ts +49 -49
- package/src/list-nav.ts +29 -29
- package/src/list-option.test.ts +56 -56
- package/src/list-option.ts +172 -172
- package/src/menus.test.ts +736 -700
- package/src/menus.ts +679 -652
- package/src/merge-objects.ts +48 -48
- package/src/overlays.test.ts +90 -90
- package/src/render-component.ts +28 -28
- package/src/row-resize.test.ts +100 -0
- package/src/row-resize.ts +36 -0
- package/src/scheduler-model.test.ts +562 -562
- package/src/scheduler-model.ts +872 -872
- package/src/selection.test.ts +754 -754
- package/src/selection.ts +600 -600
- package/src/server-data-source.test.ts +289 -289
- package/src/server-data-source.ts +413 -413
- package/src/sparkline.test.ts +68 -68
- package/src/sparkline.ts +169 -169
- package/src/spreadsheet.test.ts +489 -489
- package/src/spreadsheet.ts +312 -312
- package/src/static-functions.ts +11 -11
- package/src/subscribe.ts +38 -38
- package/src/svgrid-wrapper.types.ts +524 -524
- package/src/svgrid.api-extensions.test.ts +8 -3
- package/src/svgrid.behavior.test.ts +706 -706
- package/src/svgrid.cell-dom-ids.test.ts +96 -0
- package/src/svgrid.charting.test.ts +534 -534
- package/src/svgrid.conditional-stat-scope.test.ts +111 -0
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.filter-menu-listbox.svelte.test.ts +308 -0
- package/src/svgrid.filter-menu-scroll.test.ts +3 -1
- package/src/svgrid.group-header-ids.test.ts +121 -0
- package/src/svgrid.new-features.wrapper.test.ts +251 -251
- package/src/svgrid.wrapper.test.ts +40 -40
- package/src/test-setup.ts +62 -62
- package/src/themes/index.ts +215 -215
- package/src/toast-store.svelte.ts +246 -246
- package/src/toast-store.test.ts +147 -147
- package/src/ui-buttons.test.ts +144 -144
- package/src/ui-inputs.test.ts +118 -118
- package/src/ui-range.test.ts +70 -70
- package/src/ui-selection.test.ts +155 -155
- package/src/ui-tier1.test.ts +142 -142
- package/src/virtual.test.ts +88 -88
- package/src/virtualization/column-virtualizer.test.ts +27 -27
- package/src/virtualization/column-virtualizer.ts +30 -30
- package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
- package/src/virtualization/types.ts +30 -30
- package/src/virtualization/virtualizer.test.ts +47 -47
- package/src/virtualization/virtualizer.ts +296 -296
- package/themes/ember.css +71 -71
- package/dist/cdn/GridMenus-BzxEYNtW.js +0 -421
- package/dist/cdn/GridMenus-Dr-nGEXn.js +0 -417
package/src/menus.test.ts
CHANGED
|
@@ -1,700 +1,736 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import { createMenus } from './menus'
|
|
3
|
-
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// Fake controller (`ctx`) for the menus factory. The factory reads/writes
|
|
6
|
-
// plain menu/filter/pagination state and calls a few `ctx.grid.*` methods and
|
|
7
|
-
// clipboard/data helpers. We build the minimal surface each path touches.
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
function makeCtx(overrides: any = {}) {
|
|
11
|
-
let gridState: any = {
|
|
12
|
-
grouping: overrides.grouping ?? [],
|
|
13
|
-
...overrides.gridState,
|
|
14
|
-
}
|
|
15
|
-
const ctx: any = {
|
|
16
|
-
filterRowValues: {},
|
|
17
|
-
filterMenuValues: {},
|
|
18
|
-
valueFilters: {},
|
|
19
|
-
columnMenuFor: null,
|
|
20
|
-
filterMenuFor: null,
|
|
21
|
-
operatorMenuFor: null,
|
|
22
|
-
chooseColumnsPos: null,
|
|
23
|
-
columnMenuPos: null,
|
|
24
|
-
filterMenuPos: null,
|
|
25
|
-
operatorMenuPos: null,
|
|
26
|
-
columnMenuSearch: '',
|
|
27
|
-
contextMenuFor: null,
|
|
28
|
-
contextMenuPos: { x: 0, y: 0 },
|
|
29
|
-
commentEditFor: null,
|
|
30
|
-
commentDraft: '',
|
|
31
|
-
noteOverrides: {},
|
|
32
|
-
columnMenuFacetValues: [],
|
|
33
|
-
showColumnFiltersEffective: true,
|
|
34
|
-
showFilterRowEffective: false,
|
|
35
|
-
scrollContainer: null,
|
|
36
|
-
internalData: [],
|
|
37
|
-
internalColumns: [],
|
|
38
|
-
props: {},
|
|
39
|
-
copySelectionToClipboard: vi.fn(),
|
|
40
|
-
cutSelectionToClipboard: vi.fn(),
|
|
41
|
-
pasteFromClipboard: vi.fn(),
|
|
42
|
-
clearSelectedCells: vi.fn(),
|
|
43
|
-
allRows: [],
|
|
44
|
-
grid: {
|
|
45
|
-
getState: () => gridState,
|
|
46
|
-
setGrouping: vi.fn((g: any) => {
|
|
47
|
-
gridState = { ...gridState, grouping: g }
|
|
48
|
-
}),
|
|
49
|
-
setPagination: vi.fn(),
|
|
50
|
-
store: {
|
|
51
|
-
setState: vi.fn((updater: any) => {
|
|
52
|
-
gridState =
|
|
53
|
-
typeof updater === 'function' ? updater(gridState) : { ...gridState, ...updater }
|
|
54
|
-
}),
|
|
55
|
-
},
|
|
56
|
-
_peek: () => gridState,
|
|
57
|
-
},
|
|
58
|
-
...overrides,
|
|
59
|
-
}
|
|
60
|
-
return ctx
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
describe('createMenus - filter row/menu value updates', () => {
|
|
64
|
-
it('updateFilterRow seeds both filterRowValues and filterMenuValues', () => {
|
|
65
|
-
const ctx = makeCtx()
|
|
66
|
-
const m = createMenus(ctx)
|
|
67
|
-
m.updateFilterRow('name', 'abc')
|
|
68
|
-
expect(ctx.filterRowValues.name).toBe('abc')
|
|
69
|
-
expect(ctx.filterMenuValues.name).toEqual({ operator: 'contains', value: 'abc' })
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('updateFilterRow preserves an existing operator', () => {
|
|
73
|
-
const ctx = makeCtx({ filterMenuValues: { name: { operator: 'equals', value: '' } } })
|
|
74
|
-
const m = createMenus(ctx)
|
|
75
|
-
m.updateFilterRow('name', 'x')
|
|
76
|
-
expect(ctx.filterMenuValues.name).toEqual({ operator: 'equals', value: 'x' })
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('updateFilterOperator changes operator, defaulting value', () => {
|
|
80
|
-
const ctx = makeCtx()
|
|
81
|
-
const m = createMenus(ctx)
|
|
82
|
-
m.updateFilterOperator('age', 'greaterThan' as any)
|
|
83
|
-
expect(ctx.filterMenuValues.age).toEqual({ operator: 'greaterThan', value: '' })
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('updateFilterOperator keeps an existing value', () => {
|
|
87
|
-
const ctx = makeCtx({ filterMenuValues: { age: { operator: 'contains', value: '5' } } })
|
|
88
|
-
const m = createMenus(ctx)
|
|
89
|
-
m.updateFilterOperator('age', 'lessThan' as any)
|
|
90
|
-
expect(ctx.filterMenuValues.age).toEqual({ operator: 'lessThan', value: '5' })
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('updateFilterMenuValue mirrors value into the filter row', () => {
|
|
94
|
-
const ctx = makeCtx()
|
|
95
|
-
const m = createMenus(ctx)
|
|
96
|
-
m.updateFilterMenuValue('name', 'foo')
|
|
97
|
-
expect(ctx.filterMenuValues.name).toEqual({ operator: 'contains', value: 'foo' })
|
|
98
|
-
expect(ctx.filterRowValues.name).toBe('foo')
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('addFilterToken builds a
|
|
102
|
-
const ctx = makeCtx()
|
|
103
|
-
const m = createMenus(ctx)
|
|
104
|
-
m.addFilterToken('symbol', 'TSM')
|
|
105
|
-
m.addFilterToken('symbol', 'BP')
|
|
106
|
-
m.addFilterToken('symbol', 'TSM') // dupe - ignored
|
|
107
|
-
m.addFilterToken('symbol', ' ') // blank - ignored
|
|
108
|
-
expect(ctx.filterRowValues.symbol).toBe('TSM
|
|
109
|
-
// mirrored into the menu model too, so both filter surfaces agree
|
|
110
|
-
expect(ctx.filterMenuValues.symbol.value).toBe('TSM
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('removeFilterToken drops a value from the list', () => {
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
m
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
m
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
m.
|
|
136
|
-
expect(ctx.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
m.
|
|
146
|
-
expect(ctx.inSuggestFor).toBe(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
it('toggles on
|
|
176
|
-
const ctx = makeCtx()
|
|
177
|
-
const m = createMenus(ctx)
|
|
178
|
-
const toggle = vi.fn()
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
m
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
it('
|
|
194
|
-
const ctx = makeCtx(
|
|
195
|
-
const m = createMenus(ctx)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
expect(ctx.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const m = createMenus(ctx)
|
|
287
|
-
m.
|
|
288
|
-
expect(
|
|
289
|
-
|
|
290
|
-
expect(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
m.
|
|
300
|
-
expect(ctx.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
m.
|
|
310
|
-
expect(ctx.
|
|
311
|
-
expect(ctx.
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
m
|
|
357
|
-
expect(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
})
|
|
365
|
-
const m = createMenus(ctx)
|
|
366
|
-
m.toggleFacetValue('team', '
|
|
367
|
-
expect(ctx.valueFilters.team).
|
|
368
|
-
})
|
|
369
|
-
|
|
370
|
-
it('
|
|
371
|
-
const ctx = makeCtx({
|
|
372
|
-
columnMenuFacetValues: ['A', 'B'],
|
|
373
|
-
valueFilters: { team: new Set(['A']) },
|
|
374
|
-
})
|
|
375
|
-
const m = createMenus(ctx)
|
|
376
|
-
|
|
377
|
-
expect(
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
it('
|
|
381
|
-
const ctx = makeCtx({ columnMenuFacetValues: ['A', 'B'] })
|
|
382
|
-
const m = createMenus(ctx)
|
|
383
|
-
m.
|
|
384
|
-
expect(ctx.valueFilters.team.
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
it('
|
|
388
|
-
const ctx = makeCtx({
|
|
389
|
-
columnMenuFacetValues: ['A', 'B'],
|
|
390
|
-
valueFilters: { team: new Set(['A']) },
|
|
391
|
-
})
|
|
392
|
-
const m = createMenus(ctx)
|
|
393
|
-
m.
|
|
394
|
-
expect(ctx.valueFilters.team).toBeUndefined()
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
expect(
|
|
452
|
-
})
|
|
453
|
-
})
|
|
454
|
-
|
|
455
|
-
describe('createMenus -
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
const
|
|
476
|
-
m.
|
|
477
|
-
|
|
478
|
-
expect(
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
it('
|
|
497
|
-
const ctx = makeCtx({
|
|
498
|
-
const m = createMenus(ctx)
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
it('
|
|
506
|
-
const ctx = makeCtx({
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
expect(
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const ctx = makeCtx({
|
|
549
|
-
props: { contextMenu:
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
expect(
|
|
557
|
-
expect(
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
expect(ctx.
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
expect(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
const m = createMenus(ctx)
|
|
641
|
-
m.
|
|
642
|
-
expect(
|
|
643
|
-
})
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
expect(ctx.
|
|
690
|
-
})
|
|
691
|
-
|
|
692
|
-
it('
|
|
693
|
-
const ctx = makeCtx({
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { createMenus } from './menus'
|
|
3
|
+
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Fake controller (`ctx`) for the menus factory. The factory reads/writes
|
|
6
|
+
// plain menu/filter/pagination state and calls a few `ctx.grid.*` methods and
|
|
7
|
+
// clipboard/data helpers. We build the minimal surface each path touches.
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
function makeCtx(overrides: any = {}) {
|
|
11
|
+
let gridState: any = {
|
|
12
|
+
grouping: overrides.grouping ?? [],
|
|
13
|
+
...overrides.gridState,
|
|
14
|
+
}
|
|
15
|
+
const ctx: any = {
|
|
16
|
+
filterRowValues: {},
|
|
17
|
+
filterMenuValues: {},
|
|
18
|
+
valueFilters: {},
|
|
19
|
+
columnMenuFor: null,
|
|
20
|
+
filterMenuFor: null,
|
|
21
|
+
operatorMenuFor: null,
|
|
22
|
+
chooseColumnsPos: null,
|
|
23
|
+
columnMenuPos: null,
|
|
24
|
+
filterMenuPos: null,
|
|
25
|
+
operatorMenuPos: null,
|
|
26
|
+
columnMenuSearch: '',
|
|
27
|
+
contextMenuFor: null,
|
|
28
|
+
contextMenuPos: { x: 0, y: 0 },
|
|
29
|
+
commentEditFor: null,
|
|
30
|
+
commentDraft: '',
|
|
31
|
+
noteOverrides: {},
|
|
32
|
+
columnMenuFacetValues: [],
|
|
33
|
+
showColumnFiltersEffective: true,
|
|
34
|
+
showFilterRowEffective: false,
|
|
35
|
+
scrollContainer: null,
|
|
36
|
+
internalData: [],
|
|
37
|
+
internalColumns: [],
|
|
38
|
+
props: {},
|
|
39
|
+
copySelectionToClipboard: vi.fn(),
|
|
40
|
+
cutSelectionToClipboard: vi.fn(),
|
|
41
|
+
pasteFromClipboard: vi.fn(),
|
|
42
|
+
clearSelectedCells: vi.fn(),
|
|
43
|
+
allRows: [],
|
|
44
|
+
grid: {
|
|
45
|
+
getState: () => gridState,
|
|
46
|
+
setGrouping: vi.fn((g: any) => {
|
|
47
|
+
gridState = { ...gridState, grouping: g }
|
|
48
|
+
}),
|
|
49
|
+
setPagination: vi.fn(),
|
|
50
|
+
store: {
|
|
51
|
+
setState: vi.fn((updater: any) => {
|
|
52
|
+
gridState =
|
|
53
|
+
typeof updater === 'function' ? updater(gridState) : { ...gridState, ...updater }
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
_peek: () => gridState,
|
|
57
|
+
},
|
|
58
|
+
...overrides,
|
|
59
|
+
}
|
|
60
|
+
return ctx
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('createMenus - filter row/menu value updates', () => {
|
|
64
|
+
it('updateFilterRow seeds both filterRowValues and filterMenuValues', () => {
|
|
65
|
+
const ctx = makeCtx()
|
|
66
|
+
const m = createMenus(ctx)
|
|
67
|
+
m.updateFilterRow('name', 'abc')
|
|
68
|
+
expect(ctx.filterRowValues.name).toBe('abc')
|
|
69
|
+
expect(ctx.filterMenuValues.name).toEqual({ operator: 'contains', value: 'abc' })
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('updateFilterRow preserves an existing operator', () => {
|
|
73
|
+
const ctx = makeCtx({ filterMenuValues: { name: { operator: 'equals', value: '' } } })
|
|
74
|
+
const m = createMenus(ctx)
|
|
75
|
+
m.updateFilterRow('name', 'x')
|
|
76
|
+
expect(ctx.filterMenuValues.name).toEqual({ operator: 'equals', value: 'x' })
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('updateFilterOperator changes operator, defaulting value', () => {
|
|
80
|
+
const ctx = makeCtx()
|
|
81
|
+
const m = createMenus(ctx)
|
|
82
|
+
m.updateFilterOperator('age', 'greaterThan' as any)
|
|
83
|
+
expect(ctx.filterMenuValues.age).toEqual({ operator: 'greaterThan', value: '' })
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('updateFilterOperator keeps an existing value', () => {
|
|
87
|
+
const ctx = makeCtx({ filterMenuValues: { age: { operator: 'contains', value: '5' } } })
|
|
88
|
+
const m = createMenus(ctx)
|
|
89
|
+
m.updateFilterOperator('age', 'lessThan' as any)
|
|
90
|
+
expect(ctx.filterMenuValues.age).toEqual({ operator: 'lessThan', value: '5' })
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('updateFilterMenuValue mirrors value into the filter row', () => {
|
|
94
|
+
const ctx = makeCtx()
|
|
95
|
+
const m = createMenus(ctx)
|
|
96
|
+
m.updateFilterMenuValue('name', 'foo')
|
|
97
|
+
expect(ctx.filterMenuValues.name).toEqual({ operator: 'contains', value: 'foo' })
|
|
98
|
+
expect(ctx.filterRowValues.name).toBe('foo')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('addFilterToken builds a comma-serialised in/notIn list, ignoring dupes/blanks', () => {
|
|
102
|
+
const ctx = makeCtx()
|
|
103
|
+
const m = createMenus(ctx)
|
|
104
|
+
m.addFilterToken('symbol', 'TSM')
|
|
105
|
+
m.addFilterToken('symbol', 'BP')
|
|
106
|
+
m.addFilterToken('symbol', 'TSM') // dupe - ignored
|
|
107
|
+
m.addFilterToken('symbol', ' ') // blank - ignored
|
|
108
|
+
expect(ctx.filterRowValues.symbol).toBe('TSM, BP')
|
|
109
|
+
// mirrored into the menu model too, so both filter surfaces agree
|
|
110
|
+
expect(ctx.filterMenuValues.symbol.value).toBe('TSM, BP')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('removeFilterToken drops a value from the list', () => {
|
|
114
|
+
// Newline-separated input still parses (values serialised by older builds).
|
|
115
|
+
const ctx = makeCtx({ filterRowValues: { symbol: 'TSM\nBP\nBABA' } })
|
|
116
|
+
const m = createMenus(ctx)
|
|
117
|
+
m.removeFilterToken('symbol', 'BP')
|
|
118
|
+
expect(ctx.filterRowValues.symbol).toBe('TSM, BABA')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('toggleFilterToken adds when absent and removes when present', () => {
|
|
122
|
+
const ctx = makeCtx()
|
|
123
|
+
const m = createMenus(ctx)
|
|
124
|
+
m.toggleFilterToken('symbol', 'BP')
|
|
125
|
+
expect(ctx.filterRowValues.symbol).toBe('BP')
|
|
126
|
+
m.toggleFilterToken('symbol', 'BP')
|
|
127
|
+
expect(ctx.filterRowValues.symbol).toBe('')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('setFilterTokens replaces the whole list, dropping blanks', () => {
|
|
131
|
+
const ctx = makeCtx()
|
|
132
|
+
const m = createMenus(ctx)
|
|
133
|
+
m.setFilterTokens('symbol', ['BP', ' ', ' TSM '])
|
|
134
|
+
expect(ctx.filterRowValues.symbol).toBe('BP, TSM')
|
|
135
|
+
m.setFilterTokens('symbol', new Set<string>())
|
|
136
|
+
expect(ctx.filterRowValues.symbol).toBe('')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('openInSuggest anchors the dropdown and targets the column; closeInSuggest clears it', () => {
|
|
140
|
+
const ctx = makeCtx()
|
|
141
|
+
const m = createMenus(ctx)
|
|
142
|
+
const anchor = {
|
|
143
|
+
getBoundingClientRect: () => ({ left: 40, bottom: 80 }),
|
|
144
|
+
} as unknown as HTMLElement
|
|
145
|
+
m.openInSuggest(anchor, 'symbol')
|
|
146
|
+
expect(ctx.inSuggestFor).toBe('symbol')
|
|
147
|
+
expect(ctx.inSuggestPos).toMatchObject({ y: 84 })
|
|
148
|
+
m.closeInSuggest()
|
|
149
|
+
expect(ctx.inSuggestFor).toBe(null)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('closeMenus also dismisses the in-suggest dropdown', () => {
|
|
153
|
+
const ctx = makeCtx({ inSuggestFor: 'symbol' })
|
|
154
|
+
const m = createMenus(ctx)
|
|
155
|
+
m.closeMenus()
|
|
156
|
+
expect(ctx.inSuggestFor).toBe(null)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('updateFilterMenuValueTo sets the upper bound for between', () => {
|
|
160
|
+
const ctx = makeCtx({ filterMenuValues: { age: { operator: 'between', value: '5' } } })
|
|
161
|
+
const m = createMenus(ctx)
|
|
162
|
+
m.updateFilterMenuValueTo('age', '10')
|
|
163
|
+
expect(ctx.filterMenuValues.age).toEqual({ operator: 'between', value: '5', valueTo: '10' })
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('updateFilterMenuValueTo defaults a missing entry to between', () => {
|
|
167
|
+
const ctx = makeCtx()
|
|
168
|
+
const m = createMenus(ctx)
|
|
169
|
+
m.updateFilterMenuValueTo('age', '10')
|
|
170
|
+
expect(ctx.filterMenuValues.age).toEqual({ operator: 'between', value: '', valueTo: '10' })
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('createMenus - toggleCheckboxWithKeyboard', () => {
|
|
175
|
+
it('toggles on Enter and prevents default', () => {
|
|
176
|
+
const ctx = makeCtx()
|
|
177
|
+
const m = createMenus(ctx)
|
|
178
|
+
const toggle = vi.fn()
|
|
179
|
+
const ev = { key: 'Enter', preventDefault: vi.fn() } as any
|
|
180
|
+
m.toggleCheckboxWithKeyboard(ev, toggle)
|
|
181
|
+
expect(toggle).toHaveBeenCalled()
|
|
182
|
+
expect(ev.preventDefault).toHaveBeenCalled()
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('toggles on Space', () => {
|
|
186
|
+
const ctx = makeCtx()
|
|
187
|
+
const m = createMenus(ctx)
|
|
188
|
+
const toggle = vi.fn()
|
|
189
|
+
m.toggleCheckboxWithKeyboard({ key: ' ', preventDefault: vi.fn() } as any, toggle)
|
|
190
|
+
expect(toggle).toHaveBeenCalled()
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('ignores other keys', () => {
|
|
194
|
+
const ctx = makeCtx()
|
|
195
|
+
const m = createMenus(ctx)
|
|
196
|
+
const toggle = vi.fn()
|
|
197
|
+
m.toggleCheckboxWithKeyboard({ key: 'a', preventDefault: vi.fn() } as any, toggle)
|
|
198
|
+
expect(toggle).not.toHaveBeenCalled()
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
describe('createMenus - isColumnFiltered', () => {
|
|
203
|
+
it('true when a value filter exists', () => {
|
|
204
|
+
const ctx = makeCtx({ valueFilters: { team: new Set(['A']) } })
|
|
205
|
+
const m = createMenus(ctx)
|
|
206
|
+
expect(m.isColumnFiltered('team')).toBe(true)
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('true when a menu filter has a non-empty value', () => {
|
|
210
|
+
const ctx = makeCtx({ filterMenuValues: { name: { operator: 'contains', value: 'x' } } })
|
|
211
|
+
const m = createMenus(ctx)
|
|
212
|
+
expect(m.isColumnFiltered('name')).toBe(true)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('true for isBlank operator regardless of value', () => {
|
|
216
|
+
const ctx = makeCtx({ filterMenuValues: { name: { operator: 'isBlank', value: '' } } })
|
|
217
|
+
const m = createMenus(ctx)
|
|
218
|
+
expect(m.isColumnFiltered('name')).toBe(true)
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('false for an empty/whitespace menu value', () => {
|
|
222
|
+
const ctx = makeCtx({ filterMenuValues: { name: { operator: 'contains', value: ' ' } } })
|
|
223
|
+
const m = createMenus(ctx)
|
|
224
|
+
expect(m.isColumnFiltered('name')).toBe(false)
|
|
225
|
+
expect(m.isColumnFiltered('other')).toBe(false)
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
describe('createMenus - closeMenus and open* toggles', () => {
|
|
230
|
+
it('closeMenus clears all popover state', () => {
|
|
231
|
+
const ctx = makeCtx({
|
|
232
|
+
columnMenuFor: 'a',
|
|
233
|
+
filterMenuFor: 'b',
|
|
234
|
+
operatorMenuFor: 'c',
|
|
235
|
+
chooseColumnsPos: { x: 1, y: 1 },
|
|
236
|
+
})
|
|
237
|
+
const m = createMenus(ctx)
|
|
238
|
+
m.closeMenus()
|
|
239
|
+
expect(ctx.columnMenuFor).toBeNull()
|
|
240
|
+
expect(ctx.filterMenuFor).toBeNull()
|
|
241
|
+
expect(ctx.operatorMenuFor).toBeNull()
|
|
242
|
+
expect(ctx.chooseColumnsPos).toBeNull()
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
function fakeMouseEvent() {
|
|
246
|
+
const el = document.createElement('div')
|
|
247
|
+
el.getBoundingClientRect = () =>
|
|
248
|
+
({ left: 100, right: 300, top: 50, bottom: 70, width: 200, height: 20 } as DOMRect)
|
|
249
|
+
return {
|
|
250
|
+
stopPropagation: vi.fn(),
|
|
251
|
+
currentTarget: el,
|
|
252
|
+
} as any
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
it('openColumnMenu opens, and a second call on the same column closes (toggle)', () => {
|
|
256
|
+
const ctx = makeCtx()
|
|
257
|
+
const m = createMenus(ctx)
|
|
258
|
+
m.openColumnMenu(fakeMouseEvent(), 'name')
|
|
259
|
+
expect(ctx.columnMenuFor).toBe('name')
|
|
260
|
+
expect(ctx.columnMenuPos).toBeTruthy()
|
|
261
|
+
// toggle off
|
|
262
|
+
m.openColumnMenu(fakeMouseEvent(), 'name')
|
|
263
|
+
expect(ctx.columnMenuFor).toBeNull()
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it('openFilterMenu opens the funnel popover in menu mode', () => {
|
|
267
|
+
const ctx = makeCtx({ showColumnFiltersEffective: true })
|
|
268
|
+
const m = createMenus(ctx)
|
|
269
|
+
m.openFilterMenu(fakeMouseEvent(), 'name')
|
|
270
|
+
expect(ctx.filterMenuFor).toBe('name')
|
|
271
|
+
expect(ctx.columnMenuSearch).toBe('')
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('openFilterMenu redirects focus to the inline input in row mode', () => {
|
|
275
|
+
const container = document.createElement('div')
|
|
276
|
+
const input = document.createElement('input')
|
|
277
|
+
input.setAttribute('data-svgrid-filter-col', 'name')
|
|
278
|
+
input.focus = vi.fn()
|
|
279
|
+
input.select = vi.fn()
|
|
280
|
+
container.appendChild(input)
|
|
281
|
+
const ctx = makeCtx({
|
|
282
|
+
showColumnFiltersEffective: false,
|
|
283
|
+
showFilterRowEffective: true,
|
|
284
|
+
scrollContainer: container,
|
|
285
|
+
})
|
|
286
|
+
const m = createMenus(ctx)
|
|
287
|
+
m.openFilterMenu(fakeMouseEvent(), 'name')
|
|
288
|
+
expect(input.focus).toHaveBeenCalled()
|
|
289
|
+
expect(input.select).toHaveBeenCalled()
|
|
290
|
+
expect(input.classList.contains('sv-grid-filter-value-pulse')).toBe(true)
|
|
291
|
+
expect(ctx.filterMenuFor).toBeNull()
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
it('openOperatorMenu opens and toggles closed', () => {
|
|
295
|
+
const ctx = makeCtx()
|
|
296
|
+
const m = createMenus(ctx)
|
|
297
|
+
m.openOperatorMenu(fakeMouseEvent(), 'age')
|
|
298
|
+
expect(ctx.operatorMenuFor).toBe('age')
|
|
299
|
+
m.openOperatorMenu(fakeMouseEvent(), 'age')
|
|
300
|
+
expect(ctx.operatorMenuFor).toBeNull()
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
it('openChooseColumns positions the submenu panel', () => {
|
|
304
|
+
const ctx = makeCtx()
|
|
305
|
+
const m = createMenus(ctx)
|
|
306
|
+
const el = document.createElement('div')
|
|
307
|
+
el.getBoundingClientRect = () =>
|
|
308
|
+
({ left: 100, right: 300, top: 50, bottom: 70, width: 200, height: 20 } as DOMRect)
|
|
309
|
+
m.openChooseColumns({ stopPropagation: vi.fn(), currentTarget: el } as any)
|
|
310
|
+
expect(ctx.chooseColumnsPos).toBeTruthy()
|
|
311
|
+
expect(typeof ctx.chooseColumnsPos.x).toBe('number')
|
|
312
|
+
})
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
describe('createMenus - sorting and grouping from menu', () => {
|
|
316
|
+
it('sortColumnFromMenu sets a single sort and closes menus', () => {
|
|
317
|
+
const ctx = makeCtx({ columnMenuFor: 'name' })
|
|
318
|
+
const m = createMenus(ctx)
|
|
319
|
+
m.sortColumnFromMenu('name', true)
|
|
320
|
+
expect(ctx.grid._peek().sorting).toEqual([{ id: 'name', desc: true }])
|
|
321
|
+
expect(ctx.columnMenuFor).toBeNull()
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
it('clearColumnSort removes that column from sorting', () => {
|
|
325
|
+
const ctx = makeCtx({ gridState: { sorting: [{ id: 'name', desc: false }, { id: 'age', desc: true }] } })
|
|
326
|
+
const m = createMenus(ctx)
|
|
327
|
+
m.clearColumnSort('name')
|
|
328
|
+
expect(ctx.grid._peek().sorting).toEqual([{ id: 'age', desc: true }])
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
it('groupByColumnFromMenu adds a new grouping column', () => {
|
|
332
|
+
const ctx = makeCtx({ grouping: [] })
|
|
333
|
+
const m = createMenus(ctx)
|
|
334
|
+
m.groupByColumnFromMenu('team')
|
|
335
|
+
expect(ctx.grid.setGrouping).toHaveBeenCalledWith(['team'])
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('groupByColumnFromMenu is a no-op when already grouped', () => {
|
|
339
|
+
const ctx = makeCtx({ grouping: ['team'] })
|
|
340
|
+
const m = createMenus(ctx)
|
|
341
|
+
m.groupByColumnFromMenu('team')
|
|
342
|
+
expect(ctx.grid.setGrouping).not.toHaveBeenCalled()
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
it('clearGroupingFromMenu removes the column', () => {
|
|
346
|
+
const ctx = makeCtx({ grouping: ['team', 'dept'] })
|
|
347
|
+
const m = createMenus(ctx)
|
|
348
|
+
m.clearGroupingFromMenu('team')
|
|
349
|
+
expect(ctx.grid.setGrouping).toHaveBeenCalledWith(['dept'])
|
|
350
|
+
})
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
describe('createMenus - facet checkboxes', () => {
|
|
354
|
+
it('isFacetChecked: checked by default, unchecked when excluded', () => {
|
|
355
|
+
const ctx = makeCtx({ valueFilters: { team: new Set(['A']) } })
|
|
356
|
+
const m = createMenus(ctx)
|
|
357
|
+
expect(m.isFacetChecked('team', 'A')).toBe(true)
|
|
358
|
+
expect(m.isFacetChecked('team', 'B')).toBe(false)
|
|
359
|
+
// no filter for column -> default checked
|
|
360
|
+
expect(m.isFacetChecked('other', 'X')).toBe(true)
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
it('toggleFacetValue removes a value, building the set from all values', () => {
|
|
364
|
+
const ctx = makeCtx({ columnMenuFacetValues: ['A', 'B', 'C'] })
|
|
365
|
+
const m = createMenus(ctx)
|
|
366
|
+
m.toggleFacetValue('team', 'A')
|
|
367
|
+
expect([...ctx.valueFilters.team].sort()).toEqual(['B', 'C'])
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
it('toggleFacetValue re-adding the last value clears the filter (all selected)', () => {
|
|
371
|
+
const ctx = makeCtx({
|
|
372
|
+
columnMenuFacetValues: ['A', 'B'],
|
|
373
|
+
valueFilters: { team: new Set(['A']) },
|
|
374
|
+
})
|
|
375
|
+
const m = createMenus(ctx)
|
|
376
|
+
m.toggleFacetValue('team', 'B') // now {A,B} == all -> filter removed
|
|
377
|
+
expect(ctx.valueFilters.team).toBeUndefined()
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
it('setFacetSelection stores a subset as-is', () => {
|
|
381
|
+
const ctx = makeCtx({ columnMenuFacetValues: ['A', 'B', 'C'] })
|
|
382
|
+
const m = createMenus(ctx)
|
|
383
|
+
m.setFacetSelection('team', new Set(['B', 'C']))
|
|
384
|
+
expect([...ctx.valueFilters.team].sort()).toEqual(['B', 'C'])
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
it('setFacetSelection with everything selected drops the entry', () => {
|
|
388
|
+
const ctx = makeCtx({
|
|
389
|
+
columnMenuFacetValues: ['A', 'B'],
|
|
390
|
+
valueFilters: { team: new Set(['A']) },
|
|
391
|
+
})
|
|
392
|
+
const m = createMenus(ctx)
|
|
393
|
+
m.setFacetSelection('team', new Set(['A', 'B']))
|
|
394
|
+
expect(ctx.valueFilters.team).toBeUndefined()
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
it('setFacetSelection copies the set it is handed', () => {
|
|
398
|
+
const ctx = makeCtx({ columnMenuFacetValues: ['A', 'B', 'C'] })
|
|
399
|
+
const m = createMenus(ctx)
|
|
400
|
+
const incoming = new Set(['A'])
|
|
401
|
+
m.setFacetSelection('team', incoming)
|
|
402
|
+
incoming.add('B')
|
|
403
|
+
expect([...ctx.valueFilters.team]).toEqual(['A'])
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
it('isAllFacetsChecked true with no filter, false with a subset', () => {
|
|
407
|
+
const ctx = makeCtx({
|
|
408
|
+
columnMenuFacetValues: ['A', 'B'],
|
|
409
|
+
valueFilters: { team: new Set(['A']) },
|
|
410
|
+
})
|
|
411
|
+
const m = createMenus(ctx)
|
|
412
|
+
expect(m.isAllFacetsChecked('team')).toBe(false)
|
|
413
|
+
expect(m.isAllFacetsChecked('other')).toBe(true)
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
it('toggleAllFacets clears to empty set when all checked', () => {
|
|
417
|
+
const ctx = makeCtx({ columnMenuFacetValues: ['A', 'B'] })
|
|
418
|
+
const m = createMenus(ctx)
|
|
419
|
+
m.toggleAllFacets('team') // was all checked -> empty set
|
|
420
|
+
expect(ctx.valueFilters.team.size).toBe(0)
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
it('toggleAllFacets restores all when currently a subset', () => {
|
|
424
|
+
const ctx = makeCtx({
|
|
425
|
+
columnMenuFacetValues: ['A', 'B'],
|
|
426
|
+
valueFilters: { team: new Set(['A']) },
|
|
427
|
+
})
|
|
428
|
+
const m = createMenus(ctx)
|
|
429
|
+
m.toggleAllFacets('team') // was subset -> remove filter (all)
|
|
430
|
+
expect(ctx.valueFilters.team).toBeUndefined()
|
|
431
|
+
})
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
describe('createMenus - clearColumnFilter', () => {
|
|
435
|
+
it('clears value, menu, and row filter state for the column', () => {
|
|
436
|
+
const ctx = makeCtx({
|
|
437
|
+
valueFilters: { team: new Set(['A']) },
|
|
438
|
+
filterMenuValues: { team: { operator: 'contains', value: 'x' } },
|
|
439
|
+
filterRowValues: { team: 'x' },
|
|
440
|
+
})
|
|
441
|
+
const m = createMenus(ctx)
|
|
442
|
+
m.clearColumnFilter('team')
|
|
443
|
+
expect(ctx.valueFilters.team).toBeUndefined()
|
|
444
|
+
expect(ctx.filterMenuValues.team).toBeUndefined()
|
|
445
|
+
expect(ctx.filterRowValues.team).toBeUndefined()
|
|
446
|
+
})
|
|
447
|
+
|
|
448
|
+
it('is a no-op when nothing is set for the column', () => {
|
|
449
|
+
const ctx = makeCtx()
|
|
450
|
+
const m = createMenus(ctx)
|
|
451
|
+
expect(() => m.clearColumnFilter('team')).not.toThrow()
|
|
452
|
+
})
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
describe('createMenus - pagination', () => {
|
|
456
|
+
it('changePage applies the delta', () => {
|
|
457
|
+
const ctx = makeCtx()
|
|
458
|
+
const m = createMenus(ctx)
|
|
459
|
+
m.changePage(1)
|
|
460
|
+
const updater = ctx.grid.setPagination.mock.calls[0][0]
|
|
461
|
+
expect(updater({ pageIndex: 2, pageSize: 10 })).toEqual({ pageIndex: 3, pageSize: 10 })
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
it('changePage clamps to zero on a negative delta', () => {
|
|
465
|
+
const ctx = makeCtx()
|
|
466
|
+
const m = createMenus(ctx)
|
|
467
|
+
m.changePage(-1)
|
|
468
|
+
const updater = ctx.grid.setPagination.mock.calls[0][0]
|
|
469
|
+
expect(updater({ pageIndex: 0, pageSize: 10 })).toEqual({ pageIndex: 0, pageSize: 10 })
|
|
470
|
+
expect(updater(undefined)).toEqual({ pageIndex: 0 }) // missing prev -> 0
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
it('goToPage clamps to zero', () => {
|
|
474
|
+
const ctx = makeCtx()
|
|
475
|
+
const m = createMenus(ctx)
|
|
476
|
+
m.goToPage(-5)
|
|
477
|
+
const updater = ctx.grid.setPagination.mock.calls[0][0]
|
|
478
|
+
expect(updater({ pageIndex: 9 })).toEqual({ pageIndex: 0 })
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
it('setPageSize keeps the first visible row in view', () => {
|
|
482
|
+
const ctx = makeCtx()
|
|
483
|
+
const m = createMenus(ctx)
|
|
484
|
+
m.setPageSize(20)
|
|
485
|
+
const updater = ctx.grid.setPagination.mock.calls[0][0]
|
|
486
|
+
// firstVisibleRow = 2*10 = 20; new index = floor(20/20) = 1
|
|
487
|
+
expect(updater({ pageIndex: 2, pageSize: 10 })).toEqual({ pageIndex: 1, pageSize: 20 })
|
|
488
|
+
})
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
describe('createMenus - context menu open/close', () => {
|
|
492
|
+
function fakeContextEvent() {
|
|
493
|
+
return { preventDefault: vi.fn(), clientX: 120, clientY: 200 } as any
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
it('openContextMenu is a no-op when contextMenu prop is unset', () => {
|
|
497
|
+
const ctx = makeCtx({ props: {} })
|
|
498
|
+
const m = createMenus(ctx)
|
|
499
|
+
const ev = fakeContextEvent()
|
|
500
|
+
m.openContextMenu(ev, 0, 0, 'name')
|
|
501
|
+
expect(ev.preventDefault).not.toHaveBeenCalled()
|
|
502
|
+
expect(ctx.contextMenuFor).toBeNull()
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
it('openContextMenu sets the target and position', () => {
|
|
506
|
+
const ctx = makeCtx({
|
|
507
|
+
props: { contextMenu: true },
|
|
508
|
+
allRows: [{ id: 'r0', original: { id: 0, name: 'x' } }],
|
|
509
|
+
})
|
|
510
|
+
const m = createMenus(ctx)
|
|
511
|
+
const ev = fakeContextEvent()
|
|
512
|
+
m.openContextMenu(ev, 0, 1, 'name')
|
|
513
|
+
expect(ev.preventDefault).toHaveBeenCalled()
|
|
514
|
+
expect(ctx.contextMenuFor).toEqual({
|
|
515
|
+
rowIndex: 0,
|
|
516
|
+
colIndex: 1,
|
|
517
|
+
columnId: 'name',
|
|
518
|
+
rowId: 'r0',
|
|
519
|
+
row: { id: 0, name: 'x' },
|
|
520
|
+
})
|
|
521
|
+
expect(ctx.contextMenuPos).toBeTruthy()
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
it('openContextMenu falls back to rowIndex when the row model is missing', () => {
|
|
525
|
+
const ctx = makeCtx({ props: { contextMenu: true }, allRows: [] })
|
|
526
|
+
const m = createMenus(ctx)
|
|
527
|
+
m.openContextMenu(fakeContextEvent(), 3, 0, 'name')
|
|
528
|
+
expect(ctx.contextMenuFor.rowId).toBe('3')
|
|
529
|
+
expect(ctx.contextMenuFor.row).toBeNull()
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
it('closeContextMenu clears the target', () => {
|
|
533
|
+
const ctx = makeCtx({ contextMenuFor: { rowIndex: 0 } })
|
|
534
|
+
const m = createMenus(ctx)
|
|
535
|
+
m.closeContextMenu()
|
|
536
|
+
expect(ctx.contextMenuFor).toBeNull()
|
|
537
|
+
})
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
describe('createMenus - contextMenuItems', () => {
|
|
541
|
+
it('returns [] with no target', () => {
|
|
542
|
+
const ctx = makeCtx({ contextMenuFor: null })
|
|
543
|
+
const m = createMenus(ctx)
|
|
544
|
+
expect(m.contextMenuItems()).toEqual([])
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
it('resolves the default built-in items and trims separators', () => {
|
|
548
|
+
const ctx = makeCtx({
|
|
549
|
+
props: { contextMenu: true },
|
|
550
|
+
contextMenuFor: { rowIndex: 0, colIndex: 0, columnId: 'name', rowId: 'r0', row: { id: 0 } },
|
|
551
|
+
})
|
|
552
|
+
const m = createMenus(ctx)
|
|
553
|
+
const items = m.contextMenuItems()
|
|
554
|
+
const labels = items.filter((i) => !i.separator).map((i) => i.label)
|
|
555
|
+
expect(labels).toContain('Copy')
|
|
556
|
+
expect(labels).toContain('Paste')
|
|
557
|
+
expect(labels).toContain('Remove row')
|
|
558
|
+
expect(labels).toContain('Remove column')
|
|
559
|
+
// no leading/trailing separator
|
|
560
|
+
expect(items[0].separator).toBeFalsy()
|
|
561
|
+
expect(items[items.length - 1].separator).toBeFalsy()
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
it('built-in run wiring invokes clipboard helpers', () => {
|
|
565
|
+
const ctx = makeCtx({
|
|
566
|
+
props: { contextMenu: ['copy', 'cut', 'paste', 'clear'] },
|
|
567
|
+
contextMenuFor: { rowIndex: 0, colIndex: 0, columnId: 'name', rowId: 'r0', row: { id: 0 } },
|
|
568
|
+
})
|
|
569
|
+
const m = createMenus(ctx)
|
|
570
|
+
const items = m.contextMenuItems()
|
|
571
|
+
items.find((i) => i.key === 'copy')!.run!()
|
|
572
|
+
items.find((i) => i.key === 'cut')!.run!()
|
|
573
|
+
items.find((i) => i.key === 'paste')!.run!()
|
|
574
|
+
items.find((i) => i.key === 'clear')!.run!()
|
|
575
|
+
expect(ctx.copySelectionToClipboard).toHaveBeenCalled()
|
|
576
|
+
expect(ctx.cutSelectionToClipboard).toHaveBeenCalled()
|
|
577
|
+
expect(ctx.pasteFromClipboard).toHaveBeenCalled()
|
|
578
|
+
expect(ctx.clearSelectedCells).toHaveBeenCalled()
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
it('row_above / row_below / remove_row mutate internalData', () => {
|
|
582
|
+
const rowA = { id: 1 }
|
|
583
|
+
const rowB = { id: 2 }
|
|
584
|
+
const ctx = makeCtx({
|
|
585
|
+
props: { contextMenu: ['row_above', 'row_below', 'remove_row'] },
|
|
586
|
+
internalData: [rowA, rowB],
|
|
587
|
+
contextMenuFor: { rowIndex: 1, colIndex: 0, columnId: 'name', rowId: 'r1', row: rowB },
|
|
588
|
+
})
|
|
589
|
+
const m = createMenus(ctx)
|
|
590
|
+
const items = m.contextMenuItems()
|
|
591
|
+
items.find((i) => i.key === 'row_above')!.run!()
|
|
592
|
+
expect(ctx.internalData.length).toBe(3)
|
|
593
|
+
expect(ctx.internalData.indexOf(rowB)).toBe(2) // inserted above rowB
|
|
594
|
+
// remove
|
|
595
|
+
const m2 = createMenus(makeCtx({
|
|
596
|
+
props: { contextMenu: ['remove_row'] },
|
|
597
|
+
internalData: [rowA, rowB],
|
|
598
|
+
contextMenuFor: { rowIndex: 1, colIndex: 0, columnId: 'name', rowId: 'r1', row: rowB },
|
|
599
|
+
}))
|
|
600
|
+
const ctx2 = (m2 as any)
|
|
601
|
+
const removeItem = m2.contextMenuItems().find((i) => i.key === 'remove_row')!
|
|
602
|
+
removeItem.run!()
|
|
603
|
+
})
|
|
604
|
+
|
|
605
|
+
it('remove_col removes the matching column def', () => {
|
|
606
|
+
const ctx = makeCtx({
|
|
607
|
+
props: { contextMenu: ['remove_col'] },
|
|
608
|
+
internalColumns: [{ id: 'name' }, { field: 'team' }],
|
|
609
|
+
contextMenuFor: { rowIndex: 0, colIndex: 1, columnId: 'team', rowId: 'r0', row: { id: 0 } },
|
|
610
|
+
})
|
|
611
|
+
const m = createMenus(ctx)
|
|
612
|
+
m.contextMenuItems().find((i) => i.key === 'remove_col')!.run!()
|
|
613
|
+
expect(ctx.internalColumns).toEqual([{ id: 'name' }])
|
|
614
|
+
})
|
|
615
|
+
|
|
616
|
+
it('custom items honor hidden() and disabled() predicates', () => {
|
|
617
|
+
const action = vi.fn()
|
|
618
|
+
const ctx = makeCtx({
|
|
619
|
+
props: {
|
|
620
|
+
contextMenu: [
|
|
621
|
+
{ key: 'shown', label: 'Shown', action, disabled: () => true },
|
|
622
|
+
{ key: 'gone', label: 'Gone', action, hidden: () => true },
|
|
623
|
+
],
|
|
624
|
+
},
|
|
625
|
+
contextMenuFor: { rowIndex: 0, colIndex: 0, columnId: 'name', rowId: 'r0', row: { id: 0 } },
|
|
626
|
+
})
|
|
627
|
+
const m = createMenus(ctx)
|
|
628
|
+
const items = m.contextMenuItems()
|
|
629
|
+
expect(items.map((i) => i.key)).toEqual(['shown'])
|
|
630
|
+
expect(items[0].disabled).toBe(true)
|
|
631
|
+
items[0].run!()
|
|
632
|
+
expect(action).toHaveBeenCalled()
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
it('appends comment item when editableComments enabled with default config', () => {
|
|
636
|
+
const ctx = makeCtx({
|
|
637
|
+
props: { contextMenu: true, editableComments: true },
|
|
638
|
+
contextMenuFor: { rowIndex: 0, colIndex: 0, columnId: 'name', rowId: 'r0', row: { id: 0 } },
|
|
639
|
+
})
|
|
640
|
+
const m = createMenus(ctx)
|
|
641
|
+
const labels = m.contextMenuItems().map((i) => i.label)
|
|
642
|
+
expect(labels).toContain('Edit comment')
|
|
643
|
+
})
|
|
644
|
+
})
|
|
645
|
+
|
|
646
|
+
describe('createMenus - comments', () => {
|
|
647
|
+
it('comment item opens the editor seeded from existing note', () => {
|
|
648
|
+
const ctx = makeCtx({
|
|
649
|
+
props: { contextMenu: ['comment'], notes: { r0: { name: 'hello' } } },
|
|
650
|
+
contextMenuPos: { x: 5, y: 9 },
|
|
651
|
+
contextMenuFor: { rowIndex: 0, colIndex: 0, columnId: 'name', rowId: 'r0', row: { id: 0 } },
|
|
652
|
+
})
|
|
653
|
+
const m = createMenus(ctx)
|
|
654
|
+
m.contextMenuItems().find((i) => i.key === 'comment')!.run!()
|
|
655
|
+
expect(ctx.commentDraft).toBe('hello')
|
|
656
|
+
expect(ctx.commentEditFor).toEqual({ rowId: 'r0', columnId: 'name', x: 5, y: 9 })
|
|
657
|
+
expect(ctx.contextMenuFor).toBeNull()
|
|
658
|
+
})
|
|
659
|
+
|
|
660
|
+
it('saveComment writes the draft via onNoteChange and closes', () => {
|
|
661
|
+
const onNoteChange = vi.fn()
|
|
662
|
+
const ctx = makeCtx({
|
|
663
|
+
props: { onNoteChange },
|
|
664
|
+
commentEditFor: { rowId: 'r0', columnId: 'name', x: 0, y: 0 },
|
|
665
|
+
commentDraft: 'note text',
|
|
666
|
+
})
|
|
667
|
+
const m = createMenus(ctx)
|
|
668
|
+
m.saveComment()
|
|
669
|
+
expect(ctx.noteOverrides.r0.name).toBe('note text')
|
|
670
|
+
expect(onNoteChange).toHaveBeenCalledWith({ rowId: 'r0', columnId: 'name', note: 'note text' })
|
|
671
|
+
expect(ctx.commentEditFor).toBeNull()
|
|
672
|
+
})
|
|
673
|
+
|
|
674
|
+
it('saveComment is a no-op without an active editor', () => {
|
|
675
|
+
const ctx = makeCtx({ commentEditFor: null })
|
|
676
|
+
const m = createMenus(ctx)
|
|
677
|
+
m.saveComment()
|
|
678
|
+
expect(ctx.commentEditFor).toBeNull()
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
it('removeComment writes an empty note and closes', () => {
|
|
682
|
+
const ctx = makeCtx({
|
|
683
|
+
commentEditFor: { rowId: 'r0', columnId: 'name', x: 0, y: 0 },
|
|
684
|
+
noteOverrides: { r0: { name: 'old' } },
|
|
685
|
+
})
|
|
686
|
+
const m = createMenus(ctx)
|
|
687
|
+
m.removeComment()
|
|
688
|
+
expect(ctx.noteOverrides.r0.name).toBe('')
|
|
689
|
+
expect(ctx.commentEditFor).toBeNull()
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
it('removeComment is a no-op without an active editor', () => {
|
|
693
|
+
const ctx = makeCtx({ commentEditFor: null })
|
|
694
|
+
const m = createMenus(ctx)
|
|
695
|
+
expect(() => m.removeComment()).not.toThrow()
|
|
696
|
+
})
|
|
697
|
+
|
|
698
|
+
it('closeCommentEditor clears the editor', () => {
|
|
699
|
+
const ctx = makeCtx({ commentEditFor: { rowId: 'r0', columnId: 'name', x: 0, y: 0 } })
|
|
700
|
+
const m = createMenus(ctx)
|
|
701
|
+
m.closeCommentEditor()
|
|
702
|
+
expect(ctx.commentEditFor).toBeNull()
|
|
703
|
+
})
|
|
704
|
+
})
|
|
705
|
+
|
|
706
|
+
describe('createMenus - chart context-menu item', () => {
|
|
707
|
+
const target = { rowIndex: 0, colIndex: 0, columnId: 'a', rowId: '0', row: {} }
|
|
708
|
+
|
|
709
|
+
it('appends "Chart selected range" to the default menu when charting is enabled', () => {
|
|
710
|
+
const ctx = makeCtx({ props: { contextMenu: true }, chartingEnabled: true, contextMenuFor: target })
|
|
711
|
+
const items = createMenus(ctx).contextMenuItems()
|
|
712
|
+
expect(items.map((i) => i.label)).toContain('Chart selected range')
|
|
713
|
+
})
|
|
714
|
+
|
|
715
|
+
it('omits the chart item when charting is disabled', () => {
|
|
716
|
+
const ctx = makeCtx({ props: { contextMenu: true }, chartingEnabled: false, contextMenuFor: target })
|
|
717
|
+
const items = createMenus(ctx).contextMenuItems()
|
|
718
|
+
expect(items.map((i) => i.label)).not.toContain('Chart selected range')
|
|
719
|
+
})
|
|
720
|
+
|
|
721
|
+
it('clicking the chart item opens the chart panel', () => {
|
|
722
|
+
const ctx = makeCtx({ props: { contextMenu: true }, chartingEnabled: true, chartPanelOpen: false, contextMenuFor: target })
|
|
723
|
+
const item = createMenus(ctx).contextMenuItems().find((i) => i.label === 'Chart selected range')
|
|
724
|
+
item?.run?.()
|
|
725
|
+
expect(ctx.chartPanelOpen).toBe(true)
|
|
726
|
+
})
|
|
727
|
+
|
|
728
|
+
it('localizes the chart item label via ctx.messages', () => {
|
|
729
|
+
const ctx = makeCtx({
|
|
730
|
+
props: { contextMenu: true }, chartingEnabled: true, contextMenuFor: target,
|
|
731
|
+
messages: { chartRange: 'Graphique de la selection' },
|
|
732
|
+
})
|
|
733
|
+
const items = createMenus(ctx).contextMenuItems()
|
|
734
|
+
expect(items.map((i) => i.label)).toContain('Graphique de la selection')
|
|
735
|
+
})
|
|
736
|
+
})
|