@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,329 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import { Value } from './value'
|
|
4
|
+
import { useWidgetStore } from '../../stores/widget-store'
|
|
5
|
+
import type { FormulaWidgetState } from '../types'
|
|
6
|
+
|
|
7
|
+
describe('Value', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
useWidgetStore.getState().clearWidgets()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('renders value from widget data at default index 0', () => {
|
|
13
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
14
|
+
type: 'formula',
|
|
15
|
+
data: [{ value: 100 }],
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
render(<Value id='test-value' />)
|
|
19
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('renders value at specified index', () => {
|
|
23
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
24
|
+
type: 'formula',
|
|
25
|
+
data: [{ value: 100 }, { value: 200 }, { value: 300 }],
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
render(<Value id='test-value' index={1} />)
|
|
29
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('renders value at index 0 when index not specified', () => {
|
|
33
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
34
|
+
type: 'formula',
|
|
35
|
+
data: [{ value: 100 }, { value: 200 }],
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
render(<Value id='test-value' />)
|
|
39
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('renders zero value', () => {
|
|
43
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
44
|
+
type: 'formula',
|
|
45
|
+
data: [{ value: 0 }],
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
render(<Value id='test-value' />)
|
|
49
|
+
expect(screen.getByText('0')).toBeTruthy()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('renders negative value', () => {
|
|
53
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
54
|
+
type: 'formula',
|
|
55
|
+
data: [{ value: -100 }],
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
render(<Value id='test-value' />)
|
|
59
|
+
expect(screen.getByText('-100')).toBeTruthy()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('renders decimal value', () => {
|
|
63
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
64
|
+
type: 'formula',
|
|
65
|
+
data: [{ value: 123.456 }],
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
render(<Value id='test-value' />)
|
|
69
|
+
expect(screen.getByText('123.456')).toBeTruthy()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('renders large value', () => {
|
|
73
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
74
|
+
type: 'formula',
|
|
75
|
+
data: [{ value: 1000000000 }],
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
render(<Value id='test-value' />)
|
|
79
|
+
expect(screen.getByText('1000000000')).toBeTruthy()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('applies custom color from data', () => {
|
|
83
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
84
|
+
type: 'formula',
|
|
85
|
+
data: [{ value: 100, color: '#FF0000' }],
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
render(<Value id='test-value' />)
|
|
89
|
+
const element = screen.getByText('100')
|
|
90
|
+
expect(element).toBeTruthy()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('renders without color when not specified', () => {
|
|
94
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
95
|
+
type: 'formula',
|
|
96
|
+
data: [{ value: 100 }],
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
render(<Value id='test-value' />)
|
|
100
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('applies different colors for different items', () => {
|
|
104
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
105
|
+
type: 'formula',
|
|
106
|
+
data: [
|
|
107
|
+
{ value: 100, color: '#FF0000' },
|
|
108
|
+
{ value: 200, color: '#00FF00' },
|
|
109
|
+
],
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const { unmount } = render(<Value id='test-value' index={0} />)
|
|
113
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
114
|
+
unmount()
|
|
115
|
+
|
|
116
|
+
render(<Value id='test-value' index={1} />)
|
|
117
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('renders as Typography h5', () => {
|
|
121
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
122
|
+
type: 'formula',
|
|
123
|
+
data: [{ value: 100 }],
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
render(<Value id='test-value' />)
|
|
127
|
+
const element = screen.getByText('100')
|
|
128
|
+
expect(element.tagName).toBe('H5')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('returns nothing when widget does not exist', () => {
|
|
132
|
+
const { container } = render(<Value id='non-existent' />)
|
|
133
|
+
// Value still renders Item, which renders Typography, but with undefined children
|
|
134
|
+
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test('returns nothing when widget data is undefined', () => {
|
|
138
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
139
|
+
type: 'formula',
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const { container } = render(<Value id='test-value' />)
|
|
143
|
+
// Value still renders Item, which renders Typography, but with undefined children
|
|
144
|
+
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('returns nothing when index is out of bounds', () => {
|
|
148
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
149
|
+
type: 'formula',
|
|
150
|
+
data: [{ value: 100 }],
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
const { container } = render(<Value id='test-value' index={5} />)
|
|
154
|
+
// Value still renders Item, which renders Typography, but with undefined children
|
|
155
|
+
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('handles empty data array', () => {
|
|
159
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
160
|
+
type: 'formula',
|
|
161
|
+
data: [],
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const { container } = render(<Value id='test-value' />)
|
|
165
|
+
// Value still renders Item, which renders Typography, but with undefined children
|
|
166
|
+
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('passes disabled prop to Item', () => {
|
|
170
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
171
|
+
type: 'formula',
|
|
172
|
+
data: [{ value: 100 }],
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
render(<Value id='test-value' disabled={true} />)
|
|
176
|
+
const element = screen.getByText('100')
|
|
177
|
+
expect(element.getAttribute('data-disabled')).toBe('true')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('passes TypographyProps to Item', () => {
|
|
181
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
182
|
+
type: 'formula',
|
|
183
|
+
data: [{ value: 100 }],
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
render(<Value id='test-value' TypographyProps={{ className: 'custom' }} />)
|
|
187
|
+
const element = screen.getByText('100')
|
|
188
|
+
expect(element.classList.contains('custom')).toBe(true)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('merges color from data with TypographyProps', () => {
|
|
192
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
193
|
+
type: 'formula',
|
|
194
|
+
data: [{ value: 100, color: '#FF0000' }],
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
render(<Value id='test-value' TypographyProps={{ className: 'custom' }} />)
|
|
198
|
+
const element = screen.getByText('100')
|
|
199
|
+
expect(element.classList.contains('custom')).toBe(true)
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test('color from data is passed to TypographyProps', () => {
|
|
203
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
204
|
+
type: 'formula',
|
|
205
|
+
data: [{ value: 100, color: 'primary' }],
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
render(<Value id='test-value' />)
|
|
209
|
+
const element = screen.getByText('100')
|
|
210
|
+
// Color is passed as a prop, not an HTML attribute
|
|
211
|
+
expect(element).toBeTruthy()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('handles all data properties together', () => {
|
|
215
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
216
|
+
type: 'formula',
|
|
217
|
+
data: [
|
|
218
|
+
{
|
|
219
|
+
value: 100,
|
|
220
|
+
color: '#FF0000',
|
|
221
|
+
prefix: '$',
|
|
222
|
+
suffix: 'USD',
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
render(<Value id='test-value' />)
|
|
228
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('updates when widget data changes', () => {
|
|
232
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
233
|
+
type: 'formula',
|
|
234
|
+
data: [{ value: 100 }],
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
const { rerender } = render(<Value id='test-value' />)
|
|
238
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
239
|
+
|
|
240
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
241
|
+
data: [{ value: 200 }],
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
rerender(<Value id='test-value' />)
|
|
245
|
+
expect(screen.queryByText('100')).toBeNull()
|
|
246
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
test('updates when index changes', () => {
|
|
250
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
251
|
+
type: 'formula',
|
|
252
|
+
data: [{ value: 100 }, { value: 200 }],
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
const { rerender } = render(<Value id='test-value' index={0} />)
|
|
256
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
257
|
+
|
|
258
|
+
rerender(<Value id='test-value' index={1} />)
|
|
259
|
+
expect(screen.queryByText('100')).toBeNull()
|
|
260
|
+
expect(screen.getByText('200')).toBeTruthy()
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test('handles widget removal gracefully', () => {
|
|
264
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
265
|
+
type: 'formula',
|
|
266
|
+
data: [{ value: 100 }],
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
const { container, rerender } = render(<Value id='test-value' />)
|
|
270
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
271
|
+
|
|
272
|
+
useWidgetStore.getState().removeWidget('test-value')
|
|
273
|
+
|
|
274
|
+
rerender(<Value id='test-value' />)
|
|
275
|
+
// Item still renders, but with undefined value
|
|
276
|
+
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('renders with multiple values at different indices', () => {
|
|
280
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
281
|
+
type: 'formula',
|
|
282
|
+
data: [
|
|
283
|
+
{ value: 100 },
|
|
284
|
+
{ value: 200 },
|
|
285
|
+
{ value: 300 },
|
|
286
|
+
{ value: 400 },
|
|
287
|
+
{ value: 500 },
|
|
288
|
+
],
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
const { unmount } = render(<Value id='test-value' index={0} />)
|
|
292
|
+
expect(screen.getByText('100')).toBeTruthy()
|
|
293
|
+
unmount()
|
|
294
|
+
|
|
295
|
+
render(<Value id='test-value' index={2} />)
|
|
296
|
+
expect(screen.getByText('300')).toBeTruthy()
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
test('handles negative index (invalid but should not crash)', () => {
|
|
300
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
301
|
+
type: 'formula',
|
|
302
|
+
data: [{ value: 100 }],
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
const { container } = render(<Value id='test-value' index={-1} />)
|
|
306
|
+
// Negative index is invalid, should render undefined
|
|
307
|
+
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
test('value with very small decimal', () => {
|
|
311
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
312
|
+
type: 'formula',
|
|
313
|
+
data: [{ value: 0.0001 }],
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
render(<Value id='test-value' />)
|
|
317
|
+
expect(screen.getByText('0.0001')).toBeTruthy()
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
test('value with scientific notation', () => {
|
|
321
|
+
useWidgetStore.getState().setWidget<FormulaWidgetState>('test-value', {
|
|
322
|
+
type: 'formula',
|
|
323
|
+
data: [{ value: 1e10 }],
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
render(<Value id='test-value' />)
|
|
327
|
+
expect(screen.getByText('10000000000')).toBeTruthy()
|
|
328
|
+
})
|
|
329
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type FormulaWidgetState, type ValueProps } from '../types'
|
|
2
|
+
import { useWidgetStore } from '../../stores/widget-store'
|
|
3
|
+
import { Item } from './item'
|
|
4
|
+
import { useShallow } from 'zustand/shallow'
|
|
5
|
+
|
|
6
|
+
const defaultFormatter = (value: number) => value.toString()
|
|
7
|
+
|
|
8
|
+
export function Value({ id, index = 0, ...props }: ValueProps) {
|
|
9
|
+
const {
|
|
10
|
+
value,
|
|
11
|
+
color,
|
|
12
|
+
formatter = defaultFormatter,
|
|
13
|
+
} = useWidgetStore(
|
|
14
|
+
useShallow((state) => {
|
|
15
|
+
const widget = state.getWidget<FormulaWidgetState>(id)
|
|
16
|
+
return {
|
|
17
|
+
value: widget?.data?.[index]?.value,
|
|
18
|
+
color: widget?.data?.[index]?.color,
|
|
19
|
+
formatter: widget?.formatter,
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Item TypographyProps={{ color }} {...props}>
|
|
26
|
+
{formatter(value ?? 0)}
|
|
27
|
+
</Item>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { downloadToCSV, downloadToPNG } from '../actions'
|
|
2
|
+
import type { ConfigProps } from '../loader/types'
|
|
3
|
+
import type { FormulaDownloadConfig, FormulaWidgetConfig } from './types'
|
|
4
|
+
|
|
5
|
+
export function formulaDownloadConfig({
|
|
6
|
+
refUI,
|
|
7
|
+
}: ConfigProps): FormulaDownloadConfig {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
...downloadToPNG,
|
|
11
|
+
modifier: () => downloadToPNG.modifier(refUI),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
...downloadToCSV,
|
|
15
|
+
modifier: async (data) => {
|
|
16
|
+
const formulaData = [data?.map((item) => item.value) ?? []]
|
|
17
|
+
return downloadToCSV.modifier(formulaData)
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function formulaConfig(): FormulaWidgetConfig {
|
|
24
|
+
return {
|
|
25
|
+
series: [],
|
|
26
|
+
}
|
|
27
|
+
}
|