@cdc/core 4.25.7 → 4.25.10

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 (128) hide show
  1. package/components/AdvancedEditor/AdvancedEditor.tsx +29 -8
  2. package/components/DataTable/DataTable.tsx +63 -11
  3. package/components/DataTable/DataTableStandAlone.tsx +4 -1
  4. package/components/DataTable/components/ChartHeader.tsx +58 -9
  5. package/components/DataTable/components/ExpandCollapse.tsx +21 -1
  6. package/components/DataTable/components/MapHeader.tsx +35 -7
  7. package/components/DataTable/data-table.css +6 -0
  8. package/components/DataTable/helpers/chartCellMatrix.tsx +11 -8
  9. package/components/DataTable/helpers/mapCellMatrix.tsx +19 -1
  10. package/components/DownloadButton.tsx +42 -13
  11. package/components/EditorPanel/DataTableEditor.tsx +10 -1
  12. package/components/EditorPanel/components/MarkupHighlightedTextField.tsx +227 -0
  13. package/components/EditorPanel/components/MarkupVariablesEditor.tsx +411 -0
  14. package/components/EditorPanel/components/PanelMarkup.tsx +59 -0
  15. package/components/ErrorBoundary.jsx +3 -1
  16. package/components/Filters/Filters.tsx +35 -11
  17. package/components/Filters/components/Tabs.tsx +1 -0
  18. package/components/Footnotes/FootnotesStandAlone.tsx +2 -1
  19. package/components/Legend/Legend.Gradient.tsx +3 -6
  20. package/components/LegendShape.tsx +121 -3
  21. package/components/{MediaControls.jsx → MediaControls.tsx} +80 -16
  22. package/components/PaletteConversionModal.tsx +87 -0
  23. package/components/PaletteSelector/DeveloperPaletteRollback.tsx +114 -0
  24. package/components/PaletteSelector/PaletteSelector.css +51 -0
  25. package/components/PaletteSelector/PaletteSelector.tsx +112 -0
  26. package/components/PaletteSelector/index.ts +2 -0
  27. package/components/RichTooltip/RichTooltip.tsx +1 -0
  28. package/components/Table/Table.tsx +3 -1
  29. package/components/_stories/BlurStrokeTest.stories.tsx +1 -1
  30. package/components/_stories/DataTable.stories.tsx +1 -1
  31. package/components/_stories/Filters.stories.tsx +1 -1
  32. package/components/_stories/Footnotes.stories.tsx +1 -1
  33. package/components/_stories/Inputs.stories.tsx +1 -1
  34. package/components/_stories/MultiSelect.stories.tsx +3 -3
  35. package/components/_stories/NestedDropdown.stories.tsx +1 -1
  36. package/components/_stories/Table.stories.tsx +1 -1
  37. package/components/elements/_stories/Button.stories.tsx +1 -1
  38. package/components/elements/_stories/Card.stories.tsx +1 -1
  39. package/components/inputs/InputToggle.tsx +2 -0
  40. package/components/managers/DataDesigner.tsx +10 -9
  41. package/components/managers/_stories/DataDesigner.stories.tsx +1 -1
  42. package/components/ui/Tooltip.tsx +2 -1
  43. package/components/ui/_stories/Accordion.stories.tsx +1 -1
  44. package/components/ui/_stories/ColorPaletteMigration.stories.mdx +275 -0
  45. package/components/ui/_stories/Colors.stories.tsx +330 -0
  46. package/components/ui/_stories/IconGallery.stories.tsx +316 -0
  47. package/components/ui/_stories/Title.stories.tsx +1 -1
  48. package/contexts/EditorContext.ts +18 -0
  49. package/contexts/editor.actions.ts +28 -0
  50. package/contexts/editor.reducer.ts +94 -0
  51. package/data/chartColorPalettes.ts +118 -0
  52. package/data/colorPalettes.ts +9 -0
  53. package/data/mapColorPalettes.ts +45 -0
  54. package/data/sharedPalettes.ts +50 -0
  55. package/dist/cove-main.css +14 -13
  56. package/dist/cove-main.css.map +1 -1
  57. package/generateViteConfig.js +80 -0
  58. package/helpers/addValuesToFilters.ts +2 -3
  59. package/helpers/cloneConfig.ts +31 -0
  60. package/helpers/configDataHelpers.ts +128 -0
  61. package/helpers/configHelpers.ts +27 -0
  62. package/helpers/constants.ts +5 -2
  63. package/helpers/cove/number.ts +6 -2
  64. package/helpers/coveUpdateWorker.ts +15 -3
  65. package/helpers/events.ts +32 -0
  66. package/helpers/filterColorPalettes.ts +152 -0
  67. package/helpers/generateColorsArray.ts +13 -0
  68. package/helpers/getColorPaletteVersion.ts +33 -0
  69. package/helpers/getPaletteAccessor.ts +18 -0
  70. package/helpers/markupProcessor.ts +205 -0
  71. package/helpers/metrics/helpers.ts +75 -0
  72. package/helpers/metrics/types.ts +82 -0
  73. package/helpers/metrics/utils.ts +34 -0
  74. package/helpers/palettes/colorDistributions.ts +56 -0
  75. package/helpers/palettes/migratePaletteName.ts +150 -0
  76. package/helpers/palettes/standardizePaletteNames.ts +77 -0
  77. package/helpers/palettes/utils.ts +267 -0
  78. package/helpers/queryStringUtils.ts +13 -0
  79. package/helpers/testing.ts +345 -0
  80. package/helpers/tests/addValuesToFilters.test.ts +1 -2
  81. package/helpers/tests/generateColorsArray.test.ts +24 -0
  82. package/helpers/tests/markupProcessor.test.ts +538 -0
  83. package/helpers/tests/testStandaloneBuild.ts +44 -0
  84. package/helpers/useMarkupVariables.ts +31 -0
  85. package/helpers/vegaConfig.ts +0 -1
  86. package/helpers/ver/4.24.10.ts +2 -1
  87. package/helpers/ver/4.24.11.ts +2 -1
  88. package/helpers/ver/4.24.3.ts +2 -1
  89. package/helpers/ver/4.24.4.ts +2 -1
  90. package/helpers/ver/4.24.5.ts +2 -1
  91. package/helpers/ver/4.24.7.ts +2 -1
  92. package/helpers/ver/4.24.9.ts +2 -1
  93. package/helpers/ver/4.25.1.ts +2 -1
  94. package/helpers/ver/4.25.10.ts +36 -0
  95. package/helpers/ver/4.25.3.ts +2 -1
  96. package/helpers/ver/4.25.4.ts +2 -1
  97. package/helpers/ver/4.25.6.ts +2 -1
  98. package/helpers/ver/4.25.7.ts +2 -1
  99. package/helpers/ver/4.25.8.ts +62 -0
  100. package/helpers/ver/4.25.9.ts +293 -0
  101. package/helpers/ver/tests/4.25.10.test.ts +204 -0
  102. package/helpers/ver/tests/4.25.8.test.ts +86 -0
  103. package/helpers/ver/tests/4.25.9.test.ts +51 -0
  104. package/helpers/viewports.ts +2 -0
  105. package/hooks/useColorPalette.ts +79 -0
  106. package/package.json +12 -4
  107. package/styles/_button-section.scss +0 -2
  108. package/styles/_global.scss +7 -5
  109. package/styles/base.scss +8 -5
  110. package/styles/v2/components/button.scss +4 -3
  111. package/styles/v2/components/editor.scss +2 -1
  112. package/styles/v2/layout/_data-table.scss +3 -2
  113. package/styles/v2/themes/_color-definitions.scss +18 -17
  114. package/testBuild.js +0 -0
  115. package/testing-setup.js +32 -0
  116. package/types/ForecastingSeriesKey.ts +0 -1
  117. package/types/MarkupInclude.ts +6 -1
  118. package/types/MarkupVariable.ts +19 -0
  119. package/types/Series.ts +4 -0
  120. package/types/Table.ts +1 -0
  121. package/types/VizFilter.ts +1 -0
  122. package/vitest.config.ts +16 -0
  123. package/components/ui/_stories/Colors.stories.mdx +0 -220
  124. package/components/ui/_stories/IconGallery.stories.mdx +0 -14
  125. package/data/colorPalettes.js +0 -171
  126. package/helpers/events.js +0 -14
  127. package/helpers/formatConfigBeforeSave.ts +0 -135
  128. package/helpers/tests/formatConfigBeforeSave.test.ts +0 -68
