优化构架

This commit is contained in:
2026-08-03 18:49:18 +08:00
parent 1241d11c01
commit 44c33a6280
133 changed files with 651 additions and 603 deletions
+32
View File
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest'
import { createPaginationItems, normalizePage, normalizePageSizes } from './DataTable.vue'
describe('DataTable pagination helpers', () => {
it('normalizes page-size options', () => {
expect(normalizePageSizes([20, 10, 20, 0, -1, 0.8, 10.8])).toEqual([20, 10])
expect(normalizePageSizes([])).toEqual([10])
})
it('keeps the page inside the available range', () => {
expect(normalizePage(0, 8)).toBe(1)
expect(normalizePage(12, 8)).toBe(8)
expect(normalizePage(3.8, 8)).toBe(3)
expect(normalizePage(Number.NaN, 8)).toBe(1)
expect(normalizePage(4, 0)).toBe(1)
expect(normalizePage(4, Number.NaN)).toBe(1)
})
it('does not create page buttons for an empty result', () => {
expect(createPaginationItems(1, 0)).toEqual([])
})
it('shows all pages for a short result set', () => {
expect(createPaginationItems(3, 5)).toEqual([1, 2, 3, 4, 5])
})
it('keeps first and last pages visible for long result sets', () => {
expect(createPaginationItems(1, 30)).toEqual([1, 2, 3, 4, 5, 'ellipsis-end', 30])
expect(createPaginationItems(15, 30)).toEqual([1, 'ellipsis-start', 14, 15, 16, 'ellipsis-end', 30])
expect(createPaginationItems(30, 30)).toEqual([1, 'ellipsis-start', 26, 27, 28, 29, 30])
})
})