CI and images / lint (push) Successful in 2s
CI and images / extension-version (push) Successful in 2s
CI and images / frontend-build (push) Successful in 20s
CI and images / backend-lint-and-test (push) Successful in 30s
CI and images / integration (push) Successful in 2m18s
CI and images / sign-extension (push) Successful in 3s
CI and images / build-agent (push) Successful in 6s
CI and images / build-web (push) Successful in 1m44s
CI and images / smoke-web (push) Successful in 56s
CI and images / promote (push) Skipped
tests/factories.py holds image_row/make_image/make_image_async/make_tag. The 17 byte-identical _img/_tag helpers (15 modules) now import them under their old names, so no call site changed. frontend/test/support/stubFetch.js replaces 15 copies that differed only in formatting. Copies whose bodies differ (other defaults, other columns, a url-only stub) are left as they are; folding those needs a look at each caller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LVjrnpQjRgHdvq95rASoiR
54 lines
2.1 KiB
JavaScript
54 lines
2.1 KiB
JavaScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
import { setActivePinia, createPinia } from 'pinia'
|
|
import { useGallerySelectionStore } from '../src/stores/gallerySelection.js'
|
|
import { stubFetch } from './support/stubFetch.js'
|
|
|
|
describe('gallerySelection store', () => {
|
|
beforeEach(() => setActivePinia(createPinia()))
|
|
afterEach(() => vi.restoreAllMocks())
|
|
|
|
it('toggle adds/removes preserving order; count/isSelected track it', () => {
|
|
const s = useGallerySelectionStore()
|
|
s.toggle(5); s.toggle(9); s.toggle(2)
|
|
expect(s.order).toEqual([5, 9, 2])
|
|
expect(s.isSelected(9)).toBe(true)
|
|
expect(s.count).toBe(3)
|
|
s.toggle(9)
|
|
expect(s.order).toEqual([5, 2])
|
|
expect(s.isSelected(9)).toBe(false)
|
|
})
|
|
|
|
it('exitSelectMode clears selection and mode', () => {
|
|
const s = useGallerySelectionStore()
|
|
s.enterSelectMode(); s.toggle(1)
|
|
expect(s.isSelectMode).toBe(true)
|
|
s.exitSelectMode()
|
|
expect(s.isSelectMode).toBe(false)
|
|
expect(s.order).toEqual([])
|
|
})
|
|
|
|
it('bulkAdd posts the id list + source and refreshes', async () => {
|
|
const s = useGallerySelectionStore()
|
|
s.toggle(1); s.toggle(2)
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, body: JSON.parse(init.body) })
|
|
if (url.includes('/bulk/tags')) return { status: 200, body: { added_count: 2, total: 2 } }
|
|
if (url.includes('common-tags')) return { status: 200, body: { tags: [] } }
|
|
if (url.includes('suggestions/bulk')) return { status: 200, body: { suggestions: {}, evaluated: 2, threshold: 0.8 } }
|
|
return { status: 200, body: {} }
|
|
})
|
|
await s.bulkAdd(42, 'ml_accepted')
|
|
const add = calls.find(c => c.url.includes('/api/images/bulk/tags'))
|
|
expect(add.body).toEqual({ image_ids: [1, 2], tag_id: 42, source: 'ml_accepted' })
|
|
})
|
|
|
|
it('loadCommonTags stores returned tags', async () => {
|
|
const s = useGallerySelectionStore()
|
|
s.toggle(3)
|
|
stubFetch(() => ({ status: 200, body: { tags: [{ id: 7, name: 'x', kind: 'general' }] } }))
|
|
await s.loadCommonTags()
|
|
expect(s.commonTags).toEqual([{ id: 7, name: 'x', kind: 'general' }])
|
|
})
|
|
})
|