niuma-ui 1.0.1 → 1.1.0
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/CHANGELOG.md +65 -1
- package/package.json +10 -2
- package/src/__tests__/RsButton.spec.ts +47 -0
- package/src/__tests__/RsCard.spec.ts +160 -1
- package/src/__tests__/RsConfirmDialog.spec.ts +127 -0
- package/src/__tests__/RsContextMenu.spec.ts +12 -0
- package/src/__tests__/RsDatePicker.spec.ts +21 -0
- package/src/__tests__/RsDateTimePicker.spec.ts +11 -0
- package/src/__tests__/RsDescriptions.spec.ts +50 -0
- package/src/__tests__/RsDialog.spec.ts +178 -0
- package/src/__tests__/RsDrawer.spec.ts +96 -3
- package/src/__tests__/RsDynamicTags.spec.ts +52 -0
- package/src/__tests__/RsForm.spec.ts +250 -6
- package/src/__tests__/RsFormItem.spec.ts +478 -0
- package/src/__tests__/RsFormList.spec.ts +109 -0
- package/src/__tests__/RsInput.spec.ts +108 -1
- package/src/__tests__/RsInputNumber.spec.ts +33 -0
- package/src/__tests__/RsMenu.spec.ts +406 -14
- package/src/__tests__/RsPagination.spec.ts +67 -2
- package/src/__tests__/RsSelect.spec.ts +465 -2
- package/src/__tests__/RsSwitch.spec.ts +74 -0
- package/src/__tests__/RsTable.a11y.spec.ts +83 -0
- package/src/__tests__/RsTable.dom-baseline.spec.ts +87 -0
- package/src/__tests__/RsTable.perf.spec.ts +23 -4
- package/src/__tests__/RsTable.spec.ts +63 -8
- package/src/__tests__/RsTable.ssr.spec.ts +71 -0
- package/src/__tests__/RsTable.summary.spec.ts +45 -0
- package/src/__tests__/RsTabs.spec.ts +102 -4
- package/src/__tests__/RsTimePicker.spec.ts +20 -0
- package/src/__tests__/RsTooltip.spec.ts +43 -0
- package/src/__tests__/RsUpload.spec.ts +62 -6
- package/src/__tests__/createRsDialog.spec.ts +145 -0
- package/src/__tests__/css-token.spec.ts +51 -0
- package/src/__tests__/date-picker-utils.spec.ts +49 -0
- package/src/__tests__/dialog-utils.spec.ts +43 -0
- package/src/__tests__/form-path.spec.ts +46 -0
- package/src/__tests__/form-rules.spec.ts +139 -0
- package/src/__tests__/perf-budgets.ts +32 -0
- package/src/__tests__/rs-table-api.spec.ts +206 -0
- package/src/__tests__/rs-table-compat-matrix.spec.ts +108 -0
- package/src/__tests__/rs-table-echarts-adapter.spec.ts +43 -0
- package/src/__tests__/rs-table-grid-nav.spec.ts +63 -0
- package/src/__tests__/rs-table-isolation.spec.ts +158 -0
- package/src/__tests__/split-pane-utils.spec.ts +21 -0
- package/src/__tests__/table-chart-utils.spec.ts +88 -0
- package/src/__tests__/table-summary-utils.spec.ts +62 -0
- package/src/__tests__/table-utils.spec.ts +124 -0
- package/src/__tests__/theme.spec.ts +27 -0
- package/src/__tests__/useRsTableColumnResize.spec.ts +25 -0
- package/src/__tests__/useRsTableCore.perf.spec.ts +170 -0
- package/src/components/RsAlert.vue +212 -0
- package/src/components/RsAvatar.vue +1 -1
- package/src/components/RsBadge.vue +1 -1
- package/src/components/RsBreadcrumb.vue +1 -1
- package/src/components/RsButton.vue +147 -23
- package/src/components/RsCalendarGrid.vue +3 -3
- package/src/components/RsCard.vue +204 -20
- package/src/components/RsCodeBlock.vue +4 -4
- package/src/components/RsCodeEditor.vue +8 -8
- package/src/components/RsConfirmDialog.vue +217 -30
- package/src/components/RsContextMenu.vue +57 -17
- package/src/components/RsDatePicker.vue +316 -39
- package/src/components/RsDateTimePicker.vue +27 -2
- package/src/components/RsDescriptions.vue +186 -0
- package/src/components/RsDescriptionsItem.vue +32 -0
- package/src/components/RsDialog.vue +374 -52
- package/src/components/RsDivider.vue +89 -0
- package/src/components/RsDrawer.vue +559 -34
- package/src/components/RsDropdown.vue +34 -3
- package/src/components/RsDynamicTags.vue +531 -0
- package/src/components/RsEmpty.vue +1 -1
- package/src/components/RsForm.vue +164 -8
- package/src/components/RsFormItem.vue +423 -0
- package/src/components/RsFormItemControl.vue +21 -0
- package/src/components/RsFormList.vue +117 -0
- package/src/components/RsInput.vue +491 -100
- package/src/components/RsInputNumber.vue +77 -27
- package/src/components/RsLabel.vue +20 -5
- package/src/components/RsLink.vue +1 -1
- package/src/components/RsLoadingBar.vue +151 -0
- package/src/components/RsMarkdown.vue +5 -5
- package/src/components/RsMenu.vue +74 -16
- package/src/components/RsMenuItems.vue +147 -9
- package/src/components/RsMonacoEditor.vue +9 -3
- package/src/components/RsPagination.vue +93 -14
- package/src/components/RsProseEditor.vue +3 -3
- package/src/components/RsRadio.vue +81 -0
- package/src/components/RsRadioItem.vue +156 -0
- package/src/components/RsSelect.vue +372 -642
- package/src/components/RsSidebarGroup.vue +1 -1
- package/src/components/RsSplitPane.vue +90 -1
- package/src/components/RsStatCard.vue +2 -2
- package/src/components/RsSteps.vue +2 -2
- package/src/components/RsSwitch.vue +192 -0
- package/src/components/RsTable.vue +653 -2555
- package/src/components/RsTabs.vue +422 -90
- package/src/components/RsTag.vue +191 -0
- package/src/components/RsTerminal.vue +58 -19
- package/src/components/RsTimePicker.vue +72 -9
- package/src/components/RsTimePickerColumns.vue +137 -78
- package/src/components/RsToaster.vue +64 -24
- package/src/components/RsTooltip.vue +10 -1
- package/src/components/RsTooltipProvider.vue +11 -1
- package/src/components/RsTree.vue +45 -27
- package/src/components/RsUpload.vue +147 -14
- package/src/components/RsVNodeHost.vue +20 -0
- package/src/components/button-utils.ts +39 -0
- package/src/components/context-menu-utils.ts +6 -0
- package/src/components/date-picker-utils.ts +195 -4
- package/src/components/descriptions-utils.ts +24 -0
- package/src/components/dialog-utils.ts +182 -0
- package/src/components/dialog-window.ts +74 -9
- package/src/components/drawer-utils.ts +73 -0
- package/src/components/form-item-control.ts +55 -0
- package/src/components/form-path.ts +92 -0
- package/src/components/form-rules.ts +311 -0
- package/src/components/form-utils.ts +145 -3
- package/src/components/menu-utils.ts +11 -0
- package/src/components/overlay-utils.ts +3 -0
- package/src/components/radio-utils.ts +12 -0
- package/src/components/reka.ts +5 -0
- package/src/components/select-utils.ts +285 -6
- package/src/components/split-pane-utils.ts +65 -12
- package/src/components/table/RsTableBody.vue +217 -0
- package/src/components/table/RsTableBodyRow.vue +90 -1
- package/src/components/table/RsTableColGroup.vue +41 -0
- package/src/components/table/RsTableHeader.vue +158 -0
- package/src/components/table/RsTableHeaderFilter.vue +1 -1
- package/src/components/table/RsTableSummaryRow.vue +52 -0
- package/src/components/table/rs-table-api.ts +99 -0
- package/src/components/table/rs-table-compat-matrix.ts +71 -0
- package/src/components/table/rs-table-echarts-adapter.ts +81 -0
- package/src/components/table/rs-table-feature-host.ts +178 -0
- package/src/components/table/rs-table-grid-nav.ts +122 -0
- package/src/components/table/rs-table-header-types.ts +47 -0
- package/src/components/table/rs-table-module-registry.ts +72 -0
- package/src/components/table/rs-table-props.ts +274 -0
- package/src/components/table/rs-table-view-context.ts +258 -0
- package/src/components/table/rs-table.css +85 -7
- package/src/components/table/table-chart-utils.ts +165 -0
- package/src/components/table/table-features.ts +284 -0
- package/src/components/table/table-summary-utils.ts +194 -0
- package/src/components/table-utils.ts +452 -2
- package/src/components/tabs-utils.ts +142 -2
- package/src/components/time-picker-utils.ts +76 -3
- package/src/components/upload-utils.ts +122 -0
- package/src/components/use-rs-select.ts +436 -0
- package/src/components/virtual-list-utils.ts +15 -2
- package/src/composables/assembleRsTableApi.ts +79 -0
- package/src/composables/bindRsTableViewContext.ts +269 -0
- package/src/composables/createRsDialog.ts +357 -0
- package/src/composables/createRsTableEditEmitBridge.ts +38 -0
- package/src/composables/useRsConfig.ts +10 -3
- package/src/composables/useRsI18n.ts +16 -5
- package/src/composables/useRsLoadingBar.ts +36 -0
- package/src/composables/useRsTable.ts +134 -0
- package/src/composables/useRsTableA11y.ts +52 -0
- package/src/composables/useRsTableChartBridge.ts +79 -0
- package/src/composables/useRsTableColumnLayout.ts +320 -0
- package/src/composables/useRsTableColumnResize.ts +244 -0
- package/src/composables/useRsTableColumnVirtual.ts +180 -0
- package/src/composables/useRsTableColumns.ts +200 -0
- package/src/composables/useRsTableContextMenu.ts +257 -0
- package/src/composables/useRsTableCore.ts +256 -0
- package/src/composables/useRsTableEditActions.ts +606 -0
- package/src/composables/useRsTableEditLayer.ts +251 -0
- package/src/composables/useRsTableEngine.ts +357 -0
- package/src/composables/useRsTableGridKeyboard.ts +123 -0
- package/src/composables/useRsTableHeadless.ts +137 -0
- package/src/composables/useRsTableInteraction.ts +433 -0
- package/src/composables/useRsTableScrollHost.ts +75 -0
- package/src/composables/useRsTableScrollLayout.ts +255 -0
- package/src/composables/useRsTableSelectionSource.ts +89 -0
- package/src/composables/useRsTableShell.ts +416 -0
- package/src/composables/useRsTableShellChrome.ts +170 -0
- package/src/composables/useRsTableSummary.ts +113 -0
- package/src/composables/useRsTableViewProvide.ts +263 -0
- package/src/composables/useRsTableVirtual.ts +154 -0
- package/src/composables/useRsTabsNav.ts +4 -0
- package/src/composables/useTableEdit.ts +1 -1
- package/src/index.ts +378 -10
- package/src/locale/interpolate.ts +32 -0
- package/src/locale/messages.ts +40 -0
- package/src/styles.css +365 -56
- package/src/theme/brand.example.css +24 -2
- package/src/theme/css-token.ts +107 -0
- package/src/theme/presets.ts +4 -0
- package/src/theme/types.ts +68 -0
- package/src/components/RsTableColgroup.vue +0 -17
- package/src/components/RsTableHeaderRow.vue +0 -30
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils'
|
|
2
|
+
import { describe, expect, it, beforeEach } from 'vitest'
|
|
3
|
+
import RsTable from '../components/RsTable.vue'
|
|
4
|
+
import { createRsTableApi, isRsTableApi, RS_TABLE_API_VERSION } from '../components/table/rs-table-api'
|
|
5
|
+
import { createRsTableFeatureHost } from '../components/table/rs-table-feature-host'
|
|
6
|
+
import { RsTableModuleRegistry, resolveInstanceFeatures } from '../components/table/rs-table-module-registry'
|
|
7
|
+
import {
|
|
8
|
+
createAnalyticsTableFeature,
|
|
9
|
+
createChartSeriesTableFeature,
|
|
10
|
+
createContextMenuTableFeature,
|
|
11
|
+
} from '../components/table/table-features'
|
|
12
|
+
import type { RsTableRowData } from '../components/table-utils'
|
|
13
|
+
import { useRsTable } from '../composables/useRsTable'
|
|
14
|
+
|
|
15
|
+
type Row = RsTableRowData & { id: string; name: string }
|
|
16
|
+
|
|
17
|
+
function stubAnalytics() {
|
|
18
|
+
return {
|
|
19
|
+
getViewRows: () => [] as Row[],
|
|
20
|
+
getSelectedRows: () => [] as Row[],
|
|
21
|
+
getAnalyticsSnapshot: () => ({
|
|
22
|
+
sourceRows: [] as Row[],
|
|
23
|
+
viewRows: [] as Row[],
|
|
24
|
+
selectedRows: [] as Row[],
|
|
25
|
+
sourceMode: 'view' as const,
|
|
26
|
+
selectedCount: 0,
|
|
27
|
+
viewCount: 0,
|
|
28
|
+
}),
|
|
29
|
+
subscribeAnalytics: () => () => undefined,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('RsTableApi / FeatureHost / ModuleRegistry', () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
RsTableModuleRegistry.clear()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('createRsTableApi 冻结 apiVersion 与查询方法', () => {
|
|
39
|
+
const api = createRsTableApi<Row>({
|
|
40
|
+
getRowByKey: () => undefined,
|
|
41
|
+
getRowByIndex: () => undefined,
|
|
42
|
+
getColumnValues: () => [],
|
|
43
|
+
getCellValue: () => undefined,
|
|
44
|
+
getViewRows: () => [],
|
|
45
|
+
getSelectedRows: () => [],
|
|
46
|
+
getSelectedRowKeys: () => [],
|
|
47
|
+
getAnalyticsSnapshot: stubAnalytics().getAnalyticsSnapshot,
|
|
48
|
+
subscribeAnalytics: stubAnalytics().subscribeAnalytics,
|
|
49
|
+
getHighlightedRowKey: () => undefined,
|
|
50
|
+
setHighlightedRowKey: () => undefined,
|
|
51
|
+
cancelCellEdit: () => undefined,
|
|
52
|
+
cancelAllEdits: () => undefined,
|
|
53
|
+
getDirtyCellKeys: () => [],
|
|
54
|
+
getCellError: () => undefined,
|
|
55
|
+
setCellError: () => undefined,
|
|
56
|
+
stageCell: () => undefined,
|
|
57
|
+
rejectRowEdit: () => undefined,
|
|
58
|
+
undoEdit: () => undefined,
|
|
59
|
+
redoEdit: () => undefined,
|
|
60
|
+
commitRowEdits: () => undefined,
|
|
61
|
+
rollbackRowEdits: () => undefined,
|
|
62
|
+
})
|
|
63
|
+
expect(api.apiVersion).toBe(RS_TABLE_API_VERSION)
|
|
64
|
+
expect(isRsTableApi(api)).toBe(true)
|
|
65
|
+
expect(isRsTableApi({})).toBe(false)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('FeatureHost 收集 contextMenu 贡献并 merge', () => {
|
|
69
|
+
const host = createRsTableFeatureHost<Row>()
|
|
70
|
+
const ctx = host.createContext(stubAnalytics())
|
|
71
|
+
host.setup(
|
|
72
|
+
[
|
|
73
|
+
{
|
|
74
|
+
id: 'export-row',
|
|
75
|
+
setup(featureCtx) {
|
|
76
|
+
featureCtx.contributeContextMenuItems?.((items) => {
|
|
77
|
+
items.push({ key: 'export', label: '导出' })
|
|
78
|
+
})
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
ctx,
|
|
83
|
+
)
|
|
84
|
+
const merged = host.mergeContextMenuItems(
|
|
85
|
+
[{ key: 'copy', label: '复制' }],
|
|
86
|
+
{ row: null, selectedRows: [] },
|
|
87
|
+
)
|
|
88
|
+
expect(merged.map((i) => i.key)).toEqual(['copy', '__ctx-feature-sep', 'export'])
|
|
89
|
+
expect(host.getActiveFeatureIds()).toEqual(['export-row'])
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('ModuleRegistry 全局注册并被 resolveInstanceFeatures 合并', () => {
|
|
93
|
+
const analytics = createAnalyticsTableFeature<Row>({
|
|
94
|
+
onSnapshot: () => undefined,
|
|
95
|
+
})
|
|
96
|
+
RsTableModuleRegistry.register(analytics)
|
|
97
|
+
expect(RsTableModuleRegistry.listIds()).toContain('analytics')
|
|
98
|
+
|
|
99
|
+
const resolved = resolveInstanceFeatures<Row>([
|
|
100
|
+
{ id: 'local', setup() {} },
|
|
101
|
+
])
|
|
102
|
+
expect(resolved.map((f) => f.id).sort()).toEqual(['analytics', 'local'])
|
|
103
|
+
|
|
104
|
+
const override = resolveInstanceFeatures<Row>([
|
|
105
|
+
{
|
|
106
|
+
id: 'analytics',
|
|
107
|
+
setup() {},
|
|
108
|
+
},
|
|
109
|
+
])
|
|
110
|
+
expect(override.find((f) => f.id === 'analytics')?.setup).not.toBe(analytics.setup)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('useRsTable.bindFeatures 合并内置与全局模块', () => {
|
|
114
|
+
RsTableModuleRegistry.register({
|
|
115
|
+
id: 'plugin-a',
|
|
116
|
+
setup() {},
|
|
117
|
+
})
|
|
118
|
+
const surface = useRsTable<Row>()
|
|
119
|
+
const dispose = surface.bindFeatures({
|
|
120
|
+
builtinIds: ['selection'],
|
|
121
|
+
instanceFeatures: [{ id: 'local', setup() {} }],
|
|
122
|
+
...stubAnalytics(),
|
|
123
|
+
})
|
|
124
|
+
expect(surface.getActiveFeatureIds()).toEqual(
|
|
125
|
+
expect.arrayContaining(['selection', 'plugin-a', 'local']),
|
|
126
|
+
)
|
|
127
|
+
dispose()
|
|
128
|
+
expect(surface.getActiveFeatureIds()).toEqual([])
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('createChartSeriesTableFeature 产出 series 并登记 overlay', () => {
|
|
132
|
+
const host = createRsTableFeatureHost<Row>()
|
|
133
|
+
const seriesSeen: string[] = []
|
|
134
|
+
const ctx = host.createContext({
|
|
135
|
+
...stubAnalytics(),
|
|
136
|
+
getAnalyticsSnapshot: () => ({
|
|
137
|
+
sourceRows: [
|
|
138
|
+
{ id: '1', name: 'a' },
|
|
139
|
+
{ id: '2', name: 'a' },
|
|
140
|
+
{ id: '3', name: 'b' },
|
|
141
|
+
] as Row[],
|
|
142
|
+
viewRows: [],
|
|
143
|
+
selectedRows: [],
|
|
144
|
+
sourceMode: 'view',
|
|
145
|
+
selectedCount: 0,
|
|
146
|
+
viewCount: 0,
|
|
147
|
+
}),
|
|
148
|
+
subscribeAnalytics: (listener) => {
|
|
149
|
+
listener({
|
|
150
|
+
sourceRows: [
|
|
151
|
+
{ id: '1', name: 'a' },
|
|
152
|
+
{ id: '2', name: 'a' },
|
|
153
|
+
{ id: '3', name: 'b' },
|
|
154
|
+
] as Row[],
|
|
155
|
+
viewRows: [],
|
|
156
|
+
selectedRows: [],
|
|
157
|
+
sourceMode: 'view',
|
|
158
|
+
selectedCount: 0,
|
|
159
|
+
viewCount: 0,
|
|
160
|
+
})
|
|
161
|
+
return () => undefined
|
|
162
|
+
},
|
|
163
|
+
})
|
|
164
|
+
host.setup(
|
|
165
|
+
[
|
|
166
|
+
createChartSeriesTableFeature<Row>({
|
|
167
|
+
seriesDefs: [{ id: 'by-name', kind: 'pie', categoryField: 'name' }],
|
|
168
|
+
onSeries: (series) => {
|
|
169
|
+
seriesSeen.push(...series.map((s) => s.id))
|
|
170
|
+
},
|
|
171
|
+
}),
|
|
172
|
+
],
|
|
173
|
+
ctx,
|
|
174
|
+
)
|
|
175
|
+
expect(seriesSeen).toEqual(['by-name'])
|
|
176
|
+
expect(host.getOverlayContributions().map((i) => i.key)).toEqual(['chart'])
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('RsTable expose 符合 RsTableApi 契约', async () => {
|
|
180
|
+
const wrapper = mount(RsTable, {
|
|
181
|
+
props: {
|
|
182
|
+
columns: [{ key: 'name', title: 'Name' }],
|
|
183
|
+
data: [{ id: '1', name: 'a' }],
|
|
184
|
+
rowKey: 'id',
|
|
185
|
+
selectable: true,
|
|
186
|
+
features: [
|
|
187
|
+
createContextMenuTableFeature({
|
|
188
|
+
items: [{ key: 'ping', label: 'Ping' }],
|
|
189
|
+
}),
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
})
|
|
193
|
+
await wrapper.vm.$nextTick()
|
|
194
|
+
const api = wrapper.vm as unknown as {
|
|
195
|
+
apiVersion: string
|
|
196
|
+
getViewRows: () => Row[]
|
|
197
|
+
getSelectedRowKeys: () => string[]
|
|
198
|
+
getActiveFeatureIds: () => string[]
|
|
199
|
+
}
|
|
200
|
+
expect(api.apiVersion).toBe(RS_TABLE_API_VERSION)
|
|
201
|
+
expect(isRsTableApi(api)).toBe(true)
|
|
202
|
+
expect(api.getViewRows().length).toBe(1)
|
|
203
|
+
expect(api.getSelectedRowKeys()).toEqual([])
|
|
204
|
+
expect(api.getActiveFeatureIds()).toEqual(expect.arrayContaining(['contextMenuExtra']))
|
|
205
|
+
})
|
|
206
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
import RsTable from '../components/RsTable.vue'
|
|
4
|
+
import {
|
|
5
|
+
RS_TABLE_API_VERSION,
|
|
6
|
+
isRsTableApi,
|
|
7
|
+
} from '../components/table/rs-table-api'
|
|
8
|
+
import {
|
|
9
|
+
RS_TABLE_API_OPTIONAL_METHODS,
|
|
10
|
+
RS_TABLE_API_REQUIRED_METHODS,
|
|
11
|
+
RS_TABLE_COMPAT_API_VERSION,
|
|
12
|
+
RS_TABLE_DEFAULTED_PROP_KEYS,
|
|
13
|
+
RS_TABLE_STABLE_EMITS,
|
|
14
|
+
} from '../components/table/rs-table-compat-matrix'
|
|
15
|
+
import { RS_TABLE_PROP_DEFAULTS } from '../components/table/rs-table-props'
|
|
16
|
+
|
|
17
|
+
describe('RsTable 兼容矩阵(自动化)', () => {
|
|
18
|
+
it('契约版本与 Api 常量一致', () => {
|
|
19
|
+
expect(RS_TABLE_COMPAT_API_VERSION).toBe(RS_TABLE_API_VERSION)
|
|
20
|
+
expect(RS_TABLE_API_VERSION).toBe('1.0.0')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('PROP_DEFAULTS 键与矩阵锁定列表一致', () => {
|
|
24
|
+
expect(Object.keys(RS_TABLE_PROP_DEFAULTS).sort()).toEqual(RS_TABLE_DEFAULTED_PROP_KEYS)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('expose 满足必选 Api 方法且可选方法为函数或 undefined', async () => {
|
|
28
|
+
const wrapper = mount(RsTable, {
|
|
29
|
+
props: {
|
|
30
|
+
columns: [{ key: 'name', title: 'Name' }],
|
|
31
|
+
data: [{ id: '1', name: 'a' }],
|
|
32
|
+
rowKey: 'id',
|
|
33
|
+
selectable: true,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
await wrapper.vm.$nextTick()
|
|
37
|
+
const api = wrapper.vm as unknown as Record<string, unknown>
|
|
38
|
+
expect(isRsTableApi(api)).toBe(true)
|
|
39
|
+
expect(api.apiVersion).toBe(RS_TABLE_API_VERSION)
|
|
40
|
+
|
|
41
|
+
for (const method of RS_TABLE_API_REQUIRED_METHODS) {
|
|
42
|
+
expect(typeof api[method], `required ${method}`).toBe('function')
|
|
43
|
+
}
|
|
44
|
+
for (const method of RS_TABLE_API_OPTIONAL_METHODS) {
|
|
45
|
+
const value = api[method]
|
|
46
|
+
expect(
|
|
47
|
+
value === undefined || typeof value === 'function',
|
|
48
|
+
`optional ${method}`,
|
|
49
|
+
).toBe(true)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 冒烟:查询路径可调用
|
|
53
|
+
expect((api.getViewRows as () => unknown[])()).toHaveLength(1)
|
|
54
|
+
expect((api.getSelectedRowKeys as () => string[])()).toEqual([])
|
|
55
|
+
wrapper.unmount()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('稳定 emit 名仍可被组件声明(defineEmits 面)', () => {
|
|
59
|
+
// 通过挂载监听稳定事件,确保名称未从运行时面消失
|
|
60
|
+
const wrapper = mount(RsTable, {
|
|
61
|
+
props: {
|
|
62
|
+
columns: [{ key: 'name', title: 'Name' }],
|
|
63
|
+
data: [{ id: '1', name: 'a' }],
|
|
64
|
+
rowKey: 'id',
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
for (const name of RS_TABLE_STABLE_EMITS) {
|
|
68
|
+
expect(wrapper.emitted(name) === undefined || Array.isArray(wrapper.emitted(name))).toBe(
|
|
69
|
+
true,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
// 触发一次 rowClick 验证核心 emit 通路
|
|
73
|
+
const row = wrapper.find('.rs-table__row')
|
|
74
|
+
if (row.exists()) {
|
|
75
|
+
void row.trigger('click')
|
|
76
|
+
}
|
|
77
|
+
wrapper.unmount()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('必选 Api 方法列表快照(防静默删减)', () => {
|
|
81
|
+
expect([...RS_TABLE_API_REQUIRED_METHODS]).toMatchInlineSnapshot(`
|
|
82
|
+
[
|
|
83
|
+
"getRowByKey",
|
|
84
|
+
"getRowByIndex",
|
|
85
|
+
"getColumnValues",
|
|
86
|
+
"getCellValue",
|
|
87
|
+
"getViewRows",
|
|
88
|
+
"getSelectedRows",
|
|
89
|
+
"getSelectedRowKeys",
|
|
90
|
+
"getAnalyticsSnapshot",
|
|
91
|
+
"subscribeAnalytics",
|
|
92
|
+
"getHighlightedRowKey",
|
|
93
|
+
"setHighlightedRowKey",
|
|
94
|
+
"cancelCellEdit",
|
|
95
|
+
"cancelAllEdits",
|
|
96
|
+
"getDirtyCellKeys",
|
|
97
|
+
"getCellError",
|
|
98
|
+
"setCellError",
|
|
99
|
+
"stageCell",
|
|
100
|
+
"rejectRowEdit",
|
|
101
|
+
"undoEdit",
|
|
102
|
+
"redoEdit",
|
|
103
|
+
"commitRowEdits",
|
|
104
|
+
"rollbackRowEdits",
|
|
105
|
+
]
|
|
106
|
+
`)
|
|
107
|
+
})
|
|
108
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { mapRsTableSeriesToEChartsOption } from '../components/table/rs-table-echarts-adapter'
|
|
3
|
+
import type { RsTableChartSeries } from '../components/table/table-chart-utils'
|
|
4
|
+
|
|
5
|
+
const bar: RsTableChartSeries = {
|
|
6
|
+
id: 'by-status',
|
|
7
|
+
kind: 'bar',
|
|
8
|
+
points: [
|
|
9
|
+
{ key: 'ok', name: 'ok', value: 2, count: 2 },
|
|
10
|
+
{ key: 'wait', name: 'wait', value: 1, count: 1 },
|
|
11
|
+
],
|
|
12
|
+
categories: ['ok', 'wait'],
|
|
13
|
+
values: [2, 1],
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const pie: RsTableChartSeries = {
|
|
17
|
+
...bar,
|
|
18
|
+
id: 'pie',
|
|
19
|
+
kind: 'pie',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('mapRsTableSeriesToEChartsOption', () => {
|
|
23
|
+
it('柱状图产出类目轴 + values', () => {
|
|
24
|
+
const option = mapRsTableSeriesToEChartsOption([bar])
|
|
25
|
+
expect(option.tooltip?.trigger).toBe('axis')
|
|
26
|
+
expect(option.xAxis).toEqual({ type: 'category', data: ['ok', 'wait'] })
|
|
27
|
+
expect(option.series[0]).toMatchObject({
|
|
28
|
+
id: 'by-status',
|
|
29
|
+
type: 'bar',
|
|
30
|
+
data: [2, 1],
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('饼图产出 item tooltip 与 name/value 点', () => {
|
|
35
|
+
const option = mapRsTableSeriesToEChartsOption([pie])
|
|
36
|
+
expect(option.tooltip?.trigger).toBe('item')
|
|
37
|
+
expect(option.series[0]?.type).toBe('pie')
|
|
38
|
+
expect(option.series[0]?.data).toEqual([
|
|
39
|
+
{ name: 'ok', value: 2 },
|
|
40
|
+
{ name: 'wait', value: 1 },
|
|
41
|
+
])
|
|
42
|
+
})
|
|
43
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
navigateGridCell,
|
|
4
|
+
resolveGridNavDirection,
|
|
5
|
+
} from '../components/table/rs-table-grid-nav'
|
|
6
|
+
|
|
7
|
+
const rows = [
|
|
8
|
+
{ rowKey: '1', rowIndex: 0 },
|
|
9
|
+
{ rowKey: '2', rowIndex: 1 },
|
|
10
|
+
{ rowKey: '3', rowIndex: 2 },
|
|
11
|
+
]
|
|
12
|
+
const cols = ['a', 'b', 'c']
|
|
13
|
+
|
|
14
|
+
describe('navigateGridCell', () => {
|
|
15
|
+
it('无焦点时以左上角为种子', () => {
|
|
16
|
+
expect(navigateGridCell(rows, cols, null, 'right')).toEqual({
|
|
17
|
+
rowKey: '1',
|
|
18
|
+
colKey: 'b',
|
|
19
|
+
rowIndex: 0,
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('箭头在边界钳制', () => {
|
|
24
|
+
const at = { rowKey: '1', colKey: 'a', rowIndex: 0 }
|
|
25
|
+
expect(navigateGridCell(rows, cols, at, 'left')?.colKey).toBe('a')
|
|
26
|
+
expect(navigateGridCell(rows, cols, at, 'up')?.rowKey).toBe('1')
|
|
27
|
+
const br = { rowKey: '3', colKey: 'c', rowIndex: 2 }
|
|
28
|
+
expect(navigateGridCell(rows, cols, br, 'right')?.colKey).toBe('c')
|
|
29
|
+
expect(navigateGridCell(rows, cols, br, 'down')?.rowKey).toBe('3')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Home/End 与 Ctrl 角点', () => {
|
|
33
|
+
const mid = { rowKey: '2', colKey: 'b', rowIndex: 1 }
|
|
34
|
+
expect(navigateGridCell(rows, cols, mid, 'home')?.colKey).toBe('a')
|
|
35
|
+
expect(navigateGridCell(rows, cols, mid, 'end')?.colKey).toBe('c')
|
|
36
|
+
expect(navigateGridCell(rows, cols, mid, 'first')).toEqual({
|
|
37
|
+
rowKey: '1',
|
|
38
|
+
colKey: 'a',
|
|
39
|
+
rowIndex: 0,
|
|
40
|
+
})
|
|
41
|
+
expect(navigateGridCell(rows, cols, mid, 'last')).toEqual({
|
|
42
|
+
rowKey: '3',
|
|
43
|
+
colKey: 'c',
|
|
44
|
+
rowIndex: 2,
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('PageDown 按 pageSize 跳行', () => {
|
|
49
|
+
const at = { rowKey: '1', colKey: 'a', rowIndex: 0 }
|
|
50
|
+
expect(navigateGridCell(rows, cols, at, 'pageDown', 2)?.rowKey).toBe('3')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('resolveGridNavDirection', () => {
|
|
55
|
+
it('映射常用键', () => {
|
|
56
|
+
expect(resolveGridNavDirection({ key: 'ArrowRight' } as KeyboardEvent)).toBe('right')
|
|
57
|
+
expect(resolveGridNavDirection({ key: 'Home' } as KeyboardEvent)).toBe('home')
|
|
58
|
+
expect(resolveGridNavDirection({ key: 'Home', ctrlKey: true } as KeyboardEvent)).toBe(
|
|
59
|
+
'first',
|
|
60
|
+
)
|
|
61
|
+
expect(resolveGridNavDirection({ key: 'a' } as KeyboardEvent)).toBeNull()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils'
|
|
2
|
+
import { defineComponent, h, nextTick } from 'vue'
|
|
3
|
+
import { describe, expect, it, beforeEach } from 'vitest'
|
|
4
|
+
import RsTable from '../components/RsTable.vue'
|
|
5
|
+
import { createRsTableFeatureHost } from '../components/table/rs-table-feature-host'
|
|
6
|
+
import {
|
|
7
|
+
resolveInstanceFeatures,
|
|
8
|
+
RsTableModuleRegistry,
|
|
9
|
+
} from '../components/table/rs-table-module-registry'
|
|
10
|
+
import {
|
|
11
|
+
createOverlayTableFeature,
|
|
12
|
+
createToolbarTableFeature,
|
|
13
|
+
} from '../components/table/table-features'
|
|
14
|
+
import { useRsTableHeadless } from '../composables/useRsTableHeadless'
|
|
15
|
+
import type { RsTableRowData } from '../components/table-utils'
|
|
16
|
+
|
|
17
|
+
type Row = RsTableRowData & { id: string; name: string }
|
|
18
|
+
|
|
19
|
+
const columns = [{ key: 'name', title: 'Name' }]
|
|
20
|
+
|
|
21
|
+
function analyticsStub() {
|
|
22
|
+
return {
|
|
23
|
+
getViewRows: () => [] as Row[],
|
|
24
|
+
getSelectedRows: () => [] as Row[],
|
|
25
|
+
getAnalyticsSnapshot: () => ({
|
|
26
|
+
sourceRows: [] as Row[],
|
|
27
|
+
viewRows: [] as Row[],
|
|
28
|
+
selectedRows: [] as Row[],
|
|
29
|
+
sourceMode: 'view' as const,
|
|
30
|
+
selectedCount: 0,
|
|
31
|
+
viewCount: 0,
|
|
32
|
+
}),
|
|
33
|
+
subscribeAnalytics: () => () => undefined,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('RsTable 多表隔离', () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
RsTableModuleRegistry.clear()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('两个 FeatureHost 贡献袋互不污染', () => {
|
|
43
|
+
const a = createRsTableFeatureHost<Row>()
|
|
44
|
+
const b = createRsTableFeatureHost<Row>()
|
|
45
|
+
const stub = analyticsStub()
|
|
46
|
+
a.setup(
|
|
47
|
+
[createToolbarTableFeature({ items: [{ key: 'a-only', label: 'A' }] })],
|
|
48
|
+
a.createContext(stub),
|
|
49
|
+
)
|
|
50
|
+
b.setup(
|
|
51
|
+
[createToolbarTableFeature({ items: [{ key: 'b-only', label: 'B' }] })],
|
|
52
|
+
b.createContext(stub),
|
|
53
|
+
)
|
|
54
|
+
expect(a.getToolbarItems().map((i) => i.key)).toEqual(['a-only'])
|
|
55
|
+
expect(b.getToolbarItems().map((i) => i.key)).toEqual(['b-only'])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('同页两表选中与 viewRows 互不影响', async () => {
|
|
59
|
+
const t1 = mount(RsTable, {
|
|
60
|
+
props: {
|
|
61
|
+
columns,
|
|
62
|
+
data: [{ id: '1', name: 'a' }] as Row[],
|
|
63
|
+
rowKey: 'id',
|
|
64
|
+
selectable: true,
|
|
65
|
+
selectedRowKeys: ['1'],
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
const t2 = mount(RsTable, {
|
|
69
|
+
props: {
|
|
70
|
+
columns,
|
|
71
|
+
data: [{ id: '2', name: 'b' }] as Row[],
|
|
72
|
+
rowKey: 'id',
|
|
73
|
+
selectable: true,
|
|
74
|
+
selectedRowKeys: [],
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
await nextTick()
|
|
78
|
+
|
|
79
|
+
const api1 = t1.vm as unknown as {
|
|
80
|
+
getSelectedRowKeys: () => string[]
|
|
81
|
+
getViewRows: () => Row[]
|
|
82
|
+
getToolbarItems: () => Array<{ key: string }>
|
|
83
|
+
}
|
|
84
|
+
const api2 = t2.vm as unknown as {
|
|
85
|
+
getSelectedRowKeys: () => string[]
|
|
86
|
+
getViewRows: () => Row[]
|
|
87
|
+
}
|
|
88
|
+
expect(api1.getSelectedRowKeys()).toEqual(['1'])
|
|
89
|
+
expect(api2.getSelectedRowKeys()).toEqual([])
|
|
90
|
+
expect(api1.getViewRows()[0]?.id).toBe('1')
|
|
91
|
+
expect(api2.getViewRows()[0]?.id).toBe('2')
|
|
92
|
+
|
|
93
|
+
t1.unmount()
|
|
94
|
+
t2.unmount()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('ModuleRegistry 全局生效;实例同 id 可覆盖', () => {
|
|
98
|
+
RsTableModuleRegistry.register(
|
|
99
|
+
createOverlayTableFeature({
|
|
100
|
+
items: [{ key: 'global-chart', slot: 'chart' }],
|
|
101
|
+
}),
|
|
102
|
+
)
|
|
103
|
+
const hostA = createRsTableFeatureHost<Row>()
|
|
104
|
+
const hostB = createRsTableFeatureHost<Row>()
|
|
105
|
+
const stub = analyticsStub()
|
|
106
|
+
const featuresA = resolveInstanceFeatures<Row>([
|
|
107
|
+
createOverlayTableFeature({
|
|
108
|
+
id: 'overlayExtra',
|
|
109
|
+
items: [{ key: 'a-chart', slot: 'chart-a' }],
|
|
110
|
+
}),
|
|
111
|
+
])
|
|
112
|
+
const featuresB = resolveInstanceFeatures<Row>([])
|
|
113
|
+
hostA.setup(featuresA, hostA.createContext(stub))
|
|
114
|
+
hostB.setup(featuresB, hostB.createContext(stub))
|
|
115
|
+
expect(hostA.getOverlayContributions().map((i) => i.key)).toEqual(['a-chart'])
|
|
116
|
+
expect(hostB.getOverlayContributions().map((i) => i.key)).toEqual(['global-chart'])
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('useRsTableHeadless 两实例状态与 toolbar 隔离', async () => {
|
|
120
|
+
const Host = defineComponent({
|
|
121
|
+
setup() {
|
|
122
|
+
const h1 = useRsTableHeadless<Row>({
|
|
123
|
+
columns: () => columns,
|
|
124
|
+
data: () => [{ id: '1', name: 'a' }],
|
|
125
|
+
rowKey: 'id',
|
|
126
|
+
features: () => [
|
|
127
|
+
createToolbarTableFeature({ items: [{ key: 't1', label: 'T1' }] }),
|
|
128
|
+
],
|
|
129
|
+
})
|
|
130
|
+
const h2 = useRsTableHeadless<Row>({
|
|
131
|
+
columns: () => columns,
|
|
132
|
+
data: () => [
|
|
133
|
+
{ id: '2', name: 'b' },
|
|
134
|
+
{ id: '3', name: 'c' },
|
|
135
|
+
],
|
|
136
|
+
rowKey: 'id',
|
|
137
|
+
features: () => [
|
|
138
|
+
createToolbarTableFeature({ items: [{ key: 't2', label: 'T2' }] }),
|
|
139
|
+
],
|
|
140
|
+
})
|
|
141
|
+
return () =>
|
|
142
|
+
h('div', {
|
|
143
|
+
'data-v1': String(h1.api.getViewRows().length),
|
|
144
|
+
'data-v2': String(h2.api.getViewRows().length),
|
|
145
|
+
'data-t1': h1.getToolbarItems()[0]?.key ?? '',
|
|
146
|
+
'data-t2': h2.getToolbarItems()[0]?.key ?? '',
|
|
147
|
+
})
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
const wrapper = mount(Host)
|
|
151
|
+
await nextTick()
|
|
152
|
+
expect(wrapper.attributes('data-v1')).toBe('1')
|
|
153
|
+
expect(wrapper.attributes('data-v2')).toBe('2')
|
|
154
|
+
expect(wrapper.attributes('data-t1')).toBe('t1')
|
|
155
|
+
expect(wrapper.attributes('data-t2')).toBe('t2')
|
|
156
|
+
wrapper.unmount()
|
|
157
|
+
})
|
|
158
|
+
})
|
|
@@ -51,6 +51,27 @@ describe('normalizeSplitSizes', () => {
|
|
|
51
51
|
const sizes = normalizeSplitSizes([{ key: 'a', size: 0 }, { key: 'b', size: 0 }])
|
|
52
52
|
expect(sizes).toEqual([50, 50])
|
|
53
53
|
})
|
|
54
|
+
|
|
55
|
+
it('keeps auto panes out of percentage pool', () => {
|
|
56
|
+
const sizes = normalizeSplitSizes([
|
|
57
|
+
{ key: 'search', size: 'auto' },
|
|
58
|
+
{ key: 'table' },
|
|
59
|
+
])
|
|
60
|
+
expect(sizes[0]).toBe(0)
|
|
61
|
+
expect(sizes[1]).toBeCloseTo(100)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('distributes remaining percent among non-auto panes only', () => {
|
|
65
|
+
const sizes = normalizeSplitSizes([
|
|
66
|
+
{ key: 'a', size: 'auto' },
|
|
67
|
+
{ key: 'b', size: 40 },
|
|
68
|
+
{ key: 'c' },
|
|
69
|
+
])
|
|
70
|
+
expect(sizes[0]).toBe(0)
|
|
71
|
+
expect(sizes[1]).toBeCloseTo(40)
|
|
72
|
+
expect(sizes[2]).toBeCloseTo(60)
|
|
73
|
+
expect(sizes[1]! + sizes[2]!).toBeCloseTo(100)
|
|
74
|
+
})
|
|
54
75
|
})
|
|
55
76
|
|
|
56
77
|
describe('applySplitResize', () => {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { buildTableChartSeries } from '../components/table/table-chart-utils'
|
|
4
|
+
import { useRsTableChartBridge } from '../composables/useRsTableChartBridge'
|
|
5
|
+
import { useRsTableSelectionSource } from '../composables/useRsTableSelectionSource'
|
|
6
|
+
|
|
7
|
+
const rows = [
|
|
8
|
+
{ id: '1', status: 'ok', amount: 10 },
|
|
9
|
+
{ id: '2', status: 'ok', amount: 20 },
|
|
10
|
+
{ id: '3', status: 'wait', amount: 5 },
|
|
11
|
+
{ id: '4', status: 'wait', amount: 15 },
|
|
12
|
+
{ id: '5', status: 'fail', amount: 3 },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
describe('buildTableChartSeries', () => {
|
|
16
|
+
it('groups by category with count', () => {
|
|
17
|
+
const series = buildTableChartSeries(rows, {
|
|
18
|
+
id: 'by-status',
|
|
19
|
+
kind: 'pie',
|
|
20
|
+
categoryField: 'status',
|
|
21
|
+
valueAgg: 'count',
|
|
22
|
+
})
|
|
23
|
+
expect(series.kind).toBe('pie')
|
|
24
|
+
expect(series.categories).toEqual(['ok', 'wait', 'fail'])
|
|
25
|
+
expect(series.values).toEqual([2, 2, 1])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('sums valueField for bar', () => {
|
|
29
|
+
const series = buildTableChartSeries(rows, {
|
|
30
|
+
id: 'amount',
|
|
31
|
+
kind: 'bar',
|
|
32
|
+
categoryField: 'status',
|
|
33
|
+
valueField: 'amount',
|
|
34
|
+
valueAgg: 'sum',
|
|
35
|
+
})
|
|
36
|
+
const byName = Object.fromEntries(series.points.map((p) => [p.name, p.value]))
|
|
37
|
+
expect(byName.ok).toBe(30)
|
|
38
|
+
expect(byName.wait).toBe(20)
|
|
39
|
+
expect(byName.fail).toBe(3)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('merges tail into other when topN set', () => {
|
|
43
|
+
const series = buildTableChartSeries(rows, {
|
|
44
|
+
id: 'top1',
|
|
45
|
+
kind: 'pie',
|
|
46
|
+
categoryField: 'status',
|
|
47
|
+
valueAgg: 'count',
|
|
48
|
+
topN: 1,
|
|
49
|
+
otherLabel: '其余',
|
|
50
|
+
})
|
|
51
|
+
expect(series.points).toHaveLength(2)
|
|
52
|
+
expect(series.points[0]?.name).toBe('ok')
|
|
53
|
+
expect(series.points[1]?.name).toBe('其余')
|
|
54
|
+
expect(series.points[1]?.value).toBe(3)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('useRsTableSelectionSource', () => {
|
|
59
|
+
it('prefers selected rows as source', () => {
|
|
60
|
+
const viewRows = ref(rows)
|
|
61
|
+
const selectedRows = ref([rows[2]!])
|
|
62
|
+
const src = useRsTableSelectionSource({ viewRows, selectedRows })
|
|
63
|
+
expect(src.sourceMode.value).toBe('selected')
|
|
64
|
+
expect(src.sourceRows.value).toEqual([rows[2]])
|
|
65
|
+
selectedRows.value = []
|
|
66
|
+
expect(src.sourceMode.value).toBe('view')
|
|
67
|
+
expect(src.sourceRows.value).toHaveLength(5)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('useRsTableChartBridge', () => {
|
|
72
|
+
it('rebuilds pie series when selection changes', () => {
|
|
73
|
+
const viewRows = ref(rows)
|
|
74
|
+
const selectedRows = ref<typeof rows>([])
|
|
75
|
+
const bridge = useRsTableChartBridge({
|
|
76
|
+
viewRows,
|
|
77
|
+
selectedRows,
|
|
78
|
+
seriesDefs: [
|
|
79
|
+
{ id: 'status-pie', kind: 'pie', categoryField: 'status', valueAgg: 'count' },
|
|
80
|
+
],
|
|
81
|
+
})
|
|
82
|
+
expect(bridge.series.value[0]?.values).toEqual([2, 2, 1])
|
|
83
|
+
selectedRows.value = [rows[0]!, rows[1]!]
|
|
84
|
+
expect(bridge.sourceMode.value).toBe('selected')
|
|
85
|
+
expect(bridge.series.value[0]?.categories).toEqual(['ok'])
|
|
86
|
+
expect(bridge.series.value[0]?.values).toEqual([2])
|
|
87
|
+
})
|
|
88
|
+
})
|