@cdc/core 4.25.11 → 4.26.2

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 (147) hide show
  1. package/.claude/agents/qa-test-developer.md +126 -0
  2. package/CLAUDE.local.md +67 -0
  3. package/_stories/Gallery.Charts.stories.tsx +300 -0
  4. package/_stories/Gallery.DataBite.stories.tsx +79 -0
  5. package/_stories/Gallery.Maps.stories.tsx +239 -0
  6. package/_stories/Gallery.WaffleChart.stories.tsx +187 -0
  7. package/_stories/PageART.stories.tsx +193 -0
  8. package/_stories/PageBRFSS.stories.tsx +294 -0
  9. package/_stories/PageCancerRegistries.stories.tsx +199 -0
  10. package/_stories/PageEasternEquineEncephalitis.stories.tsx +216 -0
  11. package/_stories/PageExcessiveAlcoholUse.stories.tsx +201 -0
  12. package/_stories/PageMaternalMortality.stories.tsx +193 -0
  13. package/_stories/PageOralHealth.stories.tsx +201 -0
  14. package/_stories/PageRespiratory.stories.tsx +332 -0
  15. package/_stories/PageSmokingTobacco.stories.tsx +200 -0
  16. package/_stories/PageStateDiabetesProfiles.stories.tsx +201 -0
  17. package/_stories/PageWastewater.stories.tsx +477 -0
  18. package/_stories/VegaImport.stories.tsx +401 -0
  19. package/_stories/vega-fixtures/bars-with-line.json +444 -0
  20. package/_stories/vega-fixtures/bars.json +58 -0
  21. package/_stories/vega-fixtures/combo-bar-rolling-mean.json +88 -0
  22. package/_stories/vega-fixtures/combo.json +68 -0
  23. package/_stories/vega-fixtures/grouped-horizontal-bars.json +83 -0
  24. package/_stories/vega-fixtures/grouped-horizontal-bars2.json +231 -0
  25. package/_stories/vega-fixtures/horizontal-bar.json +427 -0
  26. package/_stories/vega-fixtures/horizontal-bars-with-bad-colors.json +197 -0
  27. package/_stories/vega-fixtures/horizontal-bars2.json +58 -0
  28. package/_stories/vega-fixtures/lines.json +227 -0
  29. package/_stories/vega-fixtures/measles-bars.json +348 -0
  30. package/_stories/vega-fixtures/measles-map.json +11101 -0
  31. package/_stories/vega-fixtures/measles-stacked-bars.json +2147 -0
  32. package/_stories/vega-fixtures/multi-dataset.json +255 -0
  33. package/_stories/vega-fixtures/no-data.json +14 -0
  34. package/_stories/vega-fixtures/pie-chart.json +94 -0
  35. package/_stories/vega-fixtures/repeat-spec.json +47 -0
  36. package/_stories/vega-fixtures/stacked-area.json +222 -0
  37. package/_stories/vega-fixtures/stacked-bar-with-rect.json +3412 -0
  38. package/_stories/vega-fixtures/stacked-bars-with-line.json +364 -0
  39. package/_stories/vega-fixtures/stacked-bars.json +212 -0
  40. package/_stories/vega-fixtures/stacked-horizontal-bars.json +140 -0
  41. package/_stories/vega-fixtures/warning-combo.json +59 -0
  42. package/_stories/vega-fixtures/warning-scatter-and-line.json +1182 -0
  43. package/assets/icon-chart-area.svg +1 -0
  44. package/assets/icon-chart-radar.svg +23 -0
  45. package/assets/icon-magnifying-glass.svg +5 -0
  46. package/assets/icon-warming-stripes.svg +13 -0
  47. package/assets/logo2.svg +31 -0
  48. package/components/AdvancedEditor/AdvancedEditor.tsx +4 -0
  49. package/components/AdvancedEditor/EmbedEditor.tsx +513 -0
  50. package/components/ComboBox/ComboBox.tsx +345 -0
  51. package/components/ComboBox/combobox.styles.css +185 -0
  52. package/components/ComboBox/index.ts +1 -0
  53. package/components/CustomColorsEditor/CustomColorsEditor.tsx +3 -10
  54. package/components/DataTable/DataTable.tsx +132 -58
  55. package/components/DataTable/data-table.css +216 -215
  56. package/components/DataTable/helpers/getSeriesName.ts +6 -0
  57. package/components/DataTable/helpers/mapCellMatrix.tsx +14 -6
  58. package/components/EditorPanel/ColumnsEditor.tsx +37 -19
  59. package/components/EditorPanel/DataTableEditor.tsx +51 -25
  60. package/components/EditorPanel/EditorPanel.styles.css +16 -0
  61. package/components/EditorPanel/EditorPanel.tsx +144 -0
  62. package/components/EditorPanel/EditorPanelDispatch.tsx +75 -0
  63. package/components/EditorPanel/FieldSetWrapper.tsx +66 -23
  64. package/components/EditorPanel/Inputs.tsx +33 -7
  65. package/components/EditorPanel/VizFilterEditor/NestedDropdownEditor.tsx +14 -6
  66. package/components/EditorPanel/VizFilterEditor/VizFilterEditor.tsx +240 -175
  67. package/components/EditorPanel/VizFilterEditor/components/FilterOrder.tsx +33 -29
  68. package/components/EditorPanel/sections/VisualSection.tsx +169 -0
  69. package/components/Filters/Filters.tsx +31 -5
  70. package/components/Filters/helpers/getNestedOptions.ts +2 -1
  71. package/components/Filters/helpers/handleSorting.ts +1 -1
  72. package/components/Layout/components/Sidebar/components/sidebar.styles.scss +84 -2
  73. package/components/Layout/components/Visualization/index.tsx +27 -1
  74. package/components/Layout/components/Visualization/visualizations.scss +7 -0
  75. package/components/Legend/Legend.Gradient.tsx +1 -1
  76. package/components/MediaControls.tsx +53 -28
  77. package/components/_stories/CustomColorsEditor.stories.tsx +37 -0
  78. package/components/_stories/DataTable.stories.tsx +1 -0
  79. package/components/ui/Icon.tsx +3 -1
  80. package/components/ui/Title/index.tsx +30 -2
  81. package/components/ui/Title/title.styles.css +42 -0
  82. package/data/colorPalettes.ts +18 -5
  83. package/data/mapColorPalettes.ts +10 -0
  84. package/devTemplate/dev.js +235 -0
  85. package/devTemplate/index.html +30 -0
  86. package/devTemplate/preview.html +1503 -0
  87. package/devTemplate/sidebar.css +151 -0
  88. package/dist/cove-main.css +2803 -4448
  89. package/dist/cove-main.css.map +1 -1
  90. package/generateViteConfig.js +118 -2
  91. package/helpers/DataTransform.ts +1 -5
  92. package/helpers/addValuesToFilters.ts +6 -1
  93. package/helpers/cove/date.ts +33 -1
  94. package/helpers/cove/string.ts +29 -0
  95. package/helpers/coveUpdateWorker.ts +21 -12
  96. package/helpers/embed/embedCodeGenerator.ts +80 -0
  97. package/helpers/embed/embedHelper.js +158 -0
  98. package/helpers/embed/filterUtils.ts +121 -0
  99. package/helpers/embed/index.ts +21 -0
  100. package/helpers/embed/urlValidation.ts +119 -0
  101. package/helpers/filterVizData.ts +6 -1
  102. package/helpers/getFileExtension.ts +0 -6
  103. package/helpers/getUniqueValues.ts +19 -0
  104. package/helpers/hashObj.ts +25 -0
  105. package/helpers/isRightAlignedTableValue.js +5 -0
  106. package/helpers/metrics/helpers.ts +1 -0
  107. package/helpers/metrics/types.ts +3 -0
  108. package/helpers/palettes/colorDistributions.ts +1 -1
  109. package/helpers/palettes/utils.ts +12 -12
  110. package/helpers/parseCsvWithQuotes.ts +15 -14
  111. package/helpers/pivotData.ts +2 -2
  112. package/helpers/prepareScreenshot.ts +288 -0
  113. package/helpers/queryStringUtils.ts +29 -0
  114. package/helpers/testing.ts +44 -0
  115. package/helpers/tests/DataTransform.test.ts +125 -0
  116. package/helpers/tests/date.test.ts +64 -0
  117. package/helpers/tests/prepareScreenshot.test.ts +414 -0
  118. package/helpers/tests/queryStringUtils.test.ts +381 -0
  119. package/helpers/tests/testStandaloneBuild.ts +23 -5
  120. package/helpers/useDataVizClasses.ts +0 -1
  121. package/helpers/vegaConfig.ts +1 -1
  122. package/helpers/vegaConfigImport.ts +160 -0
  123. package/helpers/ver/4.26.1.ts +80 -0
  124. package/helpers/ver/4.26.2.ts +84 -0
  125. package/helpers/ver/tests/4.26.1.test.ts +105 -0
  126. package/helpers/ver/tests/4.26.2.test.ts +298 -0
  127. package/helpers/viewports.ts +2 -0
  128. package/hooks/useDataColumns.ts +63 -0
  129. package/hooks/useFilterManagement.ts +94 -0
  130. package/hooks/useLegendSeparators.ts +26 -0
  131. package/hooks/useListManagement.ts +192 -0
  132. package/package.json +29 -33
  133. package/styles/_button-section.scss +0 -3
  134. package/styles/v2/components/editor.scss +9 -9
  135. package/styles/v2/utils/_grid.scss +8 -3
  136. package/types/Annotation.ts +10 -11
  137. package/types/Axis.ts +1 -0
  138. package/types/ForecastingSeriesKey.ts +1 -0
  139. package/types/General.ts +2 -0
  140. package/types/MarkupInclude.ts +1 -0
  141. package/types/Palette.ts +21 -0
  142. package/types/Series.ts +3 -0
  143. package/types/Table.ts +1 -0
  144. package/types/Visualization.ts +7 -0
  145. package/types/VizFilter.ts +1 -0
  146. package/LICENSE +0 -201
  147. package/_stories/StoryRenderingTests.stories.tsx +0 -164
