@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,601 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { useWidgetStore } from './widget-store'
|
|
3
|
+
|
|
4
|
+
describe('WidgetStore', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
// Reset the store before each test
|
|
7
|
+
useWidgetStore.setState({
|
|
8
|
+
widgets: {},
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
describe('setWidget', () => {
|
|
13
|
+
it('should add a new widget to the store', () => {
|
|
14
|
+
const widgetId = 'test-widget'
|
|
15
|
+
|
|
16
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
17
|
+
type: 'formula',
|
|
18
|
+
title: 'Test Formula',
|
|
19
|
+
isLoading: false,
|
|
20
|
+
visible: true,
|
|
21
|
+
data: {
|
|
22
|
+
value: 100,
|
|
23
|
+
prefix: '$',
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const widgets = useWidgetStore.getState().widgets
|
|
28
|
+
expect(widgets[widgetId]).toBeDefined()
|
|
29
|
+
expect(widgets[widgetId]?.id).toBe(widgetId)
|
|
30
|
+
expect(widgets[widgetId]?.type).toBe('formula')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should update an existing widget', () => {
|
|
34
|
+
const widgetId = 'test-widget'
|
|
35
|
+
|
|
36
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
37
|
+
type: 'formula',
|
|
38
|
+
title: 'Test Formula',
|
|
39
|
+
isLoading: false,
|
|
40
|
+
visible: true,
|
|
41
|
+
data: {
|
|
42
|
+
value: 100,
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
47
|
+
title: 'Updated Formula',
|
|
48
|
+
data: {
|
|
49
|
+
value: 200,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const widgets = useWidgetStore.getState().widgets
|
|
54
|
+
expect((widgets[widgetId]?.data as { value: number })?.value).toBe(200)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should handle multiple widgets', () => {
|
|
58
|
+
useWidgetStore.getState().setWidget('widget-1', {
|
|
59
|
+
type: 'formula',
|
|
60
|
+
isLoading: false,
|
|
61
|
+
visible: true,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
useWidgetStore.getState().setWidget('widget-2', {
|
|
65
|
+
type: 'bar',
|
|
66
|
+
isLoading: false,
|
|
67
|
+
visible: true,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const widgets = useWidgetStore.getState().widgets
|
|
71
|
+
expect(Object.keys(widgets)).toHaveLength(2)
|
|
72
|
+
expect(widgets['widget-1']).toBeDefined()
|
|
73
|
+
expect(widgets['widget-2']).toBeDefined()
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('removeWidget', () => {
|
|
78
|
+
it('should remove a widget from the store', () => {
|
|
79
|
+
const widgetId = 'test-widget'
|
|
80
|
+
|
|
81
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
82
|
+
type: 'formula',
|
|
83
|
+
isLoading: false,
|
|
84
|
+
visible: true,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
expect(useWidgetStore.getState().widgets[widgetId]).toBeDefined()
|
|
88
|
+
|
|
89
|
+
useWidgetStore.getState().removeWidget(widgetId)
|
|
90
|
+
expect(useWidgetStore.getState().widgets[widgetId]).toBeUndefined()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should handle removing non-existent widget gracefully', () => {
|
|
94
|
+
useWidgetStore.getState().removeWidget('non-existent')
|
|
95
|
+
expect(useWidgetStore.getState().widgets).toEqual({})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('should only remove the specified widget', () => {
|
|
99
|
+
useWidgetStore.getState().setWidget('widget-1', {
|
|
100
|
+
type: 'formula',
|
|
101
|
+
isLoading: false,
|
|
102
|
+
visible: true,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
useWidgetStore.getState().setWidget('widget-2', {
|
|
106
|
+
type: 'formula',
|
|
107
|
+
isLoading: false,
|
|
108
|
+
visible: true,
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
useWidgetStore.getState().removeWidget('widget-1')
|
|
112
|
+
|
|
113
|
+
const widgets = useWidgetStore.getState().widgets
|
|
114
|
+
expect(widgets['widget-1']).toBeUndefined()
|
|
115
|
+
expect(widgets['widget-2']).toBeDefined()
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('clearWidgets', () => {
|
|
120
|
+
it('should remove all widgets', () => {
|
|
121
|
+
useWidgetStore.getState().setWidget('widget-1', {
|
|
122
|
+
type: 'formula',
|
|
123
|
+
isLoading: false,
|
|
124
|
+
visible: true,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
useWidgetStore.getState().setWidget('widget-2', {
|
|
128
|
+
type: 'bar',
|
|
129
|
+
isLoading: false,
|
|
130
|
+
visible: true,
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
expect(Object.keys(useWidgetStore.getState().widgets)).toHaveLength(2)
|
|
134
|
+
|
|
135
|
+
useWidgetStore.getState().clearWidgets()
|
|
136
|
+
|
|
137
|
+
expect(useWidgetStore.getState().widgets).toEqual({})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('should work on empty store', () => {
|
|
141
|
+
useWidgetStore.getState().clearWidgets()
|
|
142
|
+
expect(useWidgetStore.getState().widgets).toEqual({})
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('getWidget', () => {
|
|
147
|
+
it('should get a widget by id', () => {
|
|
148
|
+
const widgetId = 'test-widget'
|
|
149
|
+
|
|
150
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
151
|
+
type: 'formula',
|
|
152
|
+
title: 'Test Widget',
|
|
153
|
+
isLoading: false,
|
|
154
|
+
visible: true,
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
158
|
+
expect(widget).toBeDefined()
|
|
159
|
+
expect(widget?.id).toBe(widgetId)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('should return undefined for non-existent widget', () => {
|
|
163
|
+
const widget = useWidgetStore.getState().getWidget('non-existent')
|
|
164
|
+
expect(widget).toBeUndefined()
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
describe('unknown type data handling', () => {
|
|
169
|
+
it('should handle widget with unknown type and data structure', () => {
|
|
170
|
+
const widgetId = 'custom-widget'
|
|
171
|
+
|
|
172
|
+
// Example: A custom widget type with arbitrary data
|
|
173
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
174
|
+
type: 'custom',
|
|
175
|
+
title: 'Custom Widget',
|
|
176
|
+
isLoading: false,
|
|
177
|
+
visible: true,
|
|
178
|
+
data: {
|
|
179
|
+
customField: 'value',
|
|
180
|
+
nestedData: {
|
|
181
|
+
foo: 'bar',
|
|
182
|
+
count: 42,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
188
|
+
expect(widget).toBeDefined()
|
|
189
|
+
expect(widget?.type).toBe('custom')
|
|
190
|
+
|
|
191
|
+
// Type assertion needed when accessing unknown data
|
|
192
|
+
const customData = widget?.data as {
|
|
193
|
+
customField: string
|
|
194
|
+
nestedData: { foo: string; count: number }
|
|
195
|
+
}
|
|
196
|
+
expect(customData?.customField).toBe('value')
|
|
197
|
+
expect(customData?.nestedData?.foo).toBe('bar')
|
|
198
|
+
expect(customData?.nestedData?.count).toBe(42)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('should handle widget updates with different data structures', () => {
|
|
202
|
+
const widgetId = 'flexible-widget'
|
|
203
|
+
|
|
204
|
+
// Initial data structure
|
|
205
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
206
|
+
type: 'dynamic',
|
|
207
|
+
isLoading: false,
|
|
208
|
+
visible: true,
|
|
209
|
+
data: {
|
|
210
|
+
format: 'json',
|
|
211
|
+
content: { items: [] },
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
// Update with different data structure
|
|
216
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
217
|
+
data: {
|
|
218
|
+
format: 'text',
|
|
219
|
+
content: 'Plain text content',
|
|
220
|
+
metadata: {
|
|
221
|
+
length: 18,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
227
|
+
const widgetData = widget?.data as {
|
|
228
|
+
format: string
|
|
229
|
+
content: string
|
|
230
|
+
metadata: { length: number }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
expect(widgetData?.format).toBe('text')
|
|
234
|
+
expect(widgetData?.content).toBe('Plain text content')
|
|
235
|
+
expect(widgetData?.metadata?.length).toBe(18)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('should handle complex nested unknown data', () => {
|
|
239
|
+
const widgetId = 'complex-widget'
|
|
240
|
+
|
|
241
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
242
|
+
type: 'analytics',
|
|
243
|
+
title: 'Analytics Dashboard',
|
|
244
|
+
isLoading: false,
|
|
245
|
+
visible: true,
|
|
246
|
+
data: {
|
|
247
|
+
metrics: [
|
|
248
|
+
{ name: 'revenue', value: 1000, trend: 'up' },
|
|
249
|
+
{ name: 'users', value: 500, trend: 'down' },
|
|
250
|
+
],
|
|
251
|
+
timeRange: {
|
|
252
|
+
start: '2025-01-01',
|
|
253
|
+
end: '2025-01-31',
|
|
254
|
+
},
|
|
255
|
+
settings: {
|
|
256
|
+
displayMode: 'chart',
|
|
257
|
+
refreshInterval: 5000,
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
263
|
+
|
|
264
|
+
// Type assertion for complex unknown data
|
|
265
|
+
const analyticsData = widget?.data as {
|
|
266
|
+
metrics: { name: string; value: number; trend: string }[]
|
|
267
|
+
timeRange: { start: string; end: string }
|
|
268
|
+
settings: { displayMode: string; refreshInterval: number }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
expect(analyticsData.metrics).toHaveLength(2)
|
|
272
|
+
expect(analyticsData.metrics[0]?.name).toBe('revenue')
|
|
273
|
+
expect(analyticsData.metrics[0]?.value).toBe(1000)
|
|
274
|
+
expect(analyticsData.timeRange.start).toBe('2025-01-01')
|
|
275
|
+
expect(analyticsData.settings.displayMode).toBe('chart')
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
it('should handle widget with no data', () => {
|
|
279
|
+
const widgetId = 'no-data-widget'
|
|
280
|
+
|
|
281
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
282
|
+
type: 'placeholder',
|
|
283
|
+
title: 'Empty Widget',
|
|
284
|
+
isLoading: false,
|
|
285
|
+
visible: true,
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
289
|
+
expect(widget?.data).toBeUndefined()
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
it('should preserve unknown type through updates', () => {
|
|
293
|
+
const widgetId = 'type-test-widget'
|
|
294
|
+
|
|
295
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
296
|
+
type: 'special-type-123',
|
|
297
|
+
isLoading: false,
|
|
298
|
+
visible: true,
|
|
299
|
+
data: { initial: true },
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
303
|
+
title: 'Updated Title',
|
|
304
|
+
data: { updated: true },
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
308
|
+
expect(widget?.type).toBe('special-type-123')
|
|
309
|
+
})
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
describe('isFetching property', () => {
|
|
313
|
+
it('should set isFetching on a new widget', () => {
|
|
314
|
+
const widgetId = 'fetching-widget'
|
|
315
|
+
|
|
316
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
317
|
+
type: 'formula',
|
|
318
|
+
title: 'Fetching Widget',
|
|
319
|
+
isLoading: false,
|
|
320
|
+
isFetching: true,
|
|
321
|
+
visible: true,
|
|
322
|
+
data: { value: 100 },
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
326
|
+
expect(widget?.isFetching).toBe(true)
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
it('should update isFetching on an existing widget', () => {
|
|
330
|
+
const widgetId = 'update-fetching-widget'
|
|
331
|
+
|
|
332
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
333
|
+
type: 'formula',
|
|
334
|
+
isLoading: false,
|
|
335
|
+
isFetching: false,
|
|
336
|
+
visible: true,
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
expect(useWidgetStore.getState().getWidget(widgetId)?.isFetching).toBe(
|
|
340
|
+
false,
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
344
|
+
isFetching: true,
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
expect(useWidgetStore.getState().getWidget(widgetId)?.isFetching).toBe(
|
|
348
|
+
true,
|
|
349
|
+
)
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it('should handle undefined isFetching (optional property)', () => {
|
|
353
|
+
const widgetId = 'no-fetching-widget'
|
|
354
|
+
|
|
355
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
356
|
+
type: 'formula',
|
|
357
|
+
isLoading: false,
|
|
358
|
+
visible: true,
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
362
|
+
expect(widget?.isFetching).toBeUndefined()
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
it('should handle different combinations of isLoading and isFetching', () => {
|
|
366
|
+
const widgetId = 'state-combination-widget'
|
|
367
|
+
|
|
368
|
+
// Both false
|
|
369
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
370
|
+
type: 'formula',
|
|
371
|
+
isLoading: false,
|
|
372
|
+
isFetching: false,
|
|
373
|
+
visible: true,
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
let widget = useWidgetStore.getState().getWidget(widgetId)
|
|
377
|
+
expect(widget?.isLoading).toBe(false)
|
|
378
|
+
expect(widget?.isFetching).toBe(false)
|
|
379
|
+
|
|
380
|
+
// Loading true, fetching false
|
|
381
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
382
|
+
isLoading: true,
|
|
383
|
+
isFetching: false,
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
widget = useWidgetStore.getState().getWidget(widgetId)
|
|
387
|
+
expect(widget?.isLoading).toBe(true)
|
|
388
|
+
expect(widget?.isFetching).toBe(false)
|
|
389
|
+
|
|
390
|
+
// Loading false, fetching true
|
|
391
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
392
|
+
isLoading: false,
|
|
393
|
+
isFetching: true,
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
widget = useWidgetStore.getState().getWidget(widgetId)
|
|
397
|
+
expect(widget?.isLoading).toBe(false)
|
|
398
|
+
expect(widget?.isFetching).toBe(true)
|
|
399
|
+
|
|
400
|
+
// Both true
|
|
401
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
402
|
+
isLoading: true,
|
|
403
|
+
isFetching: true,
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
widget = useWidgetStore.getState().getWidget(widgetId)
|
|
407
|
+
expect(widget?.isLoading).toBe(true)
|
|
408
|
+
expect(widget?.isFetching).toBe(true)
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
it('should toggle isFetching multiple times', () => {
|
|
412
|
+
const widgetId = 'toggle-fetching-widget'
|
|
413
|
+
|
|
414
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
415
|
+
type: 'formula',
|
|
416
|
+
isLoading: false,
|
|
417
|
+
isFetching: false,
|
|
418
|
+
visible: true,
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
expect(useWidgetStore.getState().getWidget(widgetId)?.isFetching).toBe(
|
|
422
|
+
false,
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
useWidgetStore.getState().setWidget(widgetId, { isFetching: true })
|
|
426
|
+
expect(useWidgetStore.getState().getWidget(widgetId)?.isFetching).toBe(
|
|
427
|
+
true,
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
useWidgetStore.getState().setWidget(widgetId, { isFetching: false })
|
|
431
|
+
expect(useWidgetStore.getState().getWidget(widgetId)?.isFetching).toBe(
|
|
432
|
+
false,
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
useWidgetStore.getState().setWidget(widgetId, { isFetching: true })
|
|
436
|
+
expect(useWidgetStore.getState().getWidget(widgetId)?.isFetching).toBe(
|
|
437
|
+
true,
|
|
438
|
+
)
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
it('should preserve isFetching when updating other properties', () => {
|
|
442
|
+
const widgetId = 'preserve-fetching-widget'
|
|
443
|
+
|
|
444
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
445
|
+
type: 'formula',
|
|
446
|
+
title: 'Original Title',
|
|
447
|
+
isLoading: false,
|
|
448
|
+
isFetching: true,
|
|
449
|
+
visible: true,
|
|
450
|
+
data: { value: 100 },
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
expect(useWidgetStore.getState().getWidget(widgetId)?.isFetching).toBe(
|
|
454
|
+
true,
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
useWidgetStore.getState().setWidget(widgetId, {
|
|
458
|
+
title: 'Updated Title',
|
|
459
|
+
data: { value: 200 },
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
const widget = useWidgetStore.getState().getWidget(widgetId)
|
|
463
|
+
expect(widget?.isFetching).toBe(true)
|
|
464
|
+
expect((widget?.data as { value: number })?.value).toBe(200)
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
describe('Tool Dependency Management', () => {
|
|
469
|
+
const widgetId = 'test-widget-deps'
|
|
470
|
+
|
|
471
|
+
beforeEach(() => {
|
|
472
|
+
useWidgetStore.getState().clearWidgets()
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
describe('Pipeline Filtering', () => {
|
|
476
|
+
it('skips tools disabled by other enabled tools', async () => {
|
|
477
|
+
const executionOrder: string[] = []
|
|
478
|
+
|
|
479
|
+
const toolA: import('./types').ToolRegistration = {
|
|
480
|
+
id: 'tool-a',
|
|
481
|
+
order: 10,
|
|
482
|
+
enabled: true,
|
|
483
|
+
fn: (data) => {
|
|
484
|
+
executionOrder.push('tool-a')
|
|
485
|
+
return data
|
|
486
|
+
},
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const toolB: import('./types').ToolRegistration = {
|
|
490
|
+
id: 'tool-b',
|
|
491
|
+
order: 20,
|
|
492
|
+
enabled: true,
|
|
493
|
+
fn: (data) => {
|
|
494
|
+
executionOrder.push('tool-b')
|
|
495
|
+
return data
|
|
496
|
+
},
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const toolC: import('./types').ToolRegistration = {
|
|
500
|
+
id: 'tool-c',
|
|
501
|
+
order: 30,
|
|
502
|
+
enabled: true,
|
|
503
|
+
fn: (data) => {
|
|
504
|
+
executionOrder.push('tool-c')
|
|
505
|
+
return data
|
|
506
|
+
},
|
|
507
|
+
disables: ['tool-b'],
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
useWidgetStore.getState().registerTool(widgetId, toolA)
|
|
511
|
+
useWidgetStore.getState().registerTool(widgetId, toolB)
|
|
512
|
+
useWidgetStore.getState().registerTool(widgetId, toolC)
|
|
513
|
+
|
|
514
|
+
await useWidgetStore.getState().executeToolPipeline(widgetId, {})
|
|
515
|
+
|
|
516
|
+
// tool-b should be skipped because tool-c disables it
|
|
517
|
+
expect(executionOrder).toEqual(['tool-a', 'tool-c'])
|
|
518
|
+
expect(executionOrder).not.toContain('tool-b')
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
it('includes tool when disabling tool is not enabled', async () => {
|
|
522
|
+
const executionOrder: string[] = []
|
|
523
|
+
|
|
524
|
+
const toolA: import('./types').ToolRegistration = {
|
|
525
|
+
id: 'tool-a',
|
|
526
|
+
order: 10,
|
|
527
|
+
enabled: true,
|
|
528
|
+
fn: (data) => {
|
|
529
|
+
executionOrder.push('tool-a')
|
|
530
|
+
return data
|
|
531
|
+
},
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const toolB: import('./types').ToolRegistration = {
|
|
535
|
+
id: 'tool-b',
|
|
536
|
+
order: 20,
|
|
537
|
+
enabled: false, // Disabled
|
|
538
|
+
fn: (data) => {
|
|
539
|
+
executionOrder.push('tool-b')
|
|
540
|
+
return data
|
|
541
|
+
},
|
|
542
|
+
disables: ['tool-a'],
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
useWidgetStore.getState().registerTool(widgetId, toolA)
|
|
546
|
+
useWidgetStore.getState().registerTool(widgetId, toolB)
|
|
547
|
+
|
|
548
|
+
await useWidgetStore.getState().executeToolPipeline(widgetId, {})
|
|
549
|
+
|
|
550
|
+
// tool-a should execute because tool-b is disabled
|
|
551
|
+
expect(executionOrder).toEqual(['tool-a'])
|
|
552
|
+
})
|
|
553
|
+
|
|
554
|
+
it('handles multiple tools disabling the same target', async () => {
|
|
555
|
+
const executionOrder: string[] = []
|
|
556
|
+
|
|
557
|
+
const toolA: import('./types').ToolRegistration = {
|
|
558
|
+
id: 'tool-a',
|
|
559
|
+
order: 10,
|
|
560
|
+
enabled: true,
|
|
561
|
+
fn: (data) => {
|
|
562
|
+
executionOrder.push('tool-a')
|
|
563
|
+
return data
|
|
564
|
+
},
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const toolB: import('./types').ToolRegistration = {
|
|
568
|
+
id: 'tool-b',
|
|
569
|
+
order: 20,
|
|
570
|
+
enabled: true,
|
|
571
|
+
fn: (data) => {
|
|
572
|
+
executionOrder.push('tool-b')
|
|
573
|
+
return data
|
|
574
|
+
},
|
|
575
|
+
disables: ['tool-a'],
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const toolC: import('./types').ToolRegistration = {
|
|
579
|
+
id: 'tool-c',
|
|
580
|
+
order: 30,
|
|
581
|
+
enabled: true,
|
|
582
|
+
fn: (data) => {
|
|
583
|
+
executionOrder.push('tool-c')
|
|
584
|
+
return data
|
|
585
|
+
},
|
|
586
|
+
disables: ['tool-a'],
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
useWidgetStore.getState().registerTool(widgetId, toolA)
|
|
590
|
+
useWidgetStore.getState().registerTool(widgetId, toolB)
|
|
591
|
+
useWidgetStore.getState().registerTool(widgetId, toolC)
|
|
592
|
+
|
|
593
|
+
await useWidgetStore.getState().executeToolPipeline(widgetId, {})
|
|
594
|
+
|
|
595
|
+
// tool-a should be skipped (disabled by both tool-b and tool-c)
|
|
596
|
+
expect(executionOrder).toEqual(['tool-b', 'tool-c'])
|
|
597
|
+
expect(executionOrder).not.toContain('tool-a')
|
|
598
|
+
})
|
|
599
|
+
})
|
|
600
|
+
})
|
|
601
|
+
})
|