fix(SPA): activity list saves pagination too

This commit is contained in:
Florian Sylvain committed 2026-10-13 16:36:42 +02:00
1 parent 9d9453c1b3
commit c41e6dbca5
5 files changed
+193 -4

No files matched your search

+29 -1
View File
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { readStoredPageSize, storePageSize } from '../pageSizeMemory'
import { readStoredPageSize, resolvePageSize, storePageSize } from '../pageSizeMemory'
const KEY = 'renewcms-page-size-articles'
const SIZES = [5, 25, 50, 100]
@@ -53,3 +53,31 @@ describe('pageSizeMemory', () => {
expect(() => storePageSize(KEY, 50)).not.toThrow()
})
})
describe('resolvePageSize', () => {
beforeEach(() => {
localStorage.clear()
})
it('uses the stored size when the query has none', () => {
localStorage.setItem(KEY, '5')
expect(resolvePageSize(undefined, KEY, SIZES, 25)).toBe(5)
})
it('falls back when nothing valid is stored', () => {
expect(resolvePageSize(undefined, KEY, SIZES, 25)).toBe(25)
})
it('lets a valid query size win over the stored one', () => {
localStorage.setItem(KEY, '5')
expect(resolvePageSize('100', KEY, SIZES, 25)).toBe(100)
})
it.each(['10', '', 'abc', ['5']])(
'falls back to the default for %j, ignoring storage',
(raw) => {
localStorage.setItem(KEY, '5')
expect(resolvePageSize(raw, KEY, SIZES, 25)).toBe(25)
},
)
})