@@ -0,0 +1,345 @@
1
+ import { expect, userEvent } from 'storybook/test'
2
+ import { waitFor } from '@testing-library/react'
3
+
4
+ /**
5
+ * Shared Testing Helpers for Editor Story Tests
6
+ *
7
+ * This file contains common testing utilities used across all visualization
8
+ * editor story tests (Chart, Map, Data Bite, Waffle Chart, etc.).
9
+ *
10
+ * Key Features:
11
+ * - Adaptive animation delays for test environments vs UI
12
+ * - Robust polling utilities for async state changes
13
+ * - Generic before/after assertion patterns
14
+ * - Element presence/absence waiting
15
+ * - Text content change detection
16
+ * - Editor loading and accordion interaction helpers
17
+ *
18
+ */
19
+
20
+ // ============================================================================
21
+ // ENVIRONMENT DETECTION & TIMING
22
+ // ============================================================================
23
+
24
+ /**
25
+ * Use 500ms delay for visual perception in Storybook UI, but skip in automated tests
26
+ * This ensures smooth visual feedback for manual testing while keeping automated tests fast
27
+ */
28
+ export const MIN_ANIMATION_DELAY_MS = (() => {
29
+ // Check if we're in automated test environment (Vitest/Jest)
30
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
31
+ return 0
32
+ }
33
+
34
+ // Check if we're running via test runner (Vitest has __vitest__ global)
35
+ if (typeof globalThis !== 'undefined' && '__vitest__' in globalThis) {
36
+ return 0
37
+ }
38
+
39
+ return 500
40
+ })()
41
+
42
+ const WAIT_FOR_TIMEOUT_MS = 5000
43
+
44
+ // ============================================================================
45
+ // CORE POLLING UTILITIES
46
+ // ============================================================================
47
+
48
+ // Wrapper for waitFor that includes explicit animation delay
49
+ const waitForWithDelay = async (predicate: () => void, options?: { timeout?: number }) => {
50
+ if (MIN_ANIMATION_DELAY_MS > 0) {
51
+ await new Promise(resolve => setTimeout(resolve, MIN_ANIMATION_DELAY_MS))
52
+ }
53
+
54
+ await waitFor(predicate, {
55
+ timeout: options?.timeout || WAIT_FOR_TIMEOUT_MS
56
+ })
57
+ }
58
+
59
+ /**
60
+ * Perform an action and assert the result using polling
61
+ * This is the core pattern for testing state changes in editor components
62
+ *
63
+ * @param label Descriptive label for the test action
64
+ * @param read Function that reads the current state
65
+ * @param act Function that performs the action
66
+ * @param predicate Function that validates the state change
67
+ * @param extraAssert Optional additional assertion on the final value
68
+ */
69
+ export const performAndAssert = async <T extends unknown>(
70
+ label: string,
71
+ read: () => T,
72
+ act: () => Promise<void> | void,
73
+ predicate: (before: T, after: T) => boolean,
74
+ extraAssert?: (after: T) => void
75
+ ): Promise<void> => {
76
+ // Capture the call site stack trace
77
+ const callSite = new Error().stack
78
+
79
+ const before = read()
80
+ await act()
81
+
82
+ await waitForWithDelay(() => {
83
+ const after = read()
84
+ const result = predicate(before, after)
85
+ if (!result) {
86
+ // Create a more informative error with the original call site
87
+ const error = new Error(
88
+ `${label} failed: Expected predicate to return true. Before: ${JSON.stringify(before)}, After: ${JSON.stringify(
89
+ after
90
+ )}`
91
+ )
92
+
93
+ // Try to preserve the original call site in the stack trace
94
+ if (callSite) {
95
+ const originalStack = callSite.split('\n')
96
+ // Replace the generic helper stack with the original call site
97
+ if (originalStack.length > 2) {
98
+ error.stack = [
99
+ error.message,
100
+ ...originalStack.slice(2) // Skip the first two lines (error creation in helper)
101
+ ].join('\n')
102
+ }
103
+ }
104
+
105
+ throw error
106
+ }
107
+ if (extraAssert) extraAssert(after)
108
+ })
109
+ }
110
+
111
+ // ============================================================================
112
+ // ELEMENT WAITING UTILITIES
113
+ // ============================================================================
114
+
115
+ /**
116
+ * Wait for an element to appear in the DOM
117
+ *
118
+ * @param selector CSS selector for the element
119
+ * @param canvasElement Container element to search within
120
+ * @returns Promise that resolves to the found element
121
+ */
122
+ export const waitForPresence = async (selector: string, canvasElement: HTMLElement) => {
123
+ await waitForWithDelay(() => {
124
+ const element = canvasElement.querySelector(selector)
125
+ expect(element).toBeTruthy()
126
+ })
127
+ return canvasElement.querySelector(selector)
128
+ }
129
+
130
+ /**
131
+ * Wait for an element to disappear from the DOM
132
+ *
133
+ * @param selector CSS selector for the element
134
+ * @param canvasElement Container element to search within
135
+ */
136
+ export const waitForAbsence = async (selector: string, canvasElement: HTMLElement) => {
137
+ await waitForWithDelay(() => {
138
+ const element = canvasElement.querySelector(selector)
139
+ expect(element).toBeFalsy()
140
+ })
141
+ }
142
+
143
+ /**
144
+ * Wait for a select element's options to populate
145
+ *
146
+ * @param selectElement The select element to monitor
147
+ * @param minCount The minimum number of expected elements
148
+ */
149
+ export const waitForOptionsToPopulate = async (selectElement: HTMLSelectElement, minCount: number = 2) => {
150
+ await waitForWithDelay(() => {
151
+ expect(selectElement.options.length).toBeGreaterThanOrEqual(minCount)
152
+ })
153
+ }
154
+
155
+ /**
156
+ * Wait for an element's text content to change to a specific value
157
+ *
158
+ * @param el The element to monitor
159
+ * @param expected The expected text content
160
+ */
161
+ export const waitForTextContent = async (el: HTMLElement | null, expected: string) => {
162
+ expect(el).toBeTruthy()
163
+ await waitForWithDelay(() => {
164
+ expect(el!.textContent?.trim()).toBe(expected.trim())
165
+ })
166
+ }
167
+
168
+ // ============================================================================
169
+ // EDITOR-SPECIFIC UTILITIES
170
+ // ============================================================================
171
+
172
+ /**
173
+ * Wait for the editor to load and become interactive
174
+ * This ensures all accordion sections are present and the component is ready for testing
175
+ *
176
+ * @param canvas Storybook canvas object from within(canvasElement)
177
+ */
178
+ export const waitForEditor = async (canvas: any) => {
179
+ await waitForWithDelay(() => {
180
+ const editorElement = canvas.queryAllByText(/general|data|visual/i)
181
+ expect(editorElement[0]).toBeVisible()
182
+ })
183
+ }
184
+
185
+ /**
186
+ * Open an accordion section in the editor
187
+ *
188
+ * @param canvas Storybook canvas object from within(canvasElement)
189
+ * @param sectionName Name of the accordion section (case-insensitive)
190
+ */
191
+ export const openAccordion = async (canvas: any, sectionName: string) => {
192
+ const accordion = canvas.getByRole('button', { name: new RegExp(sectionName, 'i') })
193
+ await userEvent.click(accordion)
194
+ await waitForWithDelay(() => {
195
+ const accordionContent = accordion.closest('.accordion-item, .accordion-section, [class*="accordion"]')
196
+ expect(accordionContent).toBeTruthy()
197
+ })
198
+ }
199
+
200
+ // ============================================================================
201
+ // VISUAL STATE HELPERS
202
+ // ============================================================================
203
+
204
+ /**
205
+ * Get visual state for boolean/checkbox testing
206
+ * This is a flexible helper that can be customized for different visual properties
207
+ *
208
+ * @param element The element to analyze
209
+ * @param options Configuration for what visual properties to check
210
+ * @returns Object containing the visual state
211
+ */
212
+ export const getVisualState = (
213
+ element: HTMLElement | null,
214
+ options: {
215
+ checkClasses?: string[] // CSS classes to check for presence
216
+ checkStyles?: string[] // CSS properties to read from computed styles
217
+ checkAttributes?: string[] // HTML attributes to read
218
+ customChecks?: ((el: HTMLElement) => Record<string, any>)[] // Custom visual checks
219
+ } = {}
220
+ ) => {
221
+ if (!element) return null
222
+
223
+ const state: Record<string, any> = {}
224
+
225
+ // Check for specific CSS classes
226
+ if (options.checkClasses) {
227
+ for (const className of options.checkClasses) {
228
+ state[`has_${className.replace(/[^a-zA-Z0-9]/g, '_')}`] = element.classList.contains(className)
229
+ }
230
+ }
231
+
232
+ // Check computed styles
233
+ if (options.checkStyles) {
234
+ const computedStyle = getComputedStyle(element)
235
+ for (const property of options.checkStyles) {
236
+ state[`style_${property.replace(/[^a-zA-Z0-9]/g, '_')}`] = computedStyle.getPropertyValue(property)
237
+ }
238
+ }
239
+
240
+ // Check attributes
241
+ if (options.checkAttributes) {
242
+ for (const attr of options.checkAttributes) {
243
+ state[`attr_${attr.replace(/[^a-zA-Z0-9]/g, '_')}`] = element.getAttribute(attr)
244
+ }
245
+ }
246
+
247
+ // Run custom checks
248
+ if (options.customChecks) {
249
+ for (const customCheck of options.customChecks) {
250
+ Object.assign(state, customCheck(element))
251
+ }
252
+ }
253
+
254
+ // Always include basic visibility state
255
+ state.isVisible = element.offsetParent !== null
256
+ state.classList = Array.from(element.classList).sort().join(' ')
257
+
258
+ return state
259
+ }
260
+
261
+ /**
262
+ * Create a comprehensive boolean testing function for checkbox controls
263
+ * Tests both enable/disable directions and verifies visual changes
264
+ *
265
+ * @param checkbox The checkbox element to test
266
+ * @param getVisualState Function that returns the current visual state
267
+ * @param testName Descriptive name for the test
268
+ */
269
+ export const testBooleanControl = async (checkbox: HTMLInputElement, getVisualState: () => any, testName: string) => {
270
+ // Get initial state
271
+ const initialCheckboxState = checkbox.checked
272
+ const initialVisualState = getVisualState()
273
+
274
+ // First toggle: change to opposite state
275
+ await userEvent.click(checkbox)
276
+ await new Promise(resolve => setTimeout(resolve, 100))
277
+ const firstToggleCheckboxState = checkbox.checked
278
+ const firstToggleVisualState = getVisualState()
279
+
280
+ // Verify checkbox changed
281
+ expect(firstToggleCheckboxState).not.toBe(initialCheckboxState)
282
+
283
+ // Verify visualization changed (with flexible handling)
284
+ if (JSON.stringify(firstToggleVisualState) === JSON.stringify(initialVisualState)) {
285
+ // Note: This warns but doesn't fail, allowing for controls that may not have
286
+ // visible effects under current data/settings
287
+ console.warn(`⚠️ ${testName}: Checkbox toggled but no visual change detected`)
288
+ } else {
289
+ expect(firstToggleVisualState).not.toEqual(initialVisualState)
290
+ }
291
+
292
+ // Second toggle: return to original state
293
+ await userEvent.click(checkbox)
294
+ await new Promise(resolve => setTimeout(resolve, 100))
295
+ const secondToggleCheckboxState = checkbox.checked
296
+ const secondToggleVisualState = getVisualState()
297
+
298
+ // Verify both checkbox AND visualization returned to original
299
+ expect(secondToggleCheckboxState).toBe(initialCheckboxState)
300
+ expect(secondToggleVisualState).toEqual(initialVisualState)
301
+ }
302
+
303
+ // ============================================================================
304
+ // DATA EXTRACTION HELPERS
305
+ // ============================================================================
306
+
307
+ /**
308
+ * Get the primary data value displayed in a visualization
309
+ * Tries multiple common selectors for data values
310
+ *
311
+ * @param canvasElement The container element to search within
312
+ * @returns The data value as a string, or empty string if not found
313
+ */
314
+ export const getDisplayValue = (canvasElement: HTMLElement): string => {
315
+ const selectors = ['svg text', '.bite-text', '.data-value', '[data-testid="data-value"]']
316
+
317
+ for (const selector of selectors) {
318
+ const elements = canvasElement.querySelectorAll(selector)
319
+ for (let i = 0; i < elements.length; i++) {
320
+ const element = elements[i]
321
+ const text = element.textContent?.trim()
322
+ if (text && /[\d,]+/.test(text)) {
323
+ return text
324
+ }
325
+ }
326
+ }
327
+
328
+ return ''
329
+ }
330
+
331
+ /**
332
+ * Get the title text from a visualization
333
+ * Tries multiple common selectors for titles
334
+ *
335
+ * @param canvas Storybook canvas object from within(canvasElement)
336
+ * @returns The title text as a string, or empty string if not found
337
+ */
338
+ export const getTitleText = (canvas: any): string => {
339
+ try {
340
+ const titleElement = canvas.getByRole('heading') || canvas.querySelector('h1, h2, h3, .title')
341
+ return titleElement?.textContent?.trim() || ''
342
+ } catch {
343
+ return ''
344
+ }
345
+ }
@@ -2,7 +2,6 @@ import _ from 'lodash'
2
2
  import { VizFilter } from '../../types/VizFilter'
