@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.
Files changed (248) hide show
  1. package/README.md +199 -199
  2. package/dist/FlexRender.svelte +96 -96
  3. package/dist/GridFooter.svelte +179 -179
  4. package/dist/GridMenus.svelte +782 -734
  5. package/dist/SvAutoComplete.svelte +165 -165
  6. package/dist/SvCalendar.svelte +503 -503
  7. package/dist/SvCarousel.svelte +141 -141
  8. package/dist/SvCheckBox.svelte +101 -101
  9. package/dist/SvColorInput.svelte +181 -181
  10. package/dist/SvComboBox.svelte +275 -275
  11. package/dist/SvContextMenu.svelte +116 -116
  12. package/dist/SvCountryInput.svelte +160 -160
  13. package/dist/SvDrawer.svelte +254 -250
  14. package/dist/SvDropDownList.svelte +374 -374
  15. package/dist/SvDurationInput.svelte +126 -126
  16. package/dist/SvField.svelte +293 -293
  17. package/dist/SvForm.svelte +437 -437
  18. package/dist/SvGrid.controller.svelte.d.ts +14 -1
  19. package/dist/SvGrid.controller.svelte.js +112 -28
  20. package/dist/SvGrid.css +2704 -2723
  21. package/dist/SvGrid.svelte +3361 -3333
  22. package/dist/SvGrid.types.d.ts +20 -5
  23. package/dist/SvGridChart.svelte +1724 -1724
  24. package/dist/SvGridChartPanel.svelte +485 -485
  25. package/dist/SvGridChartView.svelte +70 -70
  26. package/dist/SvGridDropdown.svelte +696 -696
  27. package/dist/SvGridSelect.svelte +259 -259
  28. package/dist/SvGroupCell.svelte +109 -109
  29. package/dist/SvListBox.svelte +326 -287
  30. package/dist/SvListBox.svelte.d.ts +10 -1
  31. package/dist/SvMaskedInput.svelte +122 -122
  32. package/dist/SvMenu.svelte +124 -124
  33. package/dist/SvMenuList.svelte +146 -146
  34. package/dist/SvMultiSelect.svelte +281 -281
  35. package/dist/SvNumberInput.svelte +168 -168
  36. package/dist/SvOtpInput.svelte +158 -158
  37. package/dist/SvPasswordInput.svelte +151 -151
  38. package/dist/SvPhoneInput.svelte +133 -131
  39. package/dist/SvPopover.svelte +197 -197
  40. package/dist/SvRadioGroup.svelte +107 -107
  41. package/dist/SvRowGroupPanel.svelte +170 -170
  42. package/dist/SvScrollArea.svelte +61 -61
  43. package/dist/SvSlider.svelte +200 -200
  44. package/dist/SvSwitchButton.svelte +107 -107
  45. package/dist/SvTagsInput.svelte +112 -112
  46. package/dist/SvTextInput.svelte +147 -147
  47. package/dist/SvTimePicker.svelte +245 -245
  48. package/dist/SvToaster.svelte +159 -159
  49. package/dist/SvToggleButton.svelte +85 -85
  50. package/dist/SvTooltip.svelte +161 -161
  51. package/dist/SvTour.svelte +204 -204
  52. package/dist/SvTree.svelte +437 -437
  53. package/dist/SvTreeSelect.svelte +233 -233
  54. package/dist/cdn/GridMenus-Da_p7SKS.js +486 -0
  55. package/dist/cdn/GridMenus-Ds3OpzZT.js +490 -0
  56. package/dist/cdn/{SvDateTimePicker-B1sDc9Pz.js → SvDateTimePicker-B8GopjhC.js} +2 -2
  57. package/dist/cdn/{SvDateTimePicker-Bh0FTs1E.js → SvDateTimePicker-DB0aIEk8.js} +2 -2
  58. package/dist/cdn/{SvGridChart-Bgk4hDs8.js → SvGridChart-BcLCYvw9.js} +1 -1
  59. package/dist/cdn/{SvGridChart-BKQsO5fZ.js → SvGridChart-BhnFdLd0.js} +1 -1
  60. package/dist/cdn/{SvGridChartPanel-DkCc2Z7b.js → SvGridChartPanel-Cmx9DHAS.js} +1 -1
  61. package/dist/cdn/{SvGridChartPanel-DSkHIQDd.js → SvGridChartPanel-DvjwxLvK.js} +1 -1
  62. package/dist/cdn/{SvGridChartView-BrbVaELm.js → SvGridChartView-B40DTJSX.js} +1 -1
  63. package/dist/cdn/{SvGridChartView-i9rWvSKg.js → SvGridChartView-PwqI4s02.js} +1 -1
  64. package/dist/cdn/{SvGridDropdown-D08sVmAy.js → SvGridDropdown-DjALc_4f.js} +1 -1
  65. package/dist/cdn/{SvGridDropdown-CGxxopQ4.js → SvGridDropdown-hpnHvOGt.js} +1 -1
  66. package/dist/cdn/{src-cgs1wcUS.js → src-BLJfdyL0.js} +4034 -3889
  67. package/dist/cdn/{src-Cw8d9U8j.js → src-DYDCiC0D.js} +7053 -6908
  68. package/dist/cdn/svgrid.js +9 -9
  69. package/dist/cdn/svgrid.svelte-external.js +9 -9
  70. package/dist/chart-export.js +8 -8
  71. package/dist/column-groups.js +8 -10
  72. package/dist/column-id.d.ts +9 -0
  73. package/dist/column-id.js +25 -0
  74. package/dist/core.js +2 -1
  75. package/dist/createListbox.svelte.d.ts +15 -2
  76. package/dist/createListbox.svelte.js +27 -6
  77. package/dist/editing.d.ts +1 -0
  78. package/dist/editing.js +45 -10
  79. package/dist/filtering/excel-filters.d.ts +30 -10
  80. package/dist/filtering/excel-filters.js +96 -15
  81. package/dist/index.d.ts +2 -2
  82. package/dist/index.js +2 -2
  83. package/dist/menus.d.ts +2 -0
  84. package/dist/menus.js +25 -0
  85. package/dist/row-resize.js +40 -0
  86. package/dist/selection.js +1 -1
  87. package/package.json +10 -10
  88. package/src/FlexRender.svelte +96 -96
  89. package/src/GridFooter.svelte +179 -179
  90. package/src/GridMenus.svelte +782 -734
  91. package/src/SvAutoComplete.svelte +165 -165
  92. package/src/SvCalendar.svelte +503 -503
  93. package/src/SvCalendar.test.ts +226 -226
  94. package/src/SvCarousel.svelte +141 -141
  95. package/src/SvCheckBox.svelte +101 -101
  96. package/src/SvColorInput.svelte +181 -181
  97. package/src/SvComboBox.svelte +275 -275
  98. package/src/SvContextMenu.svelte +116 -116
  99. package/src/SvCountryInput.svelte +160 -160
  100. package/src/SvDrawer.svelte +254 -250
  101. package/src/SvDrawer.test.ts +18 -1
  102. package/src/SvDropDownList.svelte +374 -374
  103. package/src/SvDurationInput.svelte +126 -126
  104. package/src/SvField.svelte +293 -293
  105. package/src/SvForm.svelte +437 -437
  106. package/src/SvForm.test.ts +411 -411
  107. package/src/SvGrid.controller.svelte.ts +3335 -3239
  108. package/src/SvGrid.css +2704 -2723
  109. package/src/SvGrid.svelte +3361 -3333
  110. package/src/SvGrid.types.ts +1628 -1613
  111. package/src/SvGridChart.svelte +1724 -1724
  112. package/src/SvGridChartPanel.svelte +485 -485
  113. package/src/SvGridChartView.svelte +70 -70
  114. package/src/SvGridDropdown.svelte +696 -696
  115. package/src/SvGridSelect.svelte +259 -259
  116. package/src/SvGroupCell.svelte +109 -109
  117. package/src/SvListBox.svelte +326 -287
  118. package/src/SvMaskedInput.svelte +122 -122
  119. package/src/SvMenu.svelte +124 -124
  120. package/src/SvMenu.test.ts +97 -97
  121. package/src/SvMenuList.svelte +146 -146
  122. package/src/SvMultiSelect.svelte +281 -281
  123. package/src/SvNavPane.test.ts +15 -4
  124. package/src/SvNumberInput.svelte +168 -168
  125. package/src/SvOtpInput.svelte +158 -158
  126. package/src/SvPasswordInput.svelte +151 -151
  127. package/src/SvPhoneInput.svelte +133 -131
  128. package/src/SvPopover.svelte +197 -197
  129. package/src/SvRadioGroup.svelte +107 -107
  130. package/src/SvRowGroupPanel.svelte +170 -170
  131. package/src/SvScrollArea.svelte +61 -61
  132. package/src/SvSlider.svelte +200 -200
  133. package/src/SvSwitchButton.svelte +107 -107
  134. package/src/SvTagsInput.svelte +112 -112
  135. package/src/SvTextInput.svelte +147 -147
  136. package/src/SvTimePicker.svelte +245 -245
  137. package/src/SvToaster.svelte +159 -159
  138. package/src/SvToaster.test.ts +95 -95
  139. package/src/SvToggleButton.svelte +85 -85
  140. package/src/SvTooltip.svelte +161 -161
  141. package/src/SvTour.svelte +204 -204
  142. package/src/SvTree.svelte +437 -437
  143. package/src/SvTreeSelect.svelte +233 -233
  144. package/src/a11y/dismissable.test.ts +119 -119
  145. package/src/a11y/dismissable.ts +114 -114
  146. package/src/a11y.contract.test.ts +49 -49
  147. package/src/a11y.test.ts +59 -59
  148. package/src/a11y.ts +61 -61
  149. package/src/ai.test.ts +502 -502
  150. package/src/ai.ts +1391 -1391
  151. package/src/build-api.coverage.test.ts +633 -633
  152. package/src/build-api.ts +895 -895
  153. package/src/builtin-editors.grid.test.ts +85 -85
  154. package/src/cell-formatting.ts +169 -169
  155. package/src/cell-render.ts +469 -469
  156. package/src/chart-export.ts +201 -201
  157. package/src/chart-view.svelte.ts +36 -36
  158. package/src/chart.ts +2296 -2296
  159. package/src/collaboration.test.ts +104 -104
  160. package/src/collaboration.ts +167 -167
  161. package/src/column-groups.test.ts +48 -0
  162. package/src/column-groups.ts +8 -10
  163. package/src/column-id.ts +30 -0
  164. package/src/core.performance.test.ts +30 -30
  165. package/src/core.ts +1112 -1111
  166. package/src/createAutocomplete.svelte.ts +132 -132
  167. package/src/createCombobox.svelte.ts +191 -191
  168. package/src/createCountryInput.svelte.ts +157 -157
  169. package/src/createDropdownList.svelte.ts +168 -168
  170. package/src/createForm.svelte.ts +386 -386
  171. package/src/createGrid.svelte.ts +42 -42
  172. package/src/createGrid.test.ts +10 -10
  173. package/src/createGridState.svelte.ts +17 -17
  174. package/src/createListbox.svelte.ts +39 -7
  175. package/src/createMenu.svelte.ts +225 -225
  176. package/src/createPopoverSelect.svelte.ts +213 -213
  177. package/src/createSlider.svelte.ts +191 -191
  178. package/src/createTooltip.svelte.ts +144 -144
  179. package/src/createTree.svelte.ts +319 -319
  180. package/src/editing.test.ts +949 -859
  181. package/src/editing.ts +709 -675
  182. package/src/editor-contract.ts +157 -157
  183. package/src/export-data-api.test.ts +126 -126
  184. package/src/export-format.test.ts +107 -107
  185. package/src/export-format.ts +598 -598
  186. package/src/filter-operators.ts +157 -157
  187. package/src/filtering/excel-filters.test.ts +44 -1
  188. package/src/filtering/excel-filters.ts +91 -14
  189. package/src/flex-render.ts +3 -3
  190. package/src/form-field.ts +127 -127
  191. package/src/index.ts +715 -713
  192. package/src/js-scroller.svelte.ts +173 -173
  193. package/src/keyboard.test.ts +59 -59
  194. package/src/keyboard.ts +97 -97
  195. package/src/list-nav.test.ts +49 -49
  196. package/src/list-nav.ts +29 -29
  197. package/src/list-option.test.ts +56 -56
  198. package/src/list-option.ts +172 -172
  199. package/src/menus.test.ts +736 -700
  200. package/src/menus.ts +679 -652
  201. package/src/merge-objects.ts +48 -48
  202. package/src/overlays.test.ts +90 -90
  203. package/src/render-component.ts +28 -28
  204. package/src/row-resize.test.ts +100 -0
  205. package/src/row-resize.ts +36 -0
  206. package/src/scheduler-model.test.ts +562 -562
  207. package/src/scheduler-model.ts +872 -872
  208. package/src/selection.test.ts +754 -754
  209. package/src/selection.ts +600 -600
  210. package/src/server-data-source.test.ts +289 -289
  211. package/src/server-data-source.ts +413 -413
  212. package/src/sparkline.test.ts +68 -68
  213. package/src/sparkline.ts +169 -169
  214. package/src/spreadsheet.test.ts +489 -489
  215. package/src/spreadsheet.ts +312 -312
  216. package/src/static-functions.ts +11 -11
  217. package/src/subscribe.ts +38 -38
  218. package/src/svgrid-wrapper.types.ts +524 -524
  219. package/src/svgrid.api-extensions.test.ts +8 -3
  220. package/src/svgrid.behavior.test.ts +706 -706
  221. package/src/svgrid.cell-dom-ids.test.ts +96 -0
  222. package/src/svgrid.charting.test.ts +534 -534
  223. package/src/svgrid.conditional-stat-scope.test.ts +111 -0
  224. package/src/svgrid.features.test.ts +157 -157
  225. package/src/svgrid.filter-menu-listbox.svelte.test.ts +308 -0
  226. package/src/svgrid.filter-menu-scroll.test.ts +3 -1
  227. package/src/svgrid.group-header-ids.test.ts +121 -0
  228. package/src/svgrid.new-features.wrapper.test.ts +251 -251
  229. package/src/svgrid.wrapper.test.ts +40 -40
  230. package/src/test-setup.ts +62 -62
  231. package/src/themes/index.ts +215 -215
  232. package/src/toast-store.svelte.ts +246 -246
  233. package/src/toast-store.test.ts +147 -147
  234. package/src/ui-buttons.test.ts +144 -144
  235. package/src/ui-inputs.test.ts +118 -118
  236. package/src/ui-range.test.ts +70 -70
  237. package/src/ui-selection.test.ts +155 -155
  238. package/src/ui-tier1.test.ts +142 -142
  239. package/src/virtual.test.ts +88 -88
  240. package/src/virtualization/column-virtualizer.test.ts +27 -27
  241. package/src/virtualization/column-virtualizer.ts +30 -30
  242. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  243. package/src/virtualization/types.ts +30 -30
  244. package/src/virtualization/virtualizer.test.ts +47 -47
  245. package/src/virtualization/virtualizer.ts +296 -296
  246. package/themes/ember.css +71 -71
  247. package/dist/cdn/GridMenus-BzxEYNtW.js +0 -421
  248. package/dist/cdn/GridMenus-Dr-nGEXn.js +0 -417