@@ -0,0 +1,216 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { within, expect } from 'storybook/test'
3
+ import Chart from '@cdc/chart'
4
+ import CdcMap from '@cdc/map'
5
+ import Dashboard from '@cdc/dashboard'
6
+
7
+ // Fallback step function for test descriptions
8
+ const step = async (description: string, fn: () => Promise<void> | void) => {
9
+ console.log(`▶ ${description}`)
10
+ await fn()
11
+ console.log(`✓ ${description}`)
12
+ }
13
+
14
+ const meta: Meta = {
15
+ title: 'Regression Tests/Pages/Eastern Equine Encephalitis',
16
+ parameters: {
17
+ layout: 'fullscreen',
18
+ docs: {
19
+ description: {
20
+ component: 'Stories for all visualizations from the CDC Eastern Equine Encephalitis historic data page'
21
+ }
22
+ }
23
+ },
24
+ tags: ['autodocs']
25
+ }
26
+
27
+ export default meta
28
+
29
+ // Config URLs from the EEE historic data page
30
+ const CONFIG_URLS = {
31
+ cumulativeData: 'https://www.cdc.gov/eastern-equine-encephalitis/data-maps/cumulative-data_1.json',
32
+ exploreHumanData: 'https://www.cdc.gov/eastern-equine-encephalitis/data-maps/explore-human-data.json',
33
+ exploreCountyData: 'https://www.cdc.gov/eastern-equine-encephalitis/data-maps/explore-county-data.json',
34
+ ct2022: 'https://www.cdc.gov/eastern-equine-encephalitis/data-maps/ct-2022.json'
35
+ }
36
+
37
+ type MapStory = StoryObj<typeof CdcMap>
38
+ type DashboardStory = StoryObj<typeof Dashboard>
39
+
40
+ // Helper function to test map rendering (supports both SVG and canvas-based maps)
41
+ const testMapRendering = async (canvasElement: HTMLElement, storyName: string) => {
42
+ await step('Wait for map to render', async () => {
43
+ await new Promise<void>((resolve, reject) => {
44
+ const startTime = Date.now()
45
+ const timeout = 15000
46
+
47
+ const checkMap = () => {
48
+ const svgMap = canvasElement.querySelector('svg[role="img"]')
49
+ const canvasMap = canvasElement.querySelector('canvas')
50
+ if (svgMap || canvasMap) {
51
+ resolve()
52
+ } else if (Date.now() - startTime > timeout) {
53
+ reject(new Error(`Timeout: No map element (svg or canvas) found after ${timeout}ms`))
54
+ } else {
55
+ setTimeout(checkMap, 100)
56
+ }
57
+ }
58
+ checkMap()
59
+ })
60
+ })
61
+
62
+ await step('Verify map visualization is present', async () => {
63
+ const svgMap = canvasElement.querySelector('svg[role="img"]')
64
+ const canvasMap = canvasElement.querySelector('canvas')
65
+ expect(svgMap || canvasMap).toBeTruthy()
66
+ })
67
+
68
+ await step('Verify COVE module wrapper is present', async () => {
69
+ const coveModule = canvasElement.querySelector('.cdc-open-viz-module')
70
+ expect(coveModule).toBeInTheDocument()
71
+ })
72
+
73
+ console.log(`✅ ${storyName} map rendered successfully`)
74
+ }
75
+
76
+ // Helper function to test dashboard rendering
77
+ const testDashboardRendering = async (canvasElement: HTMLElement, storyName: string) => {
78
+ await step('Wait for dashboard to render', async () => {
79
+ await new Promise<void>((resolve, reject) => {
80
+ const startTime = Date.now()
81
+ const timeout = 15000
82
+
83
+ const checkDashboard = () => {
84
+ const dashboardElement = canvasElement.querySelector('.type-dashboard')
85
+ if (dashboardElement) {
86
+ resolve()
87
+ } else if (Date.now() - startTime > timeout) {
88
+ reject(new Error(`Timeout: Dashboard element not found after ${timeout}ms`))
89
+ } else {
90
+ setTimeout(checkDashboard, 100)
91
+ }
92
+ }
93
+ checkDashboard()
94
+ })
95
+ })
96
+
97
+ await step('Verify dashboard wrapper is present', async () => {
98
+ const dashboard = canvasElement.querySelector('.type-dashboard')
99
+ expect(dashboard).toBeInTheDocument()
100
+ })
101
+
102
+ console.log(`✅ ${storyName} dashboard rendered successfully`)
103
+ }
104
+
105
+ /**
106
+ * Cumulative Data for 2003–2024
107
+ *
108
+ * Summary dashboard showing cumulative Eastern Equine Encephalitis cases.
109
+ */
110
+ export const Cumulative_Data: DashboardStory = {
111
+ render: () => <Dashboard configUrl={CONFIG_URLS.cumulativeData} />,
112
+ play: async ({ canvasElement }) => {
113
+ await testDashboardRendering(canvasElement, 'Cumulative Data')
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Explore Human Data for 2003–2024
119
+ *
120
+ * Interactive dashboard allowing exploration of human EEE cases with filters.
121
+ * Note: May experience slow load times after selecting filters.
122
+ */
123
+ export const Explore_Human_Data: DashboardStory = {
124
+ render: () => <Dashboard configUrl={CONFIG_URLS.exploreHumanData} />,
125
+ play: async ({ canvasElement }) => {
126
+ await testDashboardRendering(canvasElement, 'Explore Human Data')
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Explore County Level Data for 2003–2024
132
+ *
133
+ * Interactive map showing county-level EEE data across the United States.
134
+ */
135
+ export const Explore_County_Data: MapStory = {
136
+ render: () => <CdcMap configUrl={CONFIG_URLS.exploreCountyData} />,
137
+ play: async ({ canvasElement }) => {
138
+ await testMapRendering(canvasElement, 'Explore County Data')
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Connecticut 2022 Data
144
+ *
145
+ * Map visualization showing EEE data specific to Connecticut for 2022.
146
+ */
147
+ export const Connecticut_2022: MapStory = {
148
+ render: () => <CdcMap configUrl={CONFIG_URLS.ct2022} />,
149
+ play: async ({ canvasElement }) => {
150
+ await testMapRendering(canvasElement, 'Connecticut 2022')
151
+ }
152
+ }
153
+
154
+ /**
155
+ * All EEE Visualizations - Combined Test
156
+ *
157
+ * Tests all visualizations from the Eastern Equine Encephalitis historic data page.
158
+ */
159
+ export const All_EEE_Visualizations: StoryObj = {
160
+ render: () => (
161
+ <div className='container-fluid p-4'>
162
+ <h1 className='mb-4'>Eastern Equine Encephalitis - Historic Data</h1>
163
+
164
+ <section className='mb-5'>
165
+ <h2>Cumulative Data for 2003–2024</h2>
166
+ <Dashboard configUrl={CONFIG_URLS.cumulativeData} />
167
+ </section>
168
+
169
+ <section className='mb-5'>
170
+ <h2>Explore Human Data for 2003–2024</h2>
171
+ <Dashboard configUrl={CONFIG_URLS.exploreHumanData} />
172
+ </section>
173
+
174
+ <section className='mb-5'>
175
+ <h2>Explore County Level Data for 2003–2024</h2>
176
+ <CdcMap configUrl={CONFIG_URLS.exploreCountyData} />
177
+ </section>
178
+
179
+ <section className='mb-5'>
180
+ <h2>Connecticut 2022 Data</h2>
181
+ <CdcMap configUrl={CONFIG_URLS.ct2022} />
182
+ </section>
183
+ </div>
184
+ ),
185
+ play: async ({ canvasElement }) => {
186
+ await step('Wait for all visualizations to start rendering', async () => {
187
+ await new Promise<void>(resolve => setTimeout(resolve, 2000))
188
+ })
189
+
190
+ await step('Wait for all 4 COVE modules to render', async () => {
191
+ await new Promise<void>((resolve, reject) => {
192
+ const startTime = Date.now()
193
+ const timeout = 30000
194
+
195
+ const checkModules = () => {
196
+ const coveModules = canvasElement.querySelectorAll('.cdc-open-viz-module')
197
+ if (coveModules.length >= 4) {
198
+ resolve()
199
+ } else if (Date.now() - startTime > timeout) {
200
+ reject(new Error(`Timeout: Only ${coveModules.length}/4 COVE modules found after ${timeout}ms`))
201
+ } else {
202
+ setTimeout(checkModules, 200)
203
+ }
204
+ }
205
+ checkModules()
206
+ })
207
+ })
208
+
209
+ await step('Verify at least 4 visualizations are present', async () => {
210
+ const coveModules = canvasElement.querySelectorAll('.cdc-open-viz-module')
211
+ expect(coveModules.length).toBeGreaterThanOrEqual(4)
212
+ })
213
+
214
+ console.log(`✅ All 4+ EEE visualizations rendered successfully`)
215
+ }
216
+ }
@@ -0,0 +1,201 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { within, expect } from 'storybook/test'
3
+ import Dashboard from '@cdc/dashboard'
4
+ import { useEffect, useState } from 'react'
5
+
6
+ // Fallback step function for test descriptions
7
+ const step = async (description: string, fn: () => Promise<void> | void) => {
8
+ console.log(`▶ ${description}`)
9
+ await fn()
10
+ console.log(`✓ ${description}`)
11
+ }
12
+
13
+ const meta: Meta = {
14
+ title: 'Regression Tests/Pages/Excessive Alcohol Use',
15
+ parameters: {
16
+ layout: 'fullscreen',
17
+ docs: {
18
+ description: {
19
+ component:
20
+ 'Stories for visualizations from the CDC Excessive Alcohol Use page (https://www.cdc.gov/alcohol/fact-sheets/states/excessive-alcohol-use-united-states.html)'
21
+ }
22
+ }
23
+ },
24
+ tags: ['autodocs']
25
+ }
26
+
27
+ export default meta
28
+
29
+ // Config URL from the excessive alcohol use page
30
+ const CONFIG_URLS = {
31
+ excessiveAlcoholUse: 'https://www.cdc.gov/alcohol/fact-sheets/states/alcohol-data-for-50-states.json'
32
+ }
33
+
34
+ // Helper to fetch config and update data URLs to use absolute cdc.gov paths
35
+ const useConfigWithAbsoluteDataUrl = (configUrl: string) => {
36
+ const [config, setConfig] = useState(null)
37
+
38
+ useEffect(() => {
39
+ fetch(configUrl)
40
+ .then(res => res.json())
41
+ .then(data => {
42
+ // Convert relative data URLs to absolute cdc.gov URLs
43
+ if (data.dataUrl) {
44
+ // Handle different relative path formats (../../path or /path)
45
+ const dataUrl = data.dataUrl.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
46
+ data.dataUrl = `https://www.cdc.gov/${dataUrl}`
47
+ }
48
+ if (data.dataFileName) {
49
+ const dataFileName = data.dataFileName.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
50
+ data.dataFileName = `https://www.cdc.gov/${dataFileName}`
51
+ }
52
+
53
+ // For dashboard configs with multiDashboards, convert dataKey references in visualizations
54
+ if (data.multiDashboards) {
55
+ data.multiDashboards.forEach((dashboard: any) => {
56
+ if (dashboard.visualizations) {
57
+ Object.values(dashboard.visualizations).forEach((viz: any) => {
58
+ // Only convert dataKey if it's a URL path (starts with / or ../)
59
+ if (viz.dataKey && (viz.dataKey.startsWith('/') || viz.dataKey.startsWith('../'))) {
60
+ const dataKey = viz.dataKey.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
61
+ viz.dataKey = `https://www.cdc.gov/${dataKey}`
62
+ }
63
+ })
64
+ }
65
+ })
66
+ }
67
+
68
+ // For dashboard configs, convert dataKey references in visualizations
69
+ if (data.visualizations) {
70
+ Object.values(data.visualizations).forEach((viz: any) => {
71
+ // Only convert dataKey if it's a URL path (starts with / or ../)
72
+ if (viz.dataKey && (viz.dataKey.startsWith('/') || viz.dataKey.startsWith('../'))) {
73
+ const dataKey = viz.dataKey.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
74
+ viz.dataKey = `https://www.cdc.gov/${dataKey}`
75
+ }
76
+ })
77
+ }
78
+
79
+ // For dashboard configs, convert datasets only if they reference external files
80
+ if (data.datasets) {
81
+ const newDatasets = {}
82
+ Object.entries(data.datasets).forEach(([key, dataset]: [string, any]) => {
83
+ // Check if dataset has embedded data
84
+ const hasEmbeddedData = (dataset as any).data && Array.isArray((dataset as any).data)
85
+
86
+ // If data is embedded, keep the original key
87
+ if (hasEmbeddedData) {
88
+ newDatasets[key] = dataset
89
+ } else {
90
+ // Otherwise, convert paths to absolute URLs (but keep absolute URLs as-is)
91
+ const newKey = key.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
92
+ const absoluteKey = key.startsWith('http') ? key : `https://www.cdc.gov/${newKey}`
93
+
94
+ newDatasets[absoluteKey] = {
95
+ ...dataset,
96
+ dataFileName:
97
+ (dataset as any).dataFileName && !(dataset as any).dataFileName.startsWith('http')
98
+ ? `https://www.cdc.gov/${(dataset as any).dataFileName
99
+ .replace(/^(\.\.\/)+/, '')
100
+ .replace(/^\//, '')}`
101
+ : (dataset as any).dataFileName,
102
+ dataUrl:
103
+ (dataset as any).dataUrl && !(dataset as any).dataUrl.startsWith('http')
104
+ ? `https://www.cdc.gov/${(dataset as any).dataUrl.replace(/^(\.\.\/)+/, '').replace(/^\//, '')}`
105
+ : (dataset as any).dataUrl
106
+ }
107
+ }
108
+ })
109
+ data.datasets = newDatasets
110
+ }
111
+
112
+ // Set activeDashboard to 0 if it's null and multiDashboards exist
113
+ if (data.multiDashboards && data.multiDashboards.length > 0 && data.activeDashboard === null) {
114
+ data.activeDashboard = 0
115
+ }
116
+
117
+ // Log config info for debugging
118
+ console.log('✓ Config loaded:', {
119
+ type: data.type,
120
+ hasMultiDashboards: !!data.multiDashboards,
121
+ dashboardCount: data.multiDashboards?.length || 0,
122
+ activeDashboard: data.activeDashboard,
123
+ datasetCount: Object.keys(data.datasets || {}).length,
124
+ dashboardLabels: data.multiDashboards?.map((d: any) => d.label)
125
+ })
126
+
127
+ setConfig(data)
128
+ })
129
+ .catch(err => {
130
+ console.error('Failed to fetch config:', configUrl, err)
131
+ })
132
+ }, [configUrl])
133
+
134
+ return config
135
+ }
136
+
137
+ type DashboardStory = StoryObj<typeof Dashboard>
138
+
139
+ // Helper function to test dashboard rendering
140
+ const testDashboardRendering = async (canvasElement: HTMLElement, storyName: string) => {
141
+ await step('Wait for dashboard to render', async () => {
142
+ await new Promise<void>((resolve, reject) => {
143
+ const startTime = Date.now()
144
+ const timeout = 30000 // Longer timeout for external data loading
145
+
146
+ const checkDashboard = () => {
147
+ const dashboardElement = canvasElement.querySelector('.type-dashboard')
148
+ const loadingDiv = canvasElement.querySelector('div')
149
+
150
+ // Log current state for debugging
151
+ if (!dashboardElement && loadingDiv?.textContent?.includes('Loading')) {
152
+ console.log('Still loading config...')
153
+ }
154
+
155
+ if (dashboardElement) {
156
+ resolve()
157
+ } else if (Date.now() - startTime > timeout) {
158
+ reject(new Error(`Timeout: Dashboard element not found after ${timeout}ms`))
159
+ } else {
160
+ setTimeout(checkDashboard, 100)
161
+ }
162
+ }
163
+ checkDashboard()
164
+ })
165
+ })
166
+
167
+ await step('Verify dashboard wrapper is present', async () => {
168
+ const dashboard = canvasElement.querySelector('.type-dashboard')
169
+ expect(dashboard).toBeInTheDocument()
170
+ })
171
+
172
+ await step('Verify at least one visualization rendered', async () => {
173
+ const coveModules = canvasElement.querySelectorAll('.cdc-open-viz-module')
174
+ expect(coveModules.length).toBeGreaterThan(0)
175
+ })
176
+
177
+ console.log(`✓ ${storyName} dashboard rendered successfully`)
178
+ }
179
+
180
+ /**
181
+ * Excessive Alcohol Use Dashboard
182
+ *
183
+ * Interactive dashboard showing state-level data on excessive alcohol use in the United States.
184
+ *
185
+ * The dashboard displays data for all 50 states including:
186
+ * - Prevalence of excessive drinking among adults
187
+ * - Binge drinking statistics
188
+ * - Economic costs of excessive alcohol use
189
+ * - Alcohol-related deaths and health impacts
190
+ * - State-specific alcohol consumption trends
191
+ */
192
+ export const Excessive_Alcohol_Use_Dashboard: DashboardStory = {
193
+ render: () => {
194
+ const config = useConfigWithAbsoluteDataUrl(CONFIG_URLS.excessiveAlcoholUse)
195
+ if (!config) return <div>Loading...</div>
196
+ return <Dashboard config={config} />
197
+ },
198
+ play: async ({ canvasElement }) => {
199
+ await testDashboardRendering(canvasElement, 'Excessive Alcohol Use Dashboard')
200
+ }
201
+ }
@@ -0,0 +1,193 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { within, expect } from 'storybook/test'
3
+ import Dashboard from '@cdc/dashboard'
4
+ import { useEffect, useState } from 'react'
5
+
6
+ // Fallback step function for test descriptions
7
+ const step = async (description: string, fn: () => Promise<void> | void) => {
8
+ console.log(`▶ ${description}`)
9
+ await fn()
10
+ console.log(`✓ ${description}`)
11
+ }
12
+
13
+ const meta: Meta = {
14
+ title: 'Regression Tests/Pages/Maternal Mortality',
15
+ parameters: {
16
+ layout: 'fullscreen',
17
+ docs: {
18
+ description: {
19
+ component:
20
+ 'Stories for visualizations from the CDC Pregnancy Mortality Surveillance System (PMSS) page (https://www.cdc.gov/maternal-mortality/php/pregnancy-mortality-surveillance-data/index.html)'
21
+ }
22
+ }
23
+ },
24
+ tags: ['autodocs']
25
+ }
26
+
27
+ export default meta
28
+
29
+ // Config URL from the maternal mortality surveillance data page
30
+ const CONFIG_URLS = {
31
+ pmssDashboard: 'https://www.cdc.gov/maternal-mortality/dfe-module/data-mmrc/pmss-data-dashboard.json'
32
+ }
33
+
34
+ // Helper to fetch config and update data URLs to use absolute cdc.gov paths
35
+ const useConfigWithAbsoluteDataUrl = (configUrl: string) => {
36
+ const [config, setConfig] = useState(null)
37
+
38
+ useEffect(() => {
39
+ fetch(configUrl)
40
+ .then(res => res.json())
41
+ .then(data => {
42
+ // Convert relative data URLs to absolute cdc.gov URLs
43
+ if (data.dataUrl) {
44
+ // Handle different relative path formats (../../path or /path)
45
+ const dataUrl = data.dataUrl.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
46
+ data.dataUrl = `https://www.cdc.gov/${dataUrl}`
47
+ }
48
+ if (data.dataFileName) {
49
+ const dataFileName = data.dataFileName.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
50
+ data.dataFileName = `https://www.cdc.gov/${dataFileName}`
51
+ }
52
+
53
+ // For dashboard configs with multiDashboards, convert dataKey references in visualizations
54
+ if (data.multiDashboards) {
55
+ data.multiDashboards.forEach((dashboard: any) => {
56
+ if (dashboard.visualizations) {
57
+ Object.values(dashboard.visualizations).forEach((viz: any) => {
58
+ // Only convert dataKey if it's a URL path (starts with / or ../)
59
+ if (viz.dataKey && (viz.dataKey.startsWith('/') || viz.dataKey.startsWith('../'))) {
60
+ const dataKey = viz.dataKey.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
61
+ viz.dataKey = `https://www.cdc.gov/${dataKey}`
62
+ }
63
+ })
64
+ }
65
+ })
66
+ }
67
+
68
+ // For dashboard configs, convert dataKey references in visualizations
69
+ if (data.visualizations) {
70
+ Object.values(data.visualizations).forEach((viz: any) => {
71
+ // Only convert dataKey if it's a URL path (starts with / or ../)
72
+ if (viz.dataKey && (viz.dataKey.startsWith('/') || viz.dataKey.startsWith('../'))) {
73
+ const dataKey = viz.dataKey.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
74
+ viz.dataKey = `https://www.cdc.gov/${dataKey}`
75
+ }
76
+ })
77
+ }
78
+
79
+ // For dashboard configs, convert datasets only if they reference external files
80
+ if (data.datasets) {
81
+ const newDatasets = {}
82
+ Object.entries(data.datasets).forEach(([key, dataset]: [string, any]) => {
83
+ // Check if dataset has embedded data
84
+ const hasEmbeddedData = (dataset as any).data && Array.isArray((dataset as any).data)
85
+
86
+ // If data is embedded, keep the original key
87
+ if (hasEmbeddedData) {
88
+ newDatasets[key] = dataset
89
+ } else {
90
+ // Otherwise, convert paths to absolute URLs
91
+ const newKey = key.replace(/^(\.\.\/)+/, '').replace(/^\//, '')
92
+ const absoluteKey = `https://www.cdc.gov/${newKey}`
93
+
94
+ newDatasets[absoluteKey] = {
95
+ ...dataset,
96
+ dataFileName: (dataset as any).dataFileName
97
+ ? `https://www.cdc.gov/${(dataset as any).dataFileName.replace(/^(\.\.\/)+/, '').replace(/^\//, '')}`
98
+ : (dataset as any).dataFileName,
99
+ dataUrl: (dataset as any).dataUrl
100
+ ? `https://www.cdc.gov/${(dataset as any).dataUrl.replace(/^(\.\.\/)+/, '').replace(/^\//, '')}`
101
+ : (dataset as any).dataUrl
102
+ }
103
+ }
104
+ })
105
+ data.datasets = newDatasets
106
+ }
107
+
108
+ // Set activeDashboard to 0 if it's null and multiDashboards exist
109
+ if (data.multiDashboards && data.multiDashboards.length > 0 && data.activeDashboard === null) {
110
+ data.activeDashboard = 0
111
+ }
112
+
113
+ // Log config info for debugging
114
+ console.log('✓ Config loaded:', {
115
+ hasMultiDashboards: !!data.multiDashboards,
116
+ dashboardCount: data.multiDashboards?.length || 0,
117
+ activeDashboard: data.activeDashboard,
118
+ datasetCount: Object.keys(data.datasets || {}).length,
119
+ firstDashboardVizCount: data.multiDashboards?.[0]?.visualizations
120
+ ? Object.keys(data.multiDashboards[0].visualizations).length
121
+ : 0
122
+ })
123
+
124
+ setConfig(data)
125
+ })
126
+ .catch(err => {
127
+ console.error('Failed to fetch config:', configUrl, err)
128
+ })
129
+ }, [configUrl])
130
+
131
+ return config
132
+ }
133
+
134
+ type DashboardStory = StoryObj<typeof Dashboard>
135
+
136
+ // Helper function to test dashboard rendering
137
+ const testDashboardRendering = async (canvasElement: HTMLElement, storyName: string) => {
138
+ await step('Wait for dashboard to render', async () => {
139
+ await new Promise<void>((resolve, reject) => {
140
+ const startTime = Date.now()
141
+ const timeout = 20000
142
+
143
+ const checkDashboard = () => {
144
+ const dashboardElement = canvasElement.querySelector('.type-dashboard')
145
+ const loadingDiv = canvasElement.querySelector('div')
146
+
147
+ // Log current state for debugging
148
+ if (!dashboardElement && loadingDiv?.textContent?.includes('Loading')) {
149
+ console.log('Still loading config...')
150
+ }
151
+
152
+ if (dashboardElement) {
153
+ resolve()
154
+ } else if (Date.now() - startTime > timeout) {
155
+ reject(new Error(`Timeout: Dashboard element not found after ${timeout}ms`))
156
+ } else {
157
+ setTimeout(checkDashboard, 100)
158
+ }
159
+ }
160
+ checkDashboard()
161
+ })
162
+ })
163
+
164
+ await step('Verify dashboard wrapper is present', async () => {
165
+ const dashboard = canvasElement.querySelector('.type-dashboard')
166
+ expect(dashboard).toBeInTheDocument()
167
+ })
168
+
169
+ await step('Verify at least one visualization rendered', async () => {
170
+ const coveModules = canvasElement.querySelectorAll('.cdc-open-viz-module')
171
+ expect(coveModules.length).toBeGreaterThan(0)
172
+ })
173
+
174
+ console.log(` ${storyName} dashboard rendered successfully`)
175
+ }
176
+
177
+ /**
178
+ * PMSS Data Dashboard
179
+ *
180
+ * Interactive dashboard showing Pregnancy Mortality Surveillance System (PMSS) data,
181
+ * including pregnancy-related mortality ratios, trends over time, and demographic breakdowns.
182
+ * This surveillance system monitors pregnancy-related deaths in the United States.
183
+ */
184
+ export const PMSS_Dashboard: DashboardStory = {
185
+ render: () => {
186
+ const config = useConfigWithAbsoluteDataUrl(CONFIG_URLS.pmssDashboard)
187
+ if (!config) return <div>Loading...</div>
188
+ return <Dashboard config={config} />
189
+ },
190
+ play: async ({ canvasElement }) => {
191
+ await testDashboardRendering(canvasElement, 'PMSS Dashboard')
192
+ }
193
+ }