This commit is contained in:
2026-08-21 17:20:40 +08:00
parent 465be7c8f3
commit c972ad408a
14 changed files with 504 additions and 118 deletions
+22 -1
View File
@@ -1,7 +1,7 @@
import { computed, defineComponent } from 'vue'
import { shallowMount } from '@vue/test-utils'
import { beforeEach, describe, expect, it } from 'vitest'
import DataTable, { createPaginationItems, normalizePage, normalizePageSizes, type DataTableColumn } from './DataTable.vue'
import DataTable, { createPaginationItems, normalizePage, normalizePageSizes, normalizeTotal, type DataTableColumn } from './DataTable.vue'
import LayoutPreferenceList from './LayoutPreferenceList.vue'
import { UI_PREFERENCE_SCOPE, preferenceStorageKey } from '@/shared/utils/uiLayoutPreference'
@@ -59,6 +59,27 @@ describe('DataTable pagination helpers', () => {
expect(createPaginationItems(1, 0)).toEqual([])
})
it('normalizes totals serialized as JSON strings before calculating pages', () => {
expect(normalizeTotal('30')).toBe(30)
expect(normalizeTotal(' 30 ')).toBe(30)
expect(normalizeTotal(30)).toBe(30)
expect(normalizeTotal('')).toBe(0)
expect(normalizeTotal('invalid')).toBe(0)
})
it('renders page navigation when the API total is a numeric string', () => {
const wrapper = shallowMount(DataTable, {
props: { data: [], columns: configurableColumns, total: '30', page: 1, pageSize: 20 },
global: {
stubs: { ElTable: TableStub, ElTableColumn: ColumnStub, ElButton: ButtonStub, ElPopover: PopoverStub },
directives: { loading: {} },
},
})
expect(wrapper.get('.data-table__page-buttons').text()).toContain('1')
expect(wrapper.get('.data-table__page-buttons').text()).toContain('2')
})
it('shows all pages for a short result set', () => {
expect(createPaginationItems(3, 5)).toEqual([1, 2, 3, 4, 5])
})