56cc253009
The 5×10 metadata batching only staggered the cheap layer (JSON); thumbnails load as independent <img> requests and clustered, so tiles "popped in together" after a wait. Two changes: - GalleryItem reveals each tile when ITS OWN thumbnail fires @load (with an onMounted complete-check for cached thumbs), playing a showcase-style flip-up entrance. Tiles now cascade in natural load order instead of all at once. Honors prefers-reduced-motion. - gallery store does ONE initial fetch (limit=50) instead of 10 serial /scroll round-trips. Fewer RTTs, faster first paint; the reveal-on-load is what makes appearance progressive now. Infinite scroll pulls 25/trigger. Tests: GalleryItem gains is-loaded only after @load; loadInitial issues exactly one scroll request at the initial limit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68 lines
2.3 KiB
JavaScript
68 lines
2.3 KiB
JavaScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||
import { setActivePinia, createPinia } from 'pinia'
|
||
import { useGalleryStore } from '../src/stores/gallery.js'
|
||
|
||
function stubFetch(handler) {
|
||
globalThis.fetch = vi.fn(async (url, init) => {
|
||
const { status, body } = handler(url, init)
|
||
return {
|
||
ok: status >= 200 && status < 300,
|
||
status,
|
||
statusText: String(status),
|
||
text: async () => (body == null ? '' : JSON.stringify(body))
|
||
}
|
||
})
|
||
}
|
||
|
||
const EMPTY = { images: [], date_groups: [], next_cursor: null }
|
||
|
||
describe('gallery store: tag/post filter exclusivity', () => {
|
||
beforeEach(() => setActivePinia(createPinia()))
|
||
afterEach(() => vi.restoreAllMocks())
|
||
|
||
it('setPostFilter sets post_id and clears tag_id', () => {
|
||
const s = useGalleryStore()
|
||
stubFetch(() => ({ status: 200, body: EMPTY }))
|
||
s.setTagFilter(3)
|
||
expect(s.filter.tag_id).toBe(3)
|
||
s.setPostFilter(7)
|
||
expect(s.filter.post_id).toBe(7)
|
||
expect(s.filter.tag_id).toBe(null)
|
||
})
|
||
|
||
it('setTagFilter clears post_id', () => {
|
||
const s = useGalleryStore()
|
||
stubFetch(() => ({ status: 200, body: EMPTY }))
|
||
s.setPostFilter(7)
|
||
s.setTagFilter(3)
|
||
expect(s.filter.tag_id).toBe(3)
|
||
expect(s.filter.post_id).toBe(null)
|
||
})
|
||
|
||
it('loadMore sends exactly the active filter param', async () => {
|
||
const s = useGalleryStore()
|
||
const urls = []
|
||
stubFetch((url) => { urls.push(url); return { status: 200, body: EMPTY } })
|
||
s.setPostFilter(7)
|
||
await s.loadMore()
|
||
const scrollCall = urls.filter(u => u.includes('/api/gallery/scroll')).pop()
|
||
expect(scrollCall).toContain('post_id=7')
|
||
expect(scrollCall).not.toContain('tag_id=')
|
||
})
|
||
|
||
it('loadInitial issues exactly one scroll request at the initial limit', async () => {
|
||
const s = useGalleryStore()
|
||
const urls = []
|
||
// Non-null cursor: the old 10×serial-batch loop would have fired ten
|
||
// requests here. The single-fetch path must fire exactly one.
|
||
stubFetch((url) => {
|
||
urls.push(url)
|
||
return { status: 200, body: { images: [], date_groups: [], next_cursor: 'c1' } }
|
||
})
|
||
await s.loadInitial()
|
||
const scrollCalls = urls.filter(u => u.includes('/api/gallery/scroll'))
|
||
expect(scrollCalls).toHaveLength(1)
|
||
expect(scrollCalls[0]).toContain('limit=50')
|
||
})
|
||
})
|