This commit is contained in:
2026-08-12 17:45:49 +08:00
parent 5b441626e9
commit 2a889a7d91
25 changed files with 154 additions and 29 deletions
+23 -2
View File
@@ -8,8 +8,8 @@ import { UI_PREFERENCE_SCOPE, preferenceStorageKey } from '@/shared/utils/uiLayo
const TableStub = defineComponent({ template: '<div><slot /></div>', methods: { doLayout() {} } })
const ColumnStub = defineComponent({
inheritAttrs: false,
props: { label: String },
template: '<div class="column-stub" :data-label="label"><slot /></div>',
props: { label: String, prop: String },
template: '<div class="column-stub" :data-label="label" :data-prop="prop"><slot /></div>',
})
const ButtonStub = defineComponent({ template: '<button type="button"><slot /></button>' })
const PopoverStub = defineComponent({ template: '<div><slot name="reference" /><slot /></div>' })
@@ -69,6 +69,27 @@ describe('DataTable pagination helpers', () => {
describe('DataTable column preferences', () => {
beforeEach(() => localStorage.clear())
it('uses key as the data property for ordinary columns only', () => {
const wrapper = shallowMount(DataTable, {
props: {
data: [{ customerName: '客户A', explicitName: '显式字段' }],
columns: [
{ key: 'actions', label: '操作', slotName: 'actions' },
{ key: 'customerName', label: '客户' },
{ key: 'name', prop: 'explicitName', label: '显式字段' },
{ key: 'selection', type: 'selection', label: '选择' },
],
},
global: {
stubs: { ElTable: TableStub, ElTableColumn: ColumnStub, ElButton: ButtonStub, ElPopover: PopoverStub },
directives: { loading: {} },
},
})
const columns = wrapper.findAll('.column-stub')
expect(columns.map((column) => column.attributes('data-prop'))).toEqual([undefined, 'customerName', 'explicitName', undefined])
})
it('restores column order and visibility while locking the actions column', async () => {
localStorage.setItem(preferenceStorageKey('table', 'user-1', 'orders-table'), JSON.stringify({
version: 1,