@carto/ps-react-ui 4.3.3 → 4.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.js +3 -3
- package/dist/components.js.map +1 -1
- package/dist/{lasso-tool-BwRzEW7k.js → lasso-tool-wFqOD6wk.js} +13 -13
- package/dist/lasso-tool-wFqOD6wk.js.map +1 -0
- package/dist/types/components/common-types.d.ts +41 -0
- package/dist/types/components/types.d.ts +1 -1
- package/dist/types/widgets/echart/echart-ui.d.ts +1 -1
- package/dist/types/widgets/echart/types.d.ts +4 -0
- package/dist/widgets/actions.js +1 -1
- package/dist/widgets/bar.js +1 -1
- package/dist/widgets/category.js +1 -1
- package/dist/widgets/echart.js +96 -85
- package/dist/widgets/echart.js.map +1 -1
- package/dist/widgets/formula.js +1 -1
- package/dist/widgets/histogram.js +1 -1
- package/dist/widgets/markdown.js +1 -1
- package/dist/widgets/pie.js +1 -1
- package/dist/widgets/scatterplot.js +1 -1
- package/dist/widgets/spread.js +1 -1
- package/dist/widgets/table.js +1 -1
- package/dist/widgets/timeseries.js +1 -1
- package/dist/widgets/toolbar-actions.js.map +1 -1
- package/dist/widgets/wrapper.js +1 -1
- package/package.json +8 -3
- package/src/components/basemaps/basemaps.test.tsx +196 -0
- package/src/components/basemaps/basemaps.tsx +128 -0
- package/src/components/basemaps/const.ts +13 -0
- package/src/components/basemaps/group-wrapper.test.tsx +38 -0
- package/src/components/basemaps/group-wrapper.tsx +28 -0
- package/src/components/basemaps/group.test.tsx +52 -0
- package/src/components/basemaps/group.tsx +42 -0
- package/src/components/basemaps/header.test.tsx +54 -0
- package/src/components/basemaps/header.tsx +36 -0
- package/src/components/basemaps/styles.ts +76 -0
- package/src/components/basemaps/types.ts +30 -0
- package/src/components/common-types.ts +1 -0
- package/src/components/geolocation-controls/const.ts +6 -0
- package/src/components/geolocation-controls/geolocation-controls.test.tsx +133 -0
- package/src/components/geolocation-controls/geolocation-controls.tsx +95 -0
- package/src/components/geolocation-controls/types.ts +17 -0
- package/src/components/index.ts +64 -0
- package/src/components/lasso-tool/chip.tsx +37 -0
- package/src/components/lasso-tool/const.tsx +70 -0
- package/src/components/lasso-tool/icons.tsx +91 -0
- package/src/components/lasso-tool/lasso-tool-inline.test.tsx +168 -0
- package/src/components/lasso-tool/lasso-tool-inline.tsx +245 -0
- package/src/components/lasso-tool/lasso-tool.test.tsx +212 -0
- package/src/components/lasso-tool/lasso-tool.tsx +479 -0
- package/src/components/lasso-tool/styles.ts +143 -0
- package/src/components/lasso-tool/types.ts +114 -0
- package/src/components/list-data/list-data-skeleton.test.tsx +10 -0
- package/src/components/list-data/list-data-skeleton.tsx +40 -0
- package/src/components/list-data/list-data.test.tsx +94 -0
- package/src/components/list-data/list-data.tsx +106 -0
- package/src/components/list-data/styles.ts +37 -0
- package/src/components/list-data/types.ts +25 -0
- package/src/components/measurement-tools/const.tsx +108 -0
- package/src/components/measurement-tools/icons.tsx +54 -0
- package/src/components/measurement-tools/measurement-tools.test.tsx +165 -0
- package/src/components/measurement-tools/measurement-tools.tsx +443 -0
- package/src/components/measurement-tools/styles.ts +91 -0
- package/src/components/measurement-tools/types.ts +77 -0
- package/src/components/no-data-alert/no-data-alert.test.tsx +31 -0
- package/src/components/no-data-alert/no-data-alert.tsx +59 -0
- package/src/components/responsive-drawer/responsive-drawer.test.tsx +91 -0
- package/src/components/responsive-drawer/responsive-drawer.tsx +53 -0
- package/src/components/smart-tooltip/smart-tooltip.test.tsx +168 -0
- package/src/components/smart-tooltip/smart-tooltip.tsx +40 -0
- package/src/components/tooltip/tooltip.test.tsx +86 -0
- package/src/components/tooltip/tooltip.tsx +30 -0
- package/src/components/types.ts +1 -0
- package/src/components/zoom-controls/styles.ts +27 -0
- package/src/components/zoom-controls/types.ts +19 -0
- package/src/components/zoom-controls/zoom-controls.test.tsx +101 -0
- package/src/components/zoom-controls/zoom-controls.tsx +114 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-debounce.ts +55 -0
- package/src/hooks/use-skeleton.test.tsx +32 -0
- package/src/hooks/use-skeleton.ts +19 -0
- package/src/hooks/use-widget-ref.ts +33 -0
- package/src/widgets/README.md +277 -0
- package/src/widgets/_shared/chart-config/config-factory.ts +67 -0
- package/src/widgets/_shared/chart-config/csv-modifiers.ts +56 -0
- package/src/widgets/_shared/chart-config/index.ts +21 -0
- package/src/widgets/_shared/chart-config/option-builders.ts +203 -0
- package/src/widgets/_shared/skeleton/index.ts +5 -0
- package/src/widgets/_shared/skeleton/styles.ts +20 -0
- package/src/widgets/actions/change-column/change-column-icon.tsx +10 -0
- package/src/widgets/actions/change-column/change-column.test.tsx +163 -0
- package/src/widgets/actions/change-column/change-column.tsx +141 -0
- package/src/widgets/actions/change-column/sortable-column-item.tsx +49 -0
- package/src/widgets/actions/change-column/types.ts +20 -0
- package/src/widgets/actions/download/download.test.tsx +322 -0
- package/src/widgets/actions/download/download.tsx +118 -0
- package/src/widgets/actions/download/exports.test.tsx +275 -0
- package/src/widgets/actions/download/exports.tsx +103 -0
- package/src/widgets/actions/download/types.ts +21 -0
- package/src/widgets/actions/fullscreen/fullscreen.test.tsx +269 -0
- package/src/widgets/actions/fullscreen/fullscreen.tsx +82 -0
- package/src/widgets/actions/fullscreen/styles.ts +17 -0
- package/src/widgets/actions/fullscreen/types.ts +27 -0
- package/src/widgets/actions/index.ts +51 -0
- package/src/widgets/actions/lock-selection/lock-selection.test.tsx +186 -0
- package/src/widgets/actions/lock-selection/lock-selection.tsx +133 -0
- package/src/widgets/actions/lock-selection/types.ts +41 -0
- package/src/widgets/actions/relative-data/relative-data.test.tsx +267 -0
- package/src/widgets/actions/relative-data/relative-data.tsx +133 -0
- package/src/widgets/actions/relative-data/style.ts +9 -0
- package/src/widgets/actions/relative-data/types.ts +31 -0
- package/src/widgets/actions/relative-data/utils.test.ts +223 -0
- package/src/widgets/actions/relative-data/utils.ts +58 -0
- package/src/widgets/actions/searcher/searcher-toggle.test.tsx +354 -0
- package/src/widgets/actions/searcher/searcher-toggle.tsx +73 -0
- package/src/widgets/actions/searcher/searcher.tsx +205 -0
- package/src/widgets/actions/searcher/types.ts +72 -0
- package/src/widgets/actions/shared/styles.ts +12 -0
- package/src/widgets/actions/stack-toggle/grouped-bar-chart-icon.tsx +14 -0
- package/src/widgets/actions/stack-toggle/stack-toggle.test.tsx +270 -0
- package/src/widgets/actions/stack-toggle/stack-toggle.tsx +146 -0
- package/src/widgets/actions/stack-toggle/types.ts +29 -0
- package/src/widgets/actions/zoom-toggle/index.ts +2 -0
- package/src/widgets/actions/zoom-toggle/style.ts +14 -0
- package/src/widgets/actions/zoom-toggle/types.ts +44 -0
- package/src/widgets/actions/zoom-toggle/zoom-toggle.tsx +186 -0
- package/src/widgets/bar/config.ts +122 -0
- package/src/widgets/bar/index.ts +9 -0
- package/src/widgets/bar/skeleton.tsx +60 -0
- package/src/widgets/bar/style.ts +33 -0
- package/src/widgets/bar/types.ts +16 -0
- package/src/widgets/category/category-ui.test.tsx +399 -0
- package/src/widgets/category/category-ui.tsx +156 -0
- package/src/widgets/category/components/category-bar.tsx +28 -0
- package/src/widgets/category/components/category-legend.tsx +30 -0
- package/src/widgets/category/components/category-row-multi.tsx +50 -0
- package/src/widgets/category/components/category-row-other.tsx +23 -0
- package/src/widgets/category/components/category-row-single.tsx +47 -0
- package/src/widgets/category/components/index.ts +14 -0
- package/src/widgets/category/config.ts +85 -0
- package/src/widgets/category/index.ts +30 -0
- package/src/widgets/category/skeleton.tsx +24 -0
- package/src/widgets/category/style.ts +133 -0
- package/src/widgets/category/types.ts +40 -0
- package/src/widgets/echart/const.ts +1 -0
- package/src/widgets/echart/echart-ui.test.tsx +537 -0
- package/src/widgets/echart/echart-ui.tsx +92 -0
- package/src/widgets/echart/echart.test.tsx +562 -0
- package/src/widgets/echart/echart.tsx +68 -0
- package/src/widgets/echart/index.ts +16 -0
- package/src/widgets/echart/options.ts +53 -0
- package/src/widgets/echart/types.ts +45 -0
- package/src/widgets/echart/utils.ts +169 -0
- package/src/widgets/error/error.test.tsx +331 -0
- package/src/widgets/error/error.tsx +40 -0
- package/src/widgets/error/index.ts +2 -0
- package/src/widgets/error/types.ts +14 -0
- package/src/widgets/formula/components/item.test.tsx +249 -0
- package/src/widgets/formula/components/item.tsx +18 -0
- package/src/widgets/formula/components/prefix.test.tsx +341 -0
- package/src/widgets/formula/components/prefix.tsx +18 -0
- package/src/widgets/formula/components/row.test.tsx +364 -0
- package/src/widgets/formula/components/row.tsx +21 -0
- package/src/widgets/formula/components/series.tsx +34 -0
- package/src/widgets/formula/components/suffix.test.tsx +383 -0
- package/src/widgets/formula/components/suffix.tsx +28 -0
- package/src/widgets/formula/components/value.test.tsx +329 -0
- package/src/widgets/formula/components/value.tsx +29 -0
- package/src/widgets/formula/config.ts +27 -0
- package/src/widgets/formula/formula-ui.test.tsx +399 -0
- package/src/widgets/formula/formula-ui.tsx +27 -0
- package/src/widgets/formula/index.ts +24 -0
- package/src/widgets/formula/serializer.test.tsx +144 -0
- package/src/widgets/formula/serializer.ts +28 -0
- package/src/widgets/formula/skeleton.tsx +10 -0
- package/src/widgets/formula/style.ts +23 -0
- package/src/widgets/formula/types.ts +50 -0
- package/src/widgets/histogram/config.ts +143 -0
- package/src/widgets/histogram/index.ts +8 -0
- package/src/widgets/histogram/skeleton.tsx +52 -0
- package/src/widgets/histogram/style.ts +8 -0
- package/src/widgets/histogram/types.ts +17 -0
- package/src/widgets/index.ts +25 -0
- package/src/widgets/loader/index.ts +4 -0
- package/src/widgets/loader/loader.tsx +70 -0
- package/src/widgets/loader/types.ts +11 -0
- package/src/widgets/loader/utils.test.ts +112 -0
- package/src/widgets/loader/utils.ts +35 -0
- package/src/widgets/markdown/config.ts +18 -0
- package/src/widgets/markdown/index.ts +14 -0
- package/src/widgets/markdown/markdown-ui.test.tsx +341 -0
- package/src/widgets/markdown/markdown-ui.tsx +52 -0
- package/src/widgets/markdown/markdown.tsx +20 -0
- package/src/widgets/markdown/skeleton.tsx +12 -0
- package/src/widgets/markdown/style.ts +28 -0
- package/src/widgets/markdown/types.ts +28 -0
- package/src/widgets/no-data/index.ts +2 -0
- package/src/widgets/no-data/no-data.test.tsx +447 -0
- package/src/widgets/no-data/no-data.tsx +116 -0
- package/src/widgets/no-data/style.ts +18 -0
- package/src/widgets/no-data/types.ts +72 -0
- package/src/widgets/note/index.ts +2 -0
- package/src/widgets/note/note.test.tsx +391 -0
- package/src/widgets/note/note.tsx +114 -0
- package/src/widgets/note/style.ts +29 -0
- package/src/widgets/note/types.ts +9 -0
- package/src/widgets/pie/config.ts +177 -0
- package/src/widgets/pie/index.ts +8 -0
- package/src/widgets/pie/skeleton.tsx +70 -0
- package/src/widgets/pie/style.ts +8 -0
- package/src/widgets/pie/types.ts +16 -0
- package/src/widgets/range/components/range-item.tsx +213 -0
- package/src/widgets/range/config.ts +10 -0
- package/src/widgets/range/index.ts +16 -0
- package/src/widgets/range/range-ui.test.tsx +203 -0
- package/src/widgets/range/range-ui.tsx +11 -0
- package/src/widgets/range/serializer.test.ts +70 -0
- package/src/widgets/range/serializer.ts +27 -0
- package/src/widgets/range/skeleton.tsx +14 -0
- package/src/widgets/range/style.ts +37 -0
- package/src/widgets/range/types.ts +39 -0
- package/src/widgets/scatterplot/config.ts +138 -0
- package/src/widgets/scatterplot/index.ts +8 -0
- package/src/widgets/scatterplot/skeleton.tsx +59 -0
- package/src/widgets/scatterplot/style.ts +21 -0
- package/src/widgets/scatterplot/types.ts +17 -0
- package/src/widgets/selection-summary/index.ts +6 -0
- package/src/widgets/selection-summary/selection-summary.tsx +46 -0
- package/src/widgets/selection-summary/style.ts +10 -0
- package/src/widgets/selection-summary/types.ts +14 -0
- package/src/widgets/skeleton-loader/index.ts +2 -0
- package/src/widgets/skeleton-loader/skeleton-loader.test.tsx +139 -0
- package/src/widgets/skeleton-loader/skeleton-loader.tsx +28 -0
- package/src/widgets/skeleton-loader/types.ts +8 -0
- package/src/widgets/spread/components/max-value.tsx +29 -0
- package/src/widgets/spread/components/min-value.tsx +29 -0
- package/src/widgets/spread/components/separator.tsx +6 -0
- package/src/widgets/spread/config.ts +34 -0
- package/src/widgets/spread/index.ts +23 -0
- package/src/widgets/spread/skeleton.tsx +10 -0
- package/src/widgets/spread/spread-ui.test.tsx +368 -0
- package/src/widgets/spread/spread-ui.tsx +29 -0
- package/src/widgets/spread/style.ts +22 -0
- package/src/widgets/spread/types.ts +47 -0
- package/src/widgets/stores/index.ts +9 -0
- package/src/widgets/stores/types.ts +192 -0
- package/src/widgets/stores/widget-store.test.ts +601 -0
- package/src/widgets/stores/widget-store.ts +239 -0
- package/src/widgets/subheader/index.ts +3 -0
- package/src/widgets/subheader/style.ts +20 -0
- package/src/widgets/subheader/subheader.test.tsx +45 -0
- package/src/widgets/subheader/subheader.tsx +16 -0
- package/src/widgets/subheader/types.ts +11 -0
- package/src/widgets/table/components/cell-header.tsx +58 -0
- package/src/widgets/table/components/cell.tsx +80 -0
- package/src/widgets/table/components/index.ts +4 -0
- package/src/widgets/table/components/pagination-actions.tsx +67 -0
- package/src/widgets/table/components/pagination.tsx +41 -0
- package/src/widgets/table/components/row.tsx +60 -0
- package/src/widgets/table/config.ts +71 -0
- package/src/widgets/table/helpers.test.ts +244 -0
- package/src/widgets/table/helpers.ts +107 -0
- package/src/widgets/table/hooks/index.ts +7 -0
- package/src/widgets/table/hooks/use-pagination.test.ts +294 -0
- package/src/widgets/table/hooks/use-pagination.ts +155 -0
- package/src/widgets/table/hooks/use-selection.test.ts +504 -0
- package/src/widgets/table/hooks/use-selection.ts +189 -0
- package/src/widgets/table/hooks/use-sort.test.ts +296 -0
- package/src/widgets/table/hooks/use-sort.ts +138 -0
- package/src/widgets/table/index.ts +53 -0
- package/src/widgets/table/serializer.ts +54 -0
- package/src/widgets/table/skeleton.tsx +48 -0
- package/src/widgets/table/style.ts +34 -0
- package/src/widgets/table/table-ui.tsx +64 -0
- package/src/widgets/table/types.ts +223 -0
- package/src/widgets/timeseries/config.ts +135 -0
- package/src/widgets/timeseries/index.ts +8 -0
- package/src/widgets/timeseries/skeleton.tsx +55 -0
- package/src/widgets/timeseries/style.ts +36 -0
- package/src/widgets/timeseries/types.ts +17 -0
- package/src/widgets/toolbar-actions/index.ts +6 -0
- package/src/widgets/toolbar-actions/styles.ts +38 -0
- package/src/widgets/toolbar-actions/toolbar-actions.test.tsx +691 -0
- package/src/widgets/toolbar-actions/toolbar-actions.tsx +145 -0
- package/src/widgets/toolbar-actions/types.ts +60 -0
- package/src/widgets/wrapper/components/actions.test.tsx +101 -0
- package/src/widgets/wrapper/components/actions.tsx +30 -0
- package/src/widgets/wrapper/components/options.test.tsx +323 -0
- package/src/widgets/wrapper/components/options.tsx +73 -0
- package/src/widgets/wrapper/components/title.test.tsx +126 -0
- package/src/widgets/wrapper/components/title.tsx +32 -0
- package/src/widgets/wrapper/index.ts +16 -0
- package/src/widgets/wrapper/styles.ts +98 -0
- package/src/widgets/wrapper/types.ts +55 -0
- package/src/widgets/wrapper/wrapper-ui.test.tsx +232 -0
- package/src/widgets/wrapper/wrapper-ui.tsx +57 -0
- package/src/widgets/wrapper/wrapper.test.tsx +365 -0
- package/src/widgets/wrapper/wrapper.tsx +50 -0
- package/dist/lasso-tool-BwRzEW7k.js.map +0 -1
- package/dist/types/common/common.d.ts +0 -3
- package/dist/types/common/index.d.ts +0 -26
- package/dist/types/common/lasso-tools.d.ts +0 -36
- package/dist/types/common/measurement-tools.d.ts +0 -65
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import { FormulaUI } from './formula-ui'
|
|
4
|
+
import { useWidgetStore } from '../stores/widget-store'
|
|
5
|
+
import type { FormulaWidgetState } from './types'
|
|
6
|
+
|
|
7
|
+
describe('FormulaUI', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
useWidgetStore.getState().clearWidgets()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('renders empty container when widget does not exist', () => {
|
|
13
|
+
const { container } = render(<FormulaUI id='non-existent' />)
|
|
14
|
+
// Box wrapper is rendered but Row returns null for missing widget
|
|
15
|
+
expect(container.firstChild?.childNodes.length).toBe(0)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('renders with single data item', () => {
|
|
19
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
20
|
+
type: 'formula',
|
|
21
|
+
data: [{ value: 100, prefix: '$', suffix: 'USD' }],
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
render(<FormulaUI id='test-formula' />)
|
|
25
|
+
|
|
26
|
+
expect(screen.getByText('$')).toBeTruthy()
|
|
27
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
28
|
+
expect(screen.getByText('USD')).toBeTruthy()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('renders with multiple data items', () => {
|
|
32
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
33
|
+
type: 'formula',
|
|
34
|
+
data: [
|
|
35
|
+
{ value: 100, prefix: '$' },
|
|
36
|
+
{ value: 200, suffix: '%' },
|
|
37
|
+
{ value: 300 },
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
render(<FormulaUI id='test-formula' />)
|
|
42
|
+
|
|
43
|
+
expect(screen.getByText('$')).toBeTruthy()
|
|
44
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
45
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
46
|
+
expect(screen.getByText('%')).toBeTruthy()
|
|
47
|
+
expect(screen.getByText('300')).toBeTruthy()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('renders Prefix component for each item', () => {
|
|
51
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
52
|
+
type: 'formula',
|
|
53
|
+
data: [
|
|
54
|
+
{ value: 100, prefix: 'Item 1:' },
|
|
55
|
+
{ value: 200, prefix: 'Item 2:' },
|
|
56
|
+
],
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
render(<FormulaUI id='test-formula' />)
|
|
60
|
+
|
|
61
|
+
expect(screen.getByText('Item 1:')).toBeTruthy()
|
|
62
|
+
expect(screen.getByText('Item 2:')).toBeTruthy()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('renders Value component for each item', () => {
|
|
66
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
67
|
+
type: 'formula',
|
|
68
|
+
data: [{ value: 100 }, { value: 200 }],
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
render(<FormulaUI id='test-formula' />)
|
|
72
|
+
|
|
73
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
74
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('renders Suffix component for each item', () => {
|
|
78
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
79
|
+
type: 'formula',
|
|
80
|
+
data: [
|
|
81
|
+
{ value: 100, suffix: 'units' },
|
|
82
|
+
{ value: 200, suffix: 'items' },
|
|
83
|
+
],
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
render(<FormulaUI id='test-formula' />)
|
|
87
|
+
|
|
88
|
+
expect(screen.getByText('units')).toBeTruthy()
|
|
89
|
+
expect(screen.getByText('items')).toBeTruthy()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('renders in correct order: Prefix, Value, Suffix', () => {
|
|
93
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
94
|
+
type: 'formula',
|
|
95
|
+
data: [{ value: 100, prefix: '$', suffix: 'USD' }],
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const { container } = render(<FormulaUI id='test-formula' />)
|
|
99
|
+
|
|
100
|
+
const items = container.querySelectorAll('.MuiTypography-root')
|
|
101
|
+
expect(items.length).toBe(3)
|
|
102
|
+
expect(items[0]?.textContent).toBe('$')
|
|
103
|
+
expect(items[1]?.textContent).toBe('100')
|
|
104
|
+
expect(items[2]?.textContent).toBe('USD')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('handles data without prefix', () => {
|
|
108
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
109
|
+
type: 'formula',
|
|
110
|
+
data: [{ value: 100, suffix: 'USD' }],
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
render(<FormulaUI id='test-formula' />)
|
|
114
|
+
|
|
115
|
+
expect(screen.queryByText('$')).toBeNull()
|
|
116
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
117
|
+
expect(screen.getByText('USD')).toBeTruthy()
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('handles data without suffix', () => {
|
|
121
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
122
|
+
type: 'formula',
|
|
123
|
+
data: [{ value: 100, prefix: '$' }],
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
render(<FormulaUI id='test-formula' />)
|
|
127
|
+
|
|
128
|
+
expect(screen.getByText('$')).toBeTruthy()
|
|
129
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
130
|
+
// Suffix should not be rendered
|
|
131
|
+
const items = screen.queryAllByText('USD')
|
|
132
|
+
expect(items.length).toBe(0)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('handles data with only value', () => {
|
|
136
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
137
|
+
type: 'formula',
|
|
138
|
+
data: [{ value: 100 }],
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
render(<FormulaUI id='test-formula' />)
|
|
142
|
+
|
|
143
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('handles empty data array', () => {
|
|
147
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
148
|
+
type: 'formula',
|
|
149
|
+
data: [],
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const { container } = render(<FormulaUI id='test-formula' />)
|
|
153
|
+
|
|
154
|
+
// Row component returns null for empty data, Box wrapper still rendered
|
|
155
|
+
expect(container.firstChild?.childNodes.length).toBe(0)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('handles undefined data', () => {
|
|
159
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
160
|
+
type: 'formula',
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const { container } = render(<FormulaUI id='test-formula' />)
|
|
164
|
+
|
|
165
|
+
// Row component returns null for undefined data, Box wrapper still rendered
|
|
166
|
+
expect(container.firstChild?.childNodes.length).toBe(0)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('passes correct index to child components', () => {
|
|
170
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
171
|
+
type: 'formula',
|
|
172
|
+
data: [
|
|
173
|
+
{ value: 100, prefix: 'First' },
|
|
174
|
+
{ value: 200, prefix: 'Second' },
|
|
175
|
+
{ value: 300, prefix: 'Third' },
|
|
176
|
+
],
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
render(<FormulaUI id='test-formula' />)
|
|
180
|
+
|
|
181
|
+
expect(screen.getByText('First')).toBeTruthy()
|
|
182
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
183
|
+
expect(screen.getByText('Second')).toBeTruthy()
|
|
184
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
185
|
+
expect(screen.getByText('Third')).toBeTruthy()
|
|
186
|
+
expect(screen.getByText('300')).toBeTruthy()
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('renders with data containing colors', () => {
|
|
190
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
191
|
+
type: 'formula',
|
|
192
|
+
data: [
|
|
193
|
+
{ value: 100, color: '#FF0000' },
|
|
194
|
+
{ value: 200, color: '#00FF00' },
|
|
195
|
+
],
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
render(<FormulaUI id='test-formula' />)
|
|
199
|
+
|
|
200
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
201
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test('renders with negative values', () => {
|
|
205
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
206
|
+
type: 'formula',
|
|
207
|
+
data: [{ value: -100, prefix: '-' }],
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
render(<FormulaUI id='test-formula' />)
|
|
211
|
+
|
|
212
|
+
expect(screen.getByText('-')).toBeTruthy()
|
|
213
|
+
expect(screen.getByText('-100')).toBeTruthy()
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
test('renders with zero value', () => {
|
|
217
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
218
|
+
type: 'formula',
|
|
219
|
+
data: [{ value: 0 }],
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
render(<FormulaUI id='test-formula' />)
|
|
223
|
+
|
|
224
|
+
expect(screen.getByText('0')).toBeTruthy()
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
test('renders with decimal values', () => {
|
|
228
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
229
|
+
type: 'formula',
|
|
230
|
+
data: [{ value: 123.456, suffix: 'km' }],
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
render(<FormulaUI id='test-formula' />)
|
|
234
|
+
|
|
235
|
+
expect(screen.getByText('123.456')).toBeTruthy()
|
|
236
|
+
expect(screen.getByText('km')).toBeTruthy()
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
test('renders with large values', () => {
|
|
240
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
241
|
+
type: 'formula',
|
|
242
|
+
data: [{ value: 1000000000, prefix: '$' }],
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
render(<FormulaUI id='test-formula' />)
|
|
246
|
+
|
|
247
|
+
expect(screen.getByText('$')).toBeTruthy()
|
|
248
|
+
expect(screen.getByText('1000000000')).toBeTruthy()
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
test('updates when widget data changes', () => {
|
|
252
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
253
|
+
type: 'formula',
|
|
254
|
+
data: [{ value: 100 }],
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
const { rerender } = render(<FormulaUI id='test-formula' />)
|
|
258
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
259
|
+
|
|
260
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
261
|
+
data: [{ value: 200 }],
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
rerender(<FormulaUI id='test-formula' />)
|
|
265
|
+
expect(screen.queryByText('100')).toBeNull()
|
|
266
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
test('handles widget removal gracefully', () => {
|
|
270
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
271
|
+
type: 'formula',
|
|
272
|
+
data: [{ value: 100 }],
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
const { container, rerender } = render(<FormulaUI id='test-formula' />)
|
|
276
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
277
|
+
|
|
278
|
+
useWidgetStore.getState().removeWidget('test-formula')
|
|
279
|
+
|
|
280
|
+
rerender(<FormulaUI id='test-formula' />)
|
|
281
|
+
// Box wrapper still rendered but Row returns null
|
|
282
|
+
expect(container.firstChild?.childNodes.length).toBe(0)
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
test('renders with empty string prefix', () => {
|
|
286
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
287
|
+
type: 'formula',
|
|
288
|
+
data: [{ value: 100, prefix: '' }],
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
const { container } = render(<FormulaUI id='test-formula' />)
|
|
292
|
+
|
|
293
|
+
// Empty prefix should not render
|
|
294
|
+
expect(container.firstChild).toBeTruthy()
|
|
295
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
test('renders with empty string suffix', () => {
|
|
299
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
300
|
+
type: 'formula',
|
|
301
|
+
data: [{ value: 100, suffix: '' }],
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
const { container } = render(<FormulaUI id='test-formula' />)
|
|
305
|
+
|
|
306
|
+
// Empty suffix should not render
|
|
307
|
+
expect(container.firstChild).toBeTruthy()
|
|
308
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
test('renders multiple rows for multiple data items', () => {
|
|
312
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
313
|
+
type: 'formula',
|
|
314
|
+
data: [
|
|
315
|
+
{ value: 100, prefix: 'A' },
|
|
316
|
+
{ value: 200, prefix: 'B' },
|
|
317
|
+
{ value: 300, prefix: 'C' },
|
|
318
|
+
],
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
const { container } = render(<FormulaUI id='test-formula' />)
|
|
322
|
+
|
|
323
|
+
// Each data item should create a row
|
|
324
|
+
const rows = container.querySelectorAll('[class*="MuiBox-root"]')
|
|
325
|
+
expect(rows.length).toBeGreaterThan(0)
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
test('renders with single series in array', () => {
|
|
329
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
330
|
+
type: 'formula',
|
|
331
|
+
data: [{ value: 100, suffix: 'units' }],
|
|
332
|
+
series: [{ name: 'Category A' }],
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
render(<FormulaUI id='test-formula' />)
|
|
336
|
+
|
|
337
|
+
expect(screen.getByText('C')).toBeTruthy() // Avatar shows first letter
|
|
338
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
test('renders with series and custom color', () => {
|
|
342
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
343
|
+
type: 'formula',
|
|
344
|
+
data: [{ value: 100 }],
|
|
345
|
+
series: [{ name: 'Sales', color: '#FF0000' }],
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
const { container } = render(<FormulaUI id='test-formula' />)
|
|
349
|
+
|
|
350
|
+
const avatar = container.querySelector('.MuiAvatar-root')
|
|
351
|
+
expect(avatar).toBeTruthy()
|
|
352
|
+
expect(screen.getByText('S')).toBeTruthy() // First letter of 'Sales'
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
test('renders with array of series matching data indices', () => {
|
|
356
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
357
|
+
type: 'formula',
|
|
358
|
+
data: [
|
|
359
|
+
{ value: 100, suffix: 'units' },
|
|
360
|
+
{ value: 200, suffix: 'items' },
|
|
361
|
+
{ value: 300, suffix: 'pieces' },
|
|
362
|
+
],
|
|
363
|
+
series: [
|
|
364
|
+
{ name: 'Alpha', color: '#FF0000' },
|
|
365
|
+
{ name: 'Beta', color: '#00FF00' },
|
|
366
|
+
{ name: 'Gamma', color: '#0000FF' },
|
|
367
|
+
],
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
render(<FormulaUI id='test-formula' />)
|
|
371
|
+
|
|
372
|
+
expect(screen.getByText('A')).toBeTruthy() // Alpha
|
|
373
|
+
expect(screen.getByText('B')).toBeTruthy() // Beta
|
|
374
|
+
expect(screen.getByText('G')).toBeTruthy() // Gamma
|
|
375
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
376
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
377
|
+
expect(screen.getByText('300')).toBeTruthy()
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
test('renders partial series array - only shows series for available indices', () => {
|
|
381
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-formula', {
|
|
382
|
+
type: 'formula',
|
|
383
|
+
data: [
|
|
384
|
+
{ value: 100, suffix: 'units' },
|
|
385
|
+
{ value: 200, suffix: 'items' },
|
|
386
|
+
{ value: 300, suffix: 'pieces' },
|
|
387
|
+
],
|
|
388
|
+
series: [{ name: 'Only First', color: '#FF0000' }],
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
render(<FormulaUI id='test-formula' />)
|
|
392
|
+
|
|
393
|
+
// Only first row should have series avatar
|
|
394
|
+
expect(screen.getByText('O')).toBeTruthy() // Only First
|
|
395
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
396
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
397
|
+
expect(screen.getByText('300')).toBeTruthy()
|
|
398
|
+
})
|
|
399
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FormulaUIProps } from './types'
|
|
2
|
+
import { Row } from './components/row'
|
|
3
|
+
import { Value } from './components/value'
|
|
4
|
+
import { Prefix } from './components/prefix'
|
|
5
|
+
import { Suffix } from './components/suffix'
|
|
6
|
+
import { Series } from './components/series'
|
|
7
|
+
import { useWidgetRef } from '../../hooks'
|
|
8
|
+
import { Box } from '@mui/material'
|
|
9
|
+
|
|
10
|
+
export function FormulaUI(props: FormulaUIProps) {
|
|
11
|
+
const ref = useWidgetRef(props.id)
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<Box ref={ref}>
|
|
15
|
+
<Row id={props.id}>
|
|
16
|
+
{({ index }) => (
|
|
17
|
+
<>
|
|
18
|
+
<Series id={props.id} index={index} />
|
|
19
|
+
<Prefix id={props.id} index={index} />
|
|
20
|
+
<Value id={props.id} index={index} />
|
|
21
|
+
<Suffix id={props.id} index={index} />
|
|
22
|
+
</>
|
|
23
|
+
)}
|
|
24
|
+
</Row>
|
|
25
|
+
</Box>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { Item } from './components/item'
|
|
2
|
+
export { Value } from './components/value'
|
|
3
|
+
export { Prefix } from './components/prefix'
|
|
4
|
+
export { Suffix } from './components/suffix'
|
|
5
|
+
export { Series } from './components/series'
|
|
6
|
+
export { Row } from './components/row'
|
|
7
|
+
|
|
8
|
+
export { formulaConfig, formulaDownloadConfig } from './config'
|
|
9
|
+
export { FormulaUI } from './formula-ui'
|
|
10
|
+
export { FormulaSkeleton } from './skeleton'
|
|
11
|
+
export { sanitizeDataItem, sanitizeDataItems } from './serializer'
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
DataItem,
|
|
15
|
+
FormulaDownloadConfig,
|
|
16
|
+
FormulaUIProps,
|
|
17
|
+
FormulaWidgetConfig,
|
|
18
|
+
FormulaWidgetData,
|
|
19
|
+
FormulaWidgetState,
|
|
20
|
+
ItemProps,
|
|
21
|
+
RowProps,
|
|
22
|
+
SeriesConfig,
|
|
23
|
+
ValueProps,
|
|
24
|
+
} from './types'
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, test, expect } from 'vitest'
|
|
2
|
+
import { sanitizeDataItem, sanitizeDataItems } from './serializer'
|
|
3
|
+
import type { DataItem } from './types'
|
|
4
|
+
|
|
5
|
+
describe('sanitizeDataItem', () => {
|
|
6
|
+
test('preserves string prefix and suffix', () => {
|
|
7
|
+
const item: DataItem = {
|
|
8
|
+
value: 100,
|
|
9
|
+
prefix: '$',
|
|
10
|
+
suffix: 'USD',
|
|
11
|
+
color: 'blue',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const result = sanitizeDataItem(item)
|
|
15
|
+
|
|
16
|
+
expect(result).toEqual({
|
|
17
|
+
value: 100,
|
|
18
|
+
prefix: '$',
|
|
19
|
+
suffix: 'USD',
|
|
20
|
+
color: 'blue',
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('converts ReactNode prefix to undefined', () => {
|
|
25
|
+
const item: DataItem = {
|
|
26
|
+
value: 100,
|
|
27
|
+
prefix: <span>$</span>,
|
|
28
|
+
suffix: 'USD',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const result = sanitizeDataItem(item)
|
|
32
|
+
|
|
33
|
+
expect(result).toEqual({
|
|
34
|
+
value: 100,
|
|
35
|
+
prefix: undefined,
|
|
36
|
+
suffix: 'USD',
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('converts ReactNode suffix to undefined', () => {
|
|
41
|
+
const item: DataItem = {
|
|
42
|
+
value: 100,
|
|
43
|
+
prefix: '$',
|
|
44
|
+
suffix: <span>USD</span>,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result = sanitizeDataItem(item)
|
|
48
|
+
|
|
49
|
+
expect(result).toEqual({
|
|
50
|
+
value: 100,
|
|
51
|
+
prefix: '$',
|
|
52
|
+
suffix: undefined,
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('converts both ReactNode prefix and suffix to undefined', () => {
|
|
57
|
+
const item: DataItem = {
|
|
58
|
+
value: 100,
|
|
59
|
+
prefix: <span>$</span>,
|
|
60
|
+
suffix: <span>USD</span>,
|
|
61
|
+
color: 'red',
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result = sanitizeDataItem(item)
|
|
65
|
+
|
|
66
|
+
expect(result).toEqual({
|
|
67
|
+
value: 100,
|
|
68
|
+
prefix: undefined,
|
|
69
|
+
suffix: undefined,
|
|
70
|
+
color: 'red',
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('handles missing prefix and suffix', () => {
|
|
75
|
+
const item: DataItem = {
|
|
76
|
+
value: 100,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const result = sanitizeDataItem(item)
|
|
80
|
+
|
|
81
|
+
expect(result).toEqual({
|
|
82
|
+
value: 100,
|
|
83
|
+
prefix: undefined,
|
|
84
|
+
suffix: undefined,
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('preserves other properties', () => {
|
|
89
|
+
const item: DataItem = {
|
|
90
|
+
value: 42,
|
|
91
|
+
color: '#FF5733',
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const result = sanitizeDataItem(item)
|
|
95
|
+
|
|
96
|
+
expect(result).toEqual({
|
|
97
|
+
value: 42,
|
|
98
|
+
prefix: undefined,
|
|
99
|
+
suffix: undefined,
|
|
100
|
+
color: '#FF5733',
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
describe('sanitizeDataItems', () => {
|
|
106
|
+
test('sanitizes array of items', () => {
|
|
107
|
+
const items: DataItem[] = [
|
|
108
|
+
{ value: 100, prefix: '$', suffix: 'USD' },
|
|
109
|
+
{ value: 200, prefix: <span>€</span>, suffix: 'EUR' },
|
|
110
|
+
{ value: 300, prefix: '¥', suffix: <span>JPY</span> },
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
const result = sanitizeDataItems(items)
|
|
114
|
+
|
|
115
|
+
expect(result).toEqual([
|
|
116
|
+
{ value: 100, prefix: '$', suffix: 'USD' },
|
|
117
|
+
{ value: 200, prefix: undefined, suffix: 'EUR' },
|
|
118
|
+
{ value: 300, prefix: '¥', suffix: undefined },
|
|
119
|
+
])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('handles undefined input', () => {
|
|
123
|
+
const result = sanitizeDataItems(undefined)
|
|
124
|
+
|
|
125
|
+
expect(result).toBeUndefined()
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('handles empty array', () => {
|
|
129
|
+
const result = sanitizeDataItems([])
|
|
130
|
+
|
|
131
|
+
expect(result).toEqual([])
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('does not mutate original array', () => {
|
|
135
|
+
const items: DataItem[] = [
|
|
136
|
+
{ value: 100, prefix: <span>$</span>, suffix: 'USD' },
|
|
137
|
+
]
|
|
138
|
+
const original = [...items]
|
|
139
|
+
|
|
140
|
+
sanitizeDataItems(items)
|
|
141
|
+
|
|
142
|
+
expect(items).toEqual(original)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DataItem } from './types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sanitizes DataItem by converting ReactNode prefix/suffix values to undefined.
|
|
5
|
+
* This ensures only string values are stored in the widget state.
|
|
6
|
+
*
|
|
7
|
+
* @param item - The DataItem to sanitize
|
|
8
|
+
* @returns A new DataItem with ReactNode prefix/suffix values converted to undefined
|
|
9
|
+
*/
|
|
10
|
+
export function sanitizeDataItem(item: DataItem): DataItem {
|
|
11
|
+
return {
|
|
12
|
+
...item,
|
|
13
|
+
prefix: typeof item.prefix === 'string' ? item.prefix : undefined,
|
|
14
|
+
suffix: typeof item.suffix === 'string' ? item.suffix : undefined,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sanitizes an array of DataItems by converting ReactNode prefix/suffix values to undefined.
|
|
20
|
+
*
|
|
21
|
+
* @param items - Array of DataItems to sanitize
|
|
22
|
+
* @returns A new array with sanitized DataItems
|
|
23
|
+
*/
|
|
24
|
+
export function sanitizeDataItems(
|
|
25
|
+
items: DataItem[] | undefined,
|
|
26
|
+
): DataItem[] | undefined {
|
|
27
|
+
return items?.map(sanitizeDataItem)
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
export const styles = {
|
|
4
|
+
root: {
|
|
5
|
+
display: 'flex',
|
|
6
|
+
flexDirection: 'column',
|
|
7
|
+
gap: (theme: Theme) => theme.spacing(2),
|
|
8
|
+
},
|
|
9
|
+
item: {
|
|
10
|
+
'&[data-disabled="true"]': {
|
|
11
|
+
color: (theme: Theme) => theme.palette.text.disabled,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
row: {
|
|
15
|
+
display: 'flex',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
gap: (theme: Theme) => theme.spacing(1),
|
|
18
|
+
|
|
19
|
+
'& + &': {
|
|
20
|
+
marginTop: (theme: Theme) => theme.spacing(1),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
} satisfies Record<string, SxProps<Theme>>
|