@@ -1,706 +1,706 @@
1
- /**
2
- * Broad behavioral test suite for the <SvGrid /> render component.
3
- *
4
- * The intent is wide coverage on a single file - SvGrid.svelte is ~3000
5
- * lines and most of its branches are reachable only when the component is
6
- * mounted with a particular prop combination. Each test below exercises a
7
- * different feature set so the whole file's effect graph is traversed.
8
- *
9
- * Pattern (re-used across files):
10
- * 1. mount SvGrid in jsdom with the props that trigger the feature
11
- * 2. wait one microtask for $effects to flush
12
- * 3. assert on the api object delivered via onApiReady, or on visible DOM
13
- * 4. unmount
14
- */
15
-
16
- import { describe, expect, it } from 'vitest'
17
- import { mount, unmount } from 'svelte'
18
- import SvGrid from './SvGrid.svelte'
19
- import {
20
- columnFilteringFeature,
21
- columnGroupingFeature,
22
- createCoreRowModel,
23
- createExpandedRowModel,
24
- createFilteredRowModel,
25
- createGroupedRowModel,
26
- createPaginatedRowModel,
27
- createSortedRowModel,
28
- renderSnippet,
29
- rowExpandingFeature,
30
- rowPaginationFeature,
31
- rowSelectionFeature,
32
- rowSortingFeature,
33
- sortFns,
34
- tableFeatures,
35
- } from './index'
36
- import type { ColumnDef, SvGridApi } from './index'
37
-
38
- type Person = {
39
- id: number
40
- name: string
41
- team: string
42
- age: number
43
- active: boolean
44
- joined: string
45
- salary: number
46
- }
47
-
48
- const fullFeatures = tableFeatures({
49
- columnFilteringFeature,
50
- columnGroupingFeature,
51
- rowExpandingFeature,
52
- rowPaginationFeature,
53
- rowSelectionFeature,
54
- rowSortingFeature,
55
- })
56
-
57
- const people: Person[] = [
58
- { id: 1, name: 'Ada Lovelace', team: 'Research', age: 38, active: true, joined: '2020-01-10', salary: 142_000 },
59
- { id: 2, name: 'Grace Hopper', team: 'Compilers', age: 42, active: true, joined: '2018-05-22', salary: 158_000 },
60
- { id: 3, name: 'Alan Turing', team: 'Research', age: 41, active: false, joined: '2021-09-01', salary: 138_000 },
61
- { id: 4, name: 'Margaret Hamilton', team: 'Apollo', age: 35, active: true, joined: '2019-03-15', salary: 165_000 },
62
- { id: 5, name: 'Linus Torvalds', team: 'Kernel', age: 54, active: true, joined: '2017-11-30', salary: 175_000 },
63
- { id: 6, name: 'Donald Knuth', team: 'Research', age: 86, active: false, joined: '2010-06-06', salary: 120_000 },
64
- { id: 7, name: 'Brian Kernighan', team: 'Compilers', age: 80, active: true, joined: '2012-02-02', salary: 160_000 },
65
- { id: 8, name: 'Dennis Ritchie', team: 'Kernel', age: 70, active: false, joined: '2009-07-14', salary: 110_000 },
66
- ]
67
-
68
- const personColumns: ColumnDef<typeof fullFeatures, Person>[] = [
69
- { field: 'name', header: 'Name', width: 200 },
70
- { field: 'team', header: 'Team', width: 160 },
71
- {
72
- field: 'age',
73
- header: 'Age',
74
- width: 100,
75
- editorType: 'number',
76
- format: { type: 'number' },
77
- },
78
- {
79
- field: 'active',
80
- header: 'Active',
81
- width: 100,
82
- editorType: 'checkbox',
83
- },
84
- {
85
- field: 'joined',
86
- header: 'Joined',
87
- width: 140,
88
- editorType: 'date',
89
- format: { type: 'number' },
90
- },
91
- {
92
- field: 'salary',
93
- header: 'Salary',
94
- width: 140,
95
- editorType: 'number',
96
- format: { type: 'currency', currency: 'USD' },
97
- },
98
- ]
99
-
100
- type MountResult = {
101
- api: SvGridApi<typeof fullFeatures, Person>
102
- target: HTMLElement
103
- destroy: () => void
104
- }
105
-
106
- function mountGrid(overrides: Record<string, unknown> = {}): Promise<MountResult> {
107
- return new Promise((resolveApi, rejectApi) => {
108
- const target = document.createElement('div')
109
- target.style.width = '1200px'
110
- target.style.height = '600px'
111
- document.body.appendChild(target)
112
-
113
- let capturedApi: SvGridApi<typeof fullFeatures, Person> | null = null
114
-
115
- const app = mount(SvGrid, {
116
- target,
117
- props: {
118
- data: people,
119
- columns: personColumns,
120
- features: fullFeatures,
121
- _rowModels: {
122
- coreRowModel: createCoreRowModel(),
123
- filteredRowModel: createFilteredRowModel(),
124
- sortedRowModel: createSortedRowModel(sortFns),
125
- groupedRowModel: createGroupedRowModel(),
126
- expandedRowModel: createExpandedRowModel(),
127
- paginatedRowModel: createPaginatedRowModel(),
128
- },
129
- rowHeight: 36,
130
- containerHeight: 480,
131
- virtualization: false,
132
- onApiReady(api: SvGridApi<typeof fullFeatures, Person>) {
133
- capturedApi = api
134
- resolveApi({
135
- api,
136
- target,
137
- destroy: () => {
138
- unmount(app)
139
- target.remove()
140
- },
141
- })
142
- },
143
- ...overrides,
144
- } as any,
145
- })
146
-
147
- queueMicrotask(() => {
148
- if (!capturedApi) rejectApi(new Error('onApiReady never fired'))
149
- })
150
- })
151
- }
152
-
153
- const tick = () => Promise.resolve()
154
-
155
- describe('SvGrid - core render', () => {
156
- it('mounts and renders the column headers', async () => {
157
- const { target, destroy } = await mountGrid()
158
- try {
159
- const headers = target.querySelectorAll('[data-svgrid-header-col]')
160
- // jsdom reports 0 for offsetWidth so column virtualization may render
161
- // a subset. The point of this assertion is just that the header row
162
- // exists and is populated.
163
- expect(headers.length).toBeGreaterThan(0)
164
- } finally {
165
- destroy()
166
- }
167
- })
168
-
169
- it('renders the rows in the body', async () => {
170
- const { target, destroy } = await mountGrid()
171
- try {
172
- await tick()
173
- const rows = target.querySelectorAll('[data-svgrid-row]')
174
- // Pagination defaults to off in our mount - all rows render.
175
- expect(rows.length).toBeGreaterThanOrEqual(people.length)
176
- } finally {
177
- destroy()
178
- }
179
- })
180
-
181
- it('renders the empty message when data is empty', async () => {
182
- const { target, destroy } = await mountGrid({ data: [], emptyMessage: 'No rows yet' })
183
- try {
184
- await tick()
185
- expect(target.textContent).toContain('No rows yet')
186
- } finally {
187
- destroy()
188
- }
189
- })
190
-
191
- it('renders a loading state when `loading` is true', async () => {
192
- const { target, destroy } = await mountGrid({ loading: true })
193
- try {
194
- await tick()
195
- const statusEls = target.querySelectorAll('[role="status"]')
196
- expect(statusEls.length).toBeGreaterThan(0)
197
- } finally {
198
- destroy()
199
- }
200
- })
201
-
202
- it('renders an error state when `error` is set', async () => {
203
- const { target, destroy } = await mountGrid({ error: 'Something broke' })
204
- try {
205
- await tick()
206
- expect(target.textContent).toContain('Something broke')
207
- } finally {
208
- destroy()
209
- }
210
- })
211
- })
212
-
213
- describe('SvGrid - sort', () => {
214
- it('setSort then clearSort updates filters via api', async () => {
215
- const { api, destroy } = await mountGrid()
216
- try {
217
- api.setSort('name', 'asc')
218
- await tick()
219
- api.setSort('name', 'desc')
220
- await tick()
221
- api.setSort('name', null)
222
- await tick()
223
- api.clearSort()
224
- await tick()
225
- // No throw + state consistent = pass.
226
- expect(api.getData().length).toBe(people.length)
227
- } finally {
228
- destroy()
229
- }
230
- })
231
- })
232
-
233
- describe('SvGrid - pagination', () => {
234
- it('shows fewer displayed rows than total when paginated', async () => {
235
- const { api, destroy } = await mountGrid({ showPagination: true, pageSize: 3 })
236
- try {
237
- await tick()
238
- const displayed = api.getDisplayedRows()
239
- expect(displayed.length).toBeLessThanOrEqual(3)
240
- } finally {
241
- destroy()
242
- }
243
- })
244
- })
245
-
246
- describe('SvGrid - global filter', () => {
247
- it('showGlobalFilter renders the input', async () => {
248
- const { target, destroy } = await mountGrid({ showGlobalFilter: true })
249
- try {
250
- await tick()
251
- const input = target.querySelector(
252
- '.sv-grid-global-filter input, input[type="text"]',
253
- )
254
- expect(input).not.toBeNull()
255
- } finally {
256
- destroy()
257
- }
258
- })
259
- })
260
-
261
- describe('SvGrid - column filter row', () => {
262
- it('showColumnFilters renders the filter row inputs', async () => {
263
- const { target, destroy } = await mountGrid({ showColumnFilters: true })
264
- try {
265
- await tick()
266
- const inputs = target.querySelectorAll('.sv-grid-column-filter')
267
- // One filter input per filterable column.
268
- expect(inputs.length).toBeGreaterThan(0)
269
- } finally {
270
- destroy()
271
- }
272
- })
273
- })
274
-
275
- describe('SvGrid - inline editing', () => {
276
- it('enables enableInlineEditing without throwing', async () => {
277
- const { api, destroy } = await mountGrid({ enableInlineEditing: true })
278
- try {
279
- // setCellValue should mutate internal data.
280
- api.setCellValue(0, 'name', 'Renamed Person')
281
- await tick()
282
- const data = api.getData()
283
- expect((data[0] as Person).name).toBe('Renamed Person')
284
- } finally {
285
- destroy()
286
- }
287
- })
288
- })
289
-
290
- describe('SvGrid - row selection', () => {
291
- it('showRowSelection renders the checkbox column', async () => {
292
- const { target, destroy } = await mountGrid({ showRowSelection: true })
293
- try {
294
- await tick()
295
- const checkboxes = target.querySelectorAll('.sv-grid-checkbox')
296
- // At least the header + one per row.
297
- expect(checkboxes.length).toBeGreaterThan(0)
298
- } finally {
299
- destroy()
300
- }
301
- })
302
- })
303
-
304
- describe('SvGrid - capability shortcuts', () => {
305
- it('sortable + filterable enable sorting/filtering UI with no features prop', async () => {
306
- const { target, destroy } = await mountGrid({
307
- features: undefined,
308
- sortable: true,
309
- filterable: true,
310
- })
311
- try {
312
- await tick()
313
- // rowSortingFeature injected -> headers expose aria-sort.
314
- expect(
315
- target.querySelectorAll('[role="columnheader"][aria-sort]').length,
316
- ).toBeGreaterThan(0)
317
- // columnFilteringFeature injected -> per-column filter button renders.
318
- expect(target.querySelector('.sv-grid-col-filter-btn')).toBeTruthy()
319
- } finally {
320
- destroy()
321
- }
322
- })
323
-
324
- it('sortable={false} overrides a rowSortingFeature passed via features', async () => {
325
- // The harness default `fullFeatures` includes rowSortingFeature.
326
- const { target, destroy } = await mountGrid({ sortable: false })
327
- try {
328
- await tick()
329
- expect(
330
- target.querySelector('[role="columnheader"][aria-sort]'),
331
- ).toBeNull()
332
- } finally {
333
- destroy()
334
- }
335
- })
336
-
337
- it('pageable toggles the pagination footer', async () => {
338
- const off = await mountGrid({ pageable: false })
339
- try {
340
- await tick()
341
- expect(off.target.querySelector('.sv-grid-pagination')).toBeNull()
342
- } finally {
343
- off.destroy()
344
- }
345
- const on = await mountGrid({ features: undefined, pageable: true })
346
- try {
347
- await tick()
348
- expect(on.target.querySelector('.sv-grid-pagination')).toBeTruthy()
349
- } finally {
350
- on.destroy()
351
- }
352
- })
353
-
354
- it('paginationPosition mounts + gates the bottom pager', async () => {
355
- // The top pager is gated on measurement (jsdom does not measure), so it's not
356
- // asserted here; the visible top pager is covered by the browser/e2e check.
357
- // This guards the mount path (a top footer rendered pre-measure used to crash).
358
- for (const paginationPosition of ['top', 'both', 'bottom'] as const) {
359
- const g = await mountGrid({ showPagination: true, paginationPosition })
360
- try {
361
- await tick()
362
- expect(g.api).toBeTruthy()
363
- const bottoms = [...g.target.querySelectorAll('.sv-grid-pagination')].filter((el) => !el.classList.contains('sv-grid-pagination-top'))
364
- expect(bottoms.length).toBe(paginationPosition === 'top' ? 0 : 1) // no bottom pager when position is 'top'
365
- } finally {
366
- g.destroy()
367
- }
368
- }
369
- })
370
-
371
- it('pageSizeOptions is accepted by the pager', async () => {
372
- const g = await mountGrid({ showPagination: true, pageSizeOptions: [5, 15, 45] })
373
- try {
374
- await tick()
375
- expect(g.target.querySelector('.sv-grid-pagination')).toBeTruthy()
376
- } finally {
377
- g.destroy()
378
- }
379
- })
380
-
381
- it('editable={false} blocks inline editing entry points', async () => {
382
- const { api, target, destroy } = await mountGrid({ editable: false })
383
- try {
384
- await tick()
385
- // Double-clicking a body cell must not open an editor when editing
386
- // is disabled via the shortcut.
387
- const cell = target.querySelector<HTMLElement>('.sv-grid-cell')
388
- cell?.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }))
389
- await tick()
390
- expect(target.querySelector('.sv-grid-cell-editor')).toBeNull()
391
- expect(api.getData().length).toBe(people.length)
392
- } finally {
393
- destroy()
394
- }
395
- })
396
- })
397
-
398
- describe('SvGrid - cell selection', () => {
399
- it('enableCellSelection mounts without error', async () => {
400
- const { api, destroy } = await mountGrid({ enableCellSelection: true })
401
- try {
402
- await tick()
403
- expect(api.getData().length).toBe(people.length)
404
- } finally {
405
- destroy()
406
- }
407
- })
408
- })
409
-
410
- describe('SvGrid - grouping + aggregation', () => {
411
- it('setGroupBy mounts + the codepath runs without throwing', async () => {
412
- const { api, target, destroy } = await mountGrid({
413
- enableRowSummaries: true,
414
- showGroupingControls: true,
415
- })
416
- try {
417
- api.setGroupBy(['team'])
418
- await tick()
419
- await tick()
420
- // Sanity: the grid is still mounted and the API responsive.
421
- const data = api.getData()
422
- expect(data.length).toBe(people.length)
423
- // Group rendering depends on row model + container dimensions in jsdom;
424
- // just verify the codepath does not throw.
425
- expect(target).toBeTruthy()
426
- } finally {
427
- destroy()
428
- }
429
- })
430
- })
431
-
432
- describe('SvGrid - column add / remove / visibility', () => {
433
- it('addColumn and removeColumn round-trip', async () => {
434
- const { api, destroy } = await mountGrid()
435
- try {
436
- api.addColumn({ id: 'id-col', field: 'id', header: 'ID', width: 60 } as any, 'left')
437
- await tick()
438
- api.addColumn(
439
- { id: 'extra-tag', field: 'team', header: 'Extra', width: 60 } as any,
440
- 'right',
441
- )
442
- await tick()
443
- api.addColumn(
444
- { id: 'mid-col', field: 'name', header: 'Mid', width: 60 } as any,
445
- 1,
446
- )
447
- await tick()
448
- api.removeColumn('id-col')
449
- await tick()
450
- // No throw means the codepath was exercised.
451
- expect(typeof api.getData).toBe('function')
452
- } finally {
453
- destroy()
454
- }
455
- })
456
-
457
- it('setColumnVisible toggles visibility flag', async () => {
458
- const { api, destroy } = await mountGrid()
459
- try {
460
- expect(api.isColumnVisible('name')).toBe(true)
461
- api.setColumnVisible('name', false)
462
- await tick()
463
- expect(api.isColumnVisible('name')).toBe(false)
464
- api.setColumnVisible('name', true)
465
- await tick()
466
- expect(api.isColumnVisible('name')).toBe(true)
467
- } finally {
468
- destroy()
469
- }
470
- })
471
-
472
- it('columns marked `visible: false` start hidden but stay listed', async () => {
473
- const columns: ColumnDef<typeof fullFeatures, Person>[] = personColumns.map(
474
- (c) => (c.field === 'team' ? { ...c, visible: false } : c),
475
- )
476
- const { api, destroy } = await mountGrid({ columns })
477
- try {
478
- // Starts hidden...
479
- expect(api.isColumnVisible('team')).toBe(false)
480
- // ...but is still listed in getColumns() (so a Choose Columns UI
481
- // can offer it), just with visible=false.
482
- const team = api.getColumns().find((c) => c.id === 'team')
483
- expect(team).toBeDefined()
484
- expect(team?.visible).toBe(false)
485
- // A later user toggle wins over the initial flag.
486
- api.setColumnVisible('team', true)
487
- await tick()
488
- expect(api.isColumnVisible('team')).toBe(true)
489
- } finally {
490
- destroy()
491
- }
492
- })
493
- })
494
-
495
- describe('SvGrid - row add / remove', () => {
496
- it('addRow at top / bottom / specific index', async () => {
497
- const { api, destroy } = await mountGrid()
498
- try {
499
- const before = api.getData().length
500
- api.addRow({ id: 99, name: 'Top', team: 'X', age: 20, active: true, joined: '2025', salary: 1 }, 'top')
501
- api.addRow({ id: 100, name: 'Bottom', team: 'X', age: 20, active: true, joined: '2025', salary: 1 }, 'bottom')
502
- api.addRow({ id: 101, name: 'Mid', team: 'X', age: 20, active: true, joined: '2025', salary: 1 }, 2)
503
- await tick()
504
- expect(api.getData().length).toBe(before + 3)
505
- } finally {
506
- destroy()
507
- }
508
- })
509
-
510
- it('addRows / removeRow / removeRows', async () => {
511
- const { api, destroy } = await mountGrid()
512
- try {
513
- const before = api.getData().length
514
- api.addRows(
515
- [
516
- { id: 90, name: 'A', team: 'X', age: 1, active: true, joined: '2025', salary: 1 },
517
- { id: 91, name: 'B', team: 'X', age: 1, active: true, joined: '2025', salary: 1 },
518
- ],
519
- 'bottom',
520
- )
521
- await tick()
522
- api.removeRow(0)
523
- await tick()
524
- api.removeRows([0, 1])
525
- await tick()
526
- expect(api.getData().length).toBe(before + 2 - 3)
527
- } finally {
528
- destroy()
529
- }
530
- })
531
- })
532
-
533
- describe('SvGrid - getCellValue', () => {
534
- it('returns the cell value for a known row+column', async () => {
535
- const { api, destroy } = await mountGrid()
536
- try {
537
- const value = api.getCellValue(0, 'name')
538
- expect(value).toBe(people[0]!.name)
539
- } finally {
540
- destroy()
541
- }
542
- })
543
-
544
- it('returns undefined for unknown row or column', async () => {
545
- const { api, destroy } = await mountGrid()
546
- try {
547
- expect(api.getCellValue(999, 'name')).toBeUndefined()
548
- expect(api.getCellValue(0, 'no-such-col')).toBeUndefined()
549
- } finally {
550
- destroy()
551
- }
552
- })
553
- })
554
-
555
- describe('SvGrid - row number column', () => {
556
- it('showRowNumbers renders the leading row-number column', async () => {
557
- const { target, destroy } = await mountGrid({ showRowNumbers: true })
558
- try {
559
- await tick()
560
- const rnCells = target.querySelectorAll('.sv-grid-row-number-cell')
561
- expect(rnCells.length).toBeGreaterThan(0)
562
- } finally {
563
- destroy()
564
- }
565
- })
566
- })
567
-
568
- describe('SvGrid - external sort / filter', () => {
569
- it('externalSort + onSortingChange fires without re-ordering rows', async () => {
570
- let captured: Array<{ id: string; desc: boolean }> | null = null
571
- const { api, destroy } = await mountGrid({
572
- externalSort: true,
573
- onSortingChange: (s: any) => (captured = s),
574
- })
575
- try {
576
- api.setSort('age', 'desc')
577
- await tick()
578
- expect(captured).not.toBeNull()
579
- } finally {
580
- destroy()
581
- }
582
- })
583
-
584
- it('externalFilter + onFiltersChange fires when a filter is set', async () => {
585
- let calls = 0
586
- const { api, destroy } = await mountGrid({
587
- externalFilter: true,
588
- onFiltersChange: () => {
589
- calls += 1
590
- },
591
- })
592
- try {
593
- api.setFilter('team', { operator: 'contains', value: 'Research' })
594
- await tick()
595
- expect(calls).toBeGreaterThan(0)
596
- } finally {
597
- destroy()
598
- }
599
- })
600
- })
601
-
602
- describe('SvGrid - custom snippet cell', () => {
603
- it('accepts a custom cell renderer without throwing', async () => {
604
- // Build a snippet via raw object - the SvGrid component reads
605
- // `column.columnDef.cell` and pipes it through FlexRender. Returning a
606
- // plain string is the simplest renderer; tests only need to verify the
607
- // render path doesn't crash.
608
- const customCols: ColumnDef<typeof fullFeatures, Person>[] = personColumns.map((c) =>
609
- c.field === 'name'
610
- ? {
611
- ...c,
612
- cell: (ctx: any) => `★ ${(ctx.row.original as Person).name}`,
613
- }
614
- : c,
615
- )
616
- const { target, destroy } = await mountGrid({ columns: customCols })
617
- try {
618
- await tick()
619
- expect(target.textContent).toContain('★')
620
- } finally {
621
- destroy()
622
- }
623
- })
624
- })
625
-
626
- describe('SvGrid - filterMode shortcuts', () => {
627
- it('filterMode="row" + global filter input wiring', async () => {
628
- const { destroy } = await mountGrid({ filterMode: 'row' })
629
- try {
630
- await tick()
631
- // No assertion needed - exercising the codepath is enough.
632
- expect(true).toBe(true)
633
- } finally {
634
- destroy()
635
- }
636
- })
637
- it('filterMode="global"', async () => {
638
- const { destroy } = await mountGrid({ filterMode: 'global' })
639
- try {
640
- await tick()
641
- expect(true).toBe(true)
642
- } finally {
643
- destroy()
644
- }
645
- })
646
- it('filterMode="none"', async () => {
647
- const { destroy } = await mountGrid({ filterMode: 'none' })
648
- try {
649
- await tick()
650
- expect(true).toBe(true)
651
- } finally {
652
- destroy()
653
- }
654
- })
655
- })
656
-
657
- describe('SvGrid - selectionMode shortcuts', () => {
658
- it('selectionMode="row"', async () => {
659
- const { destroy } = await mountGrid({ selectionMode: 'row' })
660
- try {
661
- await tick()
662
- expect(true).toBe(true)
663
- } finally {
664
- destroy()
665
- }
666
- })
667
- it('selectionMode="cell"', async () => {
668
- const { destroy } = await mountGrid({ selectionMode: 'cell' })
669
- try {
670
- await tick()
671
- expect(true).toBe(true)
672
- } finally {
673
- destroy()
674
- }
675
- })
676
- it('selectionMode="both"', async () => {
677
- const { destroy } = await mountGrid({ selectionMode: 'both' })
678
- try {
679
- await tick()
680
- expect(true).toBe(true)
681
- } finally {
682
- destroy()
683
- }
684
- })
685
- it('selectionMode="none"', async () => {
686
- const { destroy } = await mountGrid({ selectionMode: 'none' })
687
- try {
688
- await tick()
689
- expect(true).toBe(true)
690
- } finally {
691
- destroy()
692
- }
693
- })
694
- })
695
-
696
- describe('SvGrid - fitColumns', () => {
697
- it('mounts with fitColumns=true without throwing', async () => {
698
- const { destroy } = await mountGrid({ fitColumns: true })
699
- try {
700
- await tick()
701
- expect(true).toBe(true)
702
- } finally {
703
- destroy()
704
- }
705
- })
706
- })
1
+ /**
2
+ * Broad behavioral test suite for the <SvGrid /> render component.
3
+ *
4
+ * The intent is wide coverage on a single file - SvGrid.svelte is ~3000
5
+ * lines and most of its branches are reachable only when the component is
6
+ * mounted with a particular prop combination. Each test below exercises a
7
+ * different feature set so the whole file's effect graph is traversed.
8
+ *
9
+ * Pattern (re-used across files):
10
+ * 1. mount SvGrid in jsdom with the props that trigger the feature
11
+ * 2. wait one microtask for $effects to flush
12
+ * 3. assert on the api object delivered via onApiReady, or on visible DOM
13
+ * 4. unmount
14
+ */
15
+
16
+ import { describe, expect, it } from 'vitest'
17
+ import { mount, unmount } from 'svelte'
18
+ import SvGrid from './SvGrid.svelte'
19
+ import {
20
+ columnFilteringFeature,
21
+ columnGroupingFeature,
22
+ createCoreRowModel,
23
+ createExpandedRowModel,
24
+ createFilteredRowModel,
25
+ createGroupedRowModel,
26
+ createPaginatedRowModel,
27
+ createSortedRowModel,
28
+ renderSnippet,
29
+ rowExpandingFeature,
30
+ rowPaginationFeature,
31
+ rowSelectionFeature,
32
+ rowSortingFeature,
33
+ sortFns,
34
+ tableFeatures,
35
+ } from './index'
36
+ import type { ColumnDef, SvGridApi } from './index'
37
+
38
+ type Person = {
39
+ id: number
40
+ name: string
41
+ team: string
42
+ age: number
43
+ active: boolean
44
+ joined: string
45
+ salary: number
46
+ }
47
+
48
+ const fullFeatures = tableFeatures({
49
+ columnFilteringFeature,
50
+ columnGroupingFeature,
51
+ rowExpandingFeature,
52
+ rowPaginationFeature,
53
+ rowSelectionFeature,
54
+ rowSortingFeature,
55
+ })
56
+
57
+ const people: Person[] = [
58
+ { id: 1, name: 'Ada Lovelace', team: 'Research', age: 38, active: true, joined: '2020-01-10', salary: 142_000 },
59
+ { id: 2, name: 'Grace Hopper', team: 'Compilers', age: 42, active: true, joined: '2018-05-22', salary: 158_000 },
60
+ { id: 3, name: 'Alan Turing', team: 'Research', age: 41, active: false, joined: '2021-09-01', salary: 138_000 },
61
+ { id: 4, name: 'Margaret Hamilton', team: 'Apollo', age: 35, active: true, joined: '2019-03-15', salary: 165_000 },
62
+ { id: 5, name: 'Linus Torvalds', team: 'Kernel', age: 54, active: true, joined: '2017-11-30', salary: 175_000 },
63
+ { id: 6, name: 'Donald Knuth', team: 'Research', age: 86, active: false, joined: '2010-06-06', salary: 120_000 },
64
+ { id: 7, name: 'Brian Kernighan', team: 'Compilers', age: 80, active: true, joined: '2012-02-02', salary: 160_000 },
65
+ { id: 8, name: 'Dennis Ritchie', team: 'Kernel', age: 70, active: false, joined: '2009-07-14', salary: 110_000 },
66
+ ]
67
+
68
+ const personColumns: ColumnDef<typeof fullFeatures, Person>[] = [
69
+ { field: 'name', header: 'Name', width: 200 },
70
+ { field: 'team', header: 'Team', width: 160 },
71
+ {
72
+ field: 'age',
73
+ header: 'Age',
74
+ width: 100,
75
+ editorType: 'number',
76
+ format: { type: 'number' },
77
+ },
78
+ {
79
+ field: 'active',
80
+ header: 'Active',
81
+ width: 100,
82
+ editorType: 'checkbox',
83
+ },
84
+ {
85
+ field: 'joined',
86
+ header: 'Joined',
87
+ width: 140,
88
+ editorType: 'date',
89
+ format: { type: 'number' },
90
+ },
91
+ {
92
+ field: 'salary',
93
+ header: 'Salary',
94
+ width: 140,
95
+ editorType: 'number',
96
+ format: { type: 'currency', currency: 'USD' },
97
+ },
98
+ ]
99
+
100
+ type MountResult = {
101
+ api: SvGridApi<typeof fullFeatures, Person>
102
+ target: HTMLElement
103
+ destroy: () => void
104
+ }
105
+
106
+ function mountGrid(overrides: Record<string, unknown> = {}): Promise<MountResult> {
107
+ return new Promise((resolveApi, rejectApi) => {
108
+ const target = document.createElement('div')
109
+ target.style.width = '1200px'
110
+ target.style.height = '600px'
111
+ document.body.appendChild(target)
112
+
113
+ let capturedApi: SvGridApi<typeof fullFeatures, Person> | null = null
114
+
115
+ const app = mount(SvGrid, {
116
+ target,
117
+ props: {
118
+ data: people,
119
+ columns: personColumns,
120
+ features: fullFeatures,
121
+ _rowModels: {
122
+ coreRowModel: createCoreRowModel(),
123
+ filteredRowModel: createFilteredRowModel(),
124
+ sortedRowModel: createSortedRowModel(sortFns),
125
+ groupedRowModel: createGroupedRowModel(),
126
+ expandedRowModel: createExpandedRowModel(),
127
+ paginatedRowModel: createPaginatedRowModel(),
128
+ },
129
+ rowHeight: 36,
130
+ containerHeight: 480,
131
+ virtualization: false,
132
+ onApiReady(api: SvGridApi<typeof fullFeatures, Person>) {
133
+ capturedApi = api
134
+ resolveApi({
135
+ api,
136
+ target,
137
+ destroy: () => {
138
+ unmount(app)
139
+ target.remove()
140
+ },
141
+ })
142
+ },
143
+ ...overrides,
144
+ } as any,
145
+ })
146
+
147
+ queueMicrotask(() => {
148
+ if (!capturedApi) rejectApi(new Error('onApiReady never fired'))
149
+ })
150
+ })
151
+ }
152
+
153
+ const tick = () => Promise.resolve()
154
+
155
+ describe('SvGrid - core render', () => {
156
+ it('mounts and renders the column headers', async () => {
157
+ const { target, destroy } = await mountGrid()
158
+ try {
159
+ const headers = target.querySelectorAll('[data-svgrid-header-col]')
160
+ // jsdom reports 0 for offsetWidth so column virtualization may render
161
+ // a subset. The point of this assertion is just that the header row
162
+ // exists and is populated.
163
+ expect(headers.length).toBeGreaterThan(0)
164
+ } finally {
165
+ destroy()
166
+ }
167
+ })
168
+
169
+ it('renders the rows in the body', async () => {
170
+ const { target, destroy } = await mountGrid()
171
+ try {
172
+ await tick()
173
+ const rows = target.querySelectorAll('[data-svgrid-row]')
174
+ // Pagination defaults to off in our mount - all rows render.
175
+ expect(rows.length).toBeGreaterThanOrEqual(people.length)
176
+ } finally {
177
+ destroy()
178
+ }
179
+ })
180
+
181
+ it('renders the empty message when data is empty', async () => {
182
+ const { target, destroy } = await mountGrid({ data: [], emptyMessage: 'No rows yet' })
183
+ try {
184
+ await tick()
185
+ expect(target.textContent).toContain('No rows yet')
186
+ } finally {
187
+ destroy()
188
+ }
189
+ })
190
+
191
+ it('renders a loading state when `loading` is true', async () => {
192
+ const { target, destroy } = await mountGrid({ loading: true })
193
+ try {
194
+ await tick()
195
+ const statusEls = target.querySelectorAll('[role="status"]')
196
+ expect(statusEls.length).toBeGreaterThan(0)
197
+ } finally {
198
+ destroy()
199
+ }
200
+ })
201
+
202
+ it('renders an error state when `error` is set', async () => {
203
+ const { target, destroy } = await mountGrid({ error: 'Something broke' })
204
+ try {
205
+ await tick()
206
+ expect(target.textContent).toContain('Something broke')
207
+ } finally {
208
+ destroy()
209
+ }
210
+ })
211
+ })
212
+
213
+ describe('SvGrid - sort', () => {
214
+ it('setSort then clearSort updates filters via api', async () => {
215
+ const { api, destroy } = await mountGrid()
216
+ try {
217
+ api.setSort('name', 'asc')
218
+ await tick()
219
+ api.setSort('name', 'desc')
220
+ await tick()
221
+ api.setSort('name', null)
222
+ await tick()
223
+ api.clearSort()
224
+ await tick()
225
+ // No throw + state consistent = pass.
226
+ expect(api.getData().length).toBe(people.length)
227
+ } finally {
228
+ destroy()
229
+ }
230
+ })
231
+ })
232
+
233
+ describe('SvGrid - pagination', () => {
234
+ it('shows fewer displayed rows than total when paginated', async () => {
235
+ const { api, destroy } = await mountGrid({ showPagination: true, pageSize: 3 })
236
+ try {
237
+ await tick()
238
+ const displayed = api.getDisplayedRows()
239
+ expect(displayed.length).toBeLessThanOrEqual(3)
240
+ } finally {
241
+ destroy()
242
+ }
243
+ })
244
+ })
245
+
246
+ describe('SvGrid - global filter', () => {
247
+ it('showGlobalFilter renders the input', async () => {
248
+ const { target, destroy } = await mountGrid({ showGlobalFilter: true })
249
+ try {
250
+ await tick()
251
+ const input = target.querySelector(
252
+ '.sv-grid-global-filter input, input[type="text"]',
253
+ )
254
+ expect(input).not.toBeNull()
255
+ } finally {
256
+ destroy()
257
+ }
258
+ })
259
+ })
260
+
261
+ describe('SvGrid - column filter row', () => {
262
+ it('showColumnFilters renders the filter row inputs', async () => {
263
+ const { target, destroy } = await mountGrid({ showColumnFilters: true })
264
+ try {
265
+ await tick()
266
+ const inputs = target.querySelectorAll('.sv-grid-column-filter')
267
+ // One filter input per filterable column.
268
+ expect(inputs.length).toBeGreaterThan(0)
269
+ } finally {
270
+ destroy()
271
+ }
272
+ })
273
+ })
274
+
275
+ describe('SvGrid - inline editing', () => {
276
+ it('enables enableInlineEditing without throwing', async () => {
277
+ const { api, destroy } = await mountGrid({ enableInlineEditing: true })
278
+ try {
279
+ // setCellValue should mutate internal data.
280
+ api.setCellValue(0, 'name', 'Renamed Person')
281
+ await tick()
282
+ const data = api.getData()
283
+ expect((data[0] as Person).name).toBe('Renamed Person')
284
+ } finally {
285
+ destroy()
286
+ }
287
+ })
288
+ })
289
+
290
+ describe('SvGrid - row selection', () => {
291
+ it('showRowSelection renders the checkbox column', async () => {
292
+ const { target, destroy } = await mountGrid({ showRowSelection: true })
293
+ try {
294
+ await tick()
295
+ const checkboxes = target.querySelectorAll('.sv-grid-checkbox')
296
+ // At least the header + one per row.
297
+ expect(checkboxes.length).toBeGreaterThan(0)
298
+ } finally {
299
+ destroy()
300
+ }
301
+ })
302
+ })
303
+
304
+ describe('SvGrid - capability shortcuts', () => {
305
+ it('sortable + filterable enable sorting/filtering UI with no features prop', async () => {
306
+ const { target, destroy } = await mountGrid({
307
+ features: undefined,
308
+ sortable: true,
309
+ filterable: true,
310
+ })
311
+ try {
312
+ await tick()
313
+ // rowSortingFeature injected -> headers expose aria-sort.
314
+ expect(
315
+ target.querySelectorAll('[role="columnheader"][aria-sort]').length,
316
+ ).toBeGreaterThan(0)
317
+ // columnFilteringFeature injected -> per-column filter button renders.
318
+ expect(target.querySelector('.sv-grid-col-filter-btn')).toBeTruthy()
319
+ } finally {
320
+ destroy()
321
+ }
322
+ })
323
+
324
+ it('sortable={false} overrides a rowSortingFeature passed via features', async () => {
325
+ // The harness default `fullFeatures` includes rowSortingFeature.
326
+ const { target, destroy } = await mountGrid({ sortable: false })
327
+ try {
328
+ await tick()
329
+ expect(
330
+ target.querySelector('[role="columnheader"][aria-sort]'),
331
+ ).toBeNull()
332
+ } finally {
333
+ destroy()
334
+ }
335
+ })
336
+
337
+ it('pageable toggles the pagination footer', async () => {
338
+ const off = await mountGrid({ pageable: false })
339
+ try {
340
+ await tick()
341
+ expect(off.target.querySelector('.sv-grid-pagination')).toBeNull()
342
+ } finally {
343
+ off.destroy()
344
+ }
345
+ const on = await mountGrid({ features: undefined, pageable: true })
346
+ try {
347
+ await tick()
348
+ expect(on.target.querySelector('.sv-grid-pagination')).toBeTruthy()
349
+ } finally {
350
+ on.destroy()
351
+ }
352
+ })
353
+
354
+ it('paginationPosition mounts + gates the bottom pager', async () => {
355
+ // The top pager is gated on measurement (jsdom does not measure), so it's not
356
+ // asserted here; the visible top pager is covered by the browser/e2e check.
357
+ // This guards the mount path (a top footer rendered pre-measure used to crash).
358
+ for (const paginationPosition of ['top', 'both', 'bottom'] as const) {
359
+ const g = await mountGrid({ showPagination: true, paginationPosition })
360
+ try {
361
+ await tick()
362
+ expect(g.api).toBeTruthy()
363
+ const bottoms = [...g.target.querySelectorAll('.sv-grid-pagination')].filter((el) => !el.classList.contains('sv-grid-pagination-top'))
364
+ expect(bottoms.length).toBe(paginationPosition === 'top' ? 0 : 1) // no bottom pager when position is 'top'
365
+ } finally {
366
+ g.destroy()
367
+ }
368
+ }
369
+ })
370
+
371
+ it('pageSizeOptions is accepted by the pager', async () => {
372
+ const g = await mountGrid({ showPagination: true, pageSizeOptions: [5, 15, 45] })
373
+ try {
374
+ await tick()
375
+ expect(g.target.querySelector('.sv-grid-pagination')).toBeTruthy()
376
+ } finally {
377
+ g.destroy()
378
+ }
379
+ })
380
+
381
+ it('editable={false} blocks inline editing entry points', async () => {
382
+ const { api, target, destroy } = await mountGrid({ editable: false })
383
+ try {
384
+ await tick()
385
+ // Double-clicking a body cell must not open an editor when editing
386
+ // is disabled via the shortcut.
387
+ const cell = target.querySelector<HTMLElement>('.sv-grid-cell')
388
+ cell?.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }))
389
+ await tick()
390
+ expect(target.querySelector('.sv-grid-cell-editor')).toBeNull()
391
+ expect(api.getData().length).toBe(people.length)
392
+ } finally {
393
+ destroy()
394
+ }
395
+ })
396
+ })
397
+
398
+ describe('SvGrid - cell selection', () => {
399
+ it('enableCellSelection mounts without error', async () => {
400
+ const { api, destroy } = await mountGrid({ enableCellSelection: true })
401
+ try {
402
+ await tick()
403
+ expect(api.getData().length).toBe(people.length)
404
+ } finally {
405
+ destroy()
406
+ }
407
+ })
408
+ })
409
+
410
+ describe('SvGrid - grouping + aggregation', () => {
411
+ it('setGroupBy mounts + the codepath runs without throwing', async () => {
412
+ const { api, target, destroy } = await mountGrid({
413
+ enableRowSummaries: true,
414
+ showGroupingControls: true,
415
+ })
416
+ try {
417
+ api.setGroupBy(['team'])
418
+ await tick()
419
+ await tick()
420
+ // Sanity: the grid is still mounted and the API responsive.
421
+ const data = api.getData()
422
+ expect(data.length).toBe(people.length)
423
+ // Group rendering depends on row model + container dimensions in jsdom;
424
+ // just verify the codepath does not throw.
425
+ expect(target).toBeTruthy()
426
+ } finally {
427
+ destroy()
428
+ }
429
+ })
430
+ })
431
+
432
+ describe('SvGrid - column add / remove / visibility', () => {
433
+ it('addColumn and removeColumn round-trip', async () => {
434
+ const { api, destroy } = await mountGrid()
435
+ try {
436
+ api.addColumn({ id: 'id-col', field: 'id', header: 'ID', width: 60 } as any, 'left')
437
+ await tick()
438
+ api.addColumn(
439
+ { id: 'extra-tag', field: 'team', header: 'Extra', width: 60 } as any,
440
+ 'right',
441
+ )
442
+ await tick()
443
+ api.addColumn(
444
+ { id: 'mid-col', field: 'name', header: 'Mid', width: 60 } as any,
445
+ 1,
446
+ )
447
+ await tick()
448
+ api.removeColumn('id-col')
449
+ await tick()
450
+ // No throw means the codepath was exercised.
451
+ expect(typeof api.getData).toBe('function')
452
+ } finally {
453
+ destroy()
454
+ }
455
+ })
456
+
457
+ it('setColumnVisible toggles visibility flag', async () => {
458
+ const { api, destroy } = await mountGrid()
459
+ try {
460
+ expect(api.isColumnVisible('name')).toBe(true)
461
+ api.setColumnVisible('name', false)
462
+ await tick()
463
+ expect(api.isColumnVisible('name')).toBe(false)
464
+ api.setColumnVisible('name', true)
465
+ await tick()
466
+ expect(api.isColumnVisible('name')).toBe(true)
467
+ } finally {
468
+ destroy()
469
+ }
470
+ })
471
+
472
+ it('columns marked `visible: false` start hidden but stay listed', async () => {
473
+ const columns: ColumnDef<typeof fullFeatures, Person>[] = personColumns.map(
474
+ (c) => (c.field === 'team' ? { ...c, visible: false } : c),
475
+ )
476
+ const { api, destroy } = await mountGrid({ columns })
477
+ try {
478
+ // Starts hidden...
479
+ expect(api.isColumnVisible('team')).toBe(false)
480
+ // ...but is still listed in getColumns() (so a Choose Columns UI
481
+ // can offer it), just with visible=false.
482
+ const team = api.getColumns().find((c) => c.id === 'team')
483
+ expect(team).toBeDefined()
484
+ expect(team?.visible).toBe(false)
485
+ // A later user toggle wins over the initial flag.
486
+ api.setColumnVisible('team', true)
487
+ await tick()
488
+ expect(api.isColumnVisible('team')).toBe(true)
489
+ } finally {
490
+ destroy()
491
+ }
492
+ })
493
+ })
494
+
495
+ describe('SvGrid - row add / remove', () => {
496
+ it('addRow at top / bottom / specific index', async () => {
497
+ const { api, destroy } = await mountGrid()
498
+ try {
499
+ const before = api.getData().length
500
+ api.addRow({ id: 99, name: 'Top', team: 'X', age: 20, active: true, joined: '2025', salary: 1 }, 'top')
501
+ api.addRow({ id: 100, name: 'Bottom', team: 'X', age: 20, active: true, joined: '2025', salary: 1 }, 'bottom')
502
+ api.addRow({ id: 101, name: 'Mid', team: 'X', age: 20, active: true, joined: '2025', salary: 1 }, 2)
503
+ await tick()
504
+ expect(api.getData().length).toBe(before + 3)
505
+ } finally {
506
+ destroy()
507
+ }
508
+ })
509
+
510
+ it('addRows / removeRow / removeRows', async () => {
511
+ const { api, destroy } = await mountGrid()
512
+ try {
513
+ const before = api.getData().length
514
+ api.addRows(
515
+ [
516
+ { id: 90, name: 'A', team: 'X', age: 1, active: true, joined: '2025', salary: 1 },
517
+ { id: 91, name: 'B', team: 'X', age: 1, active: true, joined: '2025', salary: 1 },
518
+ ],
519
+ 'bottom',
520
+ )
521
+ await tick()
522
+ api.removeRow(0)
523
+ await tick()
524
+ api.removeRows([0, 1])
525
+ await tick()
526
+ expect(api.getData().length).toBe(before + 2 - 3)
527
+ } finally {
528
+ destroy()
529
+ }
530
+ })
531
+ })
532
+
533
+ describe('SvGrid - getCellValue', () => {
534
+ it('returns the cell value for a known row+column', async () => {
535
+ const { api, destroy } = await mountGrid()
536
+ try {
537
+ const value = api.getCellValue(0, 'name')
538
+ expect(value).toBe(people[0]!.name)
539
+ } finally {
540
+ destroy()
541
+ }
542
+ })
543
+
544
+ it('returns undefined for unknown row or column', async () => {
545
+ const { api, destroy } = await mountGrid()
546
+ try {
547
+ expect(api.getCellValue(999, 'name')).toBeUndefined()
548
+ expect(api.getCellValue(0, 'no-such-col')).toBeUndefined()
549
+ } finally {
550
+ destroy()
551
+ }
552
+ })
553
+ })
554
+
555
+ describe('SvGrid - row number column', () => {
556
+ it('showRowNumbers renders the leading row-number column', async () => {
557
+ const { target, destroy } = await mountGrid({ showRowNumbers: true })
558
+ try {
559
+ await tick()
560
+ const rnCells = target.querySelectorAll('.sv-grid-row-number-cell')
561
+ expect(rnCells.length).toBeGreaterThan(0)
562
+ } finally {
563
+ destroy()
564
+ }
565
+ })
566
+ })
567
+
568
+ describe('SvGrid - external sort / filter', () => {
569
+ it('externalSort + onSortingChange fires without re-ordering rows', async () => {
570
+ let captured: Array<{ id: string; desc: boolean }> | null = null
571
+ const { api, destroy } = await mountGrid({
572
+ externalSort: true,
573
+ onSortingChange: (s: any) => (captured = s),
574
+ })
575
+ try {
576
+ api.setSort('age', 'desc')
577
+ await tick()
578
+ expect(captured).not.toBeNull()
579
+ } finally {
580
+ destroy()
581
+ }
582
+ })
583
+
584
+ it('externalFilter + onFiltersChange fires when a filter is set', async () => {
585
+ let calls = 0
586
+ const { api, destroy } = await mountGrid({
587
+ externalFilter: true,
588
+ onFiltersChange: () => {
589
+ calls += 1
590
+ },
591
+ })
592
+ try {
593
+ api.setFilter('team', { operator: 'contains', value: 'Research' })
594
+ await tick()
595
+ expect(calls).toBeGreaterThan(0)
596
+ } finally {
597
+ destroy()
598
+ }
599
+ })
600
+ })
601
+
602
+ describe('SvGrid - custom snippet cell', () => {
603
+ it('accepts a custom cell renderer without throwing', async () => {
604
+ // Build a snippet via raw object - the SvGrid component reads
605
+ // `column.columnDef.cell` and pipes it through FlexRender. Returning a
606
+ // plain string is the simplest renderer; tests only need to verify the
607
+ // render path doesn't crash.
608
+ const customCols: ColumnDef<typeof fullFeatures, Person>[] = personColumns.map((c) =>
609
+ c.field === 'name'
610
+ ? {
611
+ ...c,
612
+ cell: (ctx: any) => `★ ${(ctx.row.original as Person).name}`,
613
+ }
614
+ : c,
615
+ )
616
+ const { target, destroy } = await mountGrid({ columns: customCols })
617
+ try {
618
+ await tick()
619
+ expect(target.textContent).toContain('★')
620
+ } finally {
621
+ destroy()
622
+ }
623
+ })
624
+ })
625
+
626
+ describe('SvGrid - filterMode shortcuts', () => {
627
+ it('filterMode="row" + global filter input wiring', async () => {
628
+ const { destroy } = await mountGrid({ filterMode: 'row' })
629
+ try {
630
+ await tick()
631
+ // No assertion needed - exercising the codepath is enough.
632
+ expect(true).toBe(true)
633
+ } finally {
634
+ destroy()
635
+ }
636
+ })
637
+ it('filterMode="global"', async () => {
638
+ const { destroy } = await mountGrid({ filterMode: 'global' })
639
+ try {
640
+ await tick()
641
+ expect(true).toBe(true)
642
+ } finally {
643
+ destroy()
644
+ }
645
+ })
646
+ it('filterMode="none"', async () => {
647
+ const { destroy } = await mountGrid({ filterMode: 'none' })
648
+ try {
649
+ await tick()
650
+ expect(true).toBe(true)
651
+ } finally {
652
+ destroy()
653
+ }
654
+ })
655
+ })
656
+
657
+ describe('SvGrid - selectionMode shortcuts', () => {
658
+ it('selectionMode="row"', async () => {
659
+ const { destroy } = await mountGrid({ selectionMode: 'row' })
660
+ try {
661
+ await tick()
662
+ expect(true).toBe(true)
663
+ } finally {
664
+ destroy()
665
+ }
666
+ })
667
+ it('selectionMode="cell"', async () => {
668
+ const { destroy } = await mountGrid({ selectionMode: 'cell' })
669
+ try {
670
+ await tick()
671
+ expect(true).toBe(true)
672
+ } finally {
673
+ destroy()
674
+ }
675
+ })
676
+ it('selectionMode="both"', async () => {
677
+ const { destroy } = await mountGrid({ selectionMode: 'both' })
678
+ try {
679
+ await tick()
680
+ expect(true).toBe(true)
681
+ } finally {
682
+ destroy()
683
+ }
684
+ })
685
+ it('selectionMode="none"', async () => {
686
+ const { destroy } = await mountGrid({ selectionMode: 'none' })
687
+ try {
688
+ await tick()
689
+ expect(true).toBe(true)
690
+ } finally {
691
+ destroy()
692
+ }
693
+ })
694
+ })
695
+
696
+ describe('SvGrid - fitColumns', () => {
697
+ it('mounts with fitColumns=true without throwing', async () => {
698
+ const { destroy } = await mountGrid({ fitColumns: true })
699
+ try {
700
+ await tick()
701
+ expect(true).toBe(true)
702
+ } finally {
703
+ destroy()
704
+ }
705
+ })
706
+ })