3
3
  import { addValuesToFilters } from '../addValuesToFilters'
4
4
  import { describe, it, expect, vi } from 'vitest'
5
- import { FILTER_STYLE } from '@cdc/dashboard/src/types/FilterStyles'
6
5
 
7
6
  describe('addValuesToFilters', () => {
8
7
  const parentFilter = { columnName: 'parentColumn', id: 11, active: 'apple', values: [] } as VizFilter
@@ -52,7 +51,7 @@ describe('addValuesToFilters', () => {
52
51
  it('works for nested dropdowns', () => {
53
52
  const nestedParentFilter = {
54
53
  ...parentFilter,
55
- filterStyle: FILTER_STYLE.nestedDropdown,
54
+ filterStyle: 'nested-dropdown',
56
55
  subGrouping: { columnName: 'childColumn' }
57
56
  }
58
57
  const newFilters = addValuesToFilters([nestedParentFilter], data)
@@ -0,0 +1,24 @@
1
+ import { generateColorsArray } from '../generateColorsArray'
2
+ import { describe, it, expect } from 'vitest'
3
+
4
+ describe('generateColorsArray', () => {
5
+ it('should return an array of colors', () => {
6
+ const colors = generateColorsArray('#fde0dd', false)
7
+ expect(colors).toEqual(expect.arrayContaining(['#fde0dd', '#ffd0c9', '#edd1ce']))
8
+ })
9
+
10
+ it('should return a brighter hover color when special flag is true', () => {
11
+ const colors = generateColorsArray('#fde0dd', true)
12
+ expect(colors[1]).toEqual('#fffaf7')
13
+ })
14
+
15
+ it('should return a darker color for the third element in the array', () => {
16
+ const colors = generateColorsArray('#fde0dd', false)
17
+ expect(colors[2]).toBe('#edd1ce')
18
+ })
19
+
20
+ it('should use black as default color', () => {
21
+ const colors = generateColorsArray()
22
+ expect(colors[0]).toBe('#000000')
23
+ })
24
+ })