feat(admin): album management pages with members and categories
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { accumulatePage, firstPage, type CursorPage } from './cursorList'
|
||||
|
||||
const pageOf = <T>(items: T[], nextCursor: string | null): CursorPage<T> => ({
|
||||
items,
|
||||
nextCursor,
|
||||
hasMore: nextCursor !== null
|
||||
})
|
||||
|
||||
describe('cursorList 游标累积', () => {
|
||||
it('首页整页替换并保留游标', () => {
|
||||
const state = firstPage(pageOf([1, 2], 'c1'))
|
||||
expect(state.items).toEqual([1, 2])
|
||||
expect(state.nextCursor).toBe('c1')
|
||||
expect(state.hasMore).toBe(true)
|
||||
})
|
||||
|
||||
it('加载更多按序追加,nextCursor 为 null 即到底', () => {
|
||||
let state = firstPage(pageOf([1, 2], 'c1'))
|
||||
state = accumulatePage(state, pageOf([3], 'c2'))
|
||||
expect(state.items).toEqual([1, 2, 3])
|
||||
expect(state.hasMore).toBe(true)
|
||||
state = accumulatePage(state, pageOf([4], null))
|
||||
expect(state.items).toEqual([1, 2, 3, 4])
|
||||
expect(state.hasMore).toBe(false)
|
||||
})
|
||||
|
||||
it('keyOf 去重:跨页重复行不重复 append', () => {
|
||||
let state = firstPage(pageOf([{ id: 'a' }, { id: 'b' }], 'c1'))
|
||||
state = accumulatePage(state, pageOf([{ id: 'b' }, { id: 'c' }], null), (x) => x.id)
|
||||
expect(state.items.map((x) => x.id)).toEqual(['a', 'b', 'c'])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user