8ad40da145
Completes FC-6.1: the series management UI now works in chapters. - SeriesManageView: chapters as cards (inline-rename, stated-page range inputs, move up/down, merge-into-previous, delete, pick-as-add-target), pages drag-reorder WITHIN a chapter, a "gap: N-M missing" badge between chapters with a stated-page hole, and Add chapter / Add placeholder. The picker adds the selection into the targeted chapter. - seriesManage store: chapter CRUD + reorderChapters/moveChapter/mergeChapter/ reorderPages actions; consumes chapters[]/gaps[]; addSelected targets a chapter. - Reader: page_number is now within-chapter, so anchors switched to a global `seq` (reading-order position) — fixes scroll/jump/active collisions across chapters — plus chapter-title dividers at each chapter boundary. - Updated seriesManage.spec to the chaptered store shape. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
96 lines
3.4 KiB
JavaScript
96 lines
3.4 KiB
JavaScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
import { setActivePinia, createPinia } from 'pinia'
|
|
import { useSeriesManageStore, moveItem } from '../src/stores/seriesManage.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 SERIES_BODY = {
|
|
series: { id: 7, name: 'V' },
|
|
chapters: [
|
|
{
|
|
id: 1, chapter_number: 1, title: null, is_placeholder: false,
|
|
stated_page_start: null, stated_page_end: null,
|
|
pages: [{ image_id: 1, page_number: 1, thumbnail_url: 't' }]
|
|
}
|
|
],
|
|
gaps: [],
|
|
pages: [{ image_id: 1, page_number: 1, thumbnail_url: 't' }]
|
|
}
|
|
|
|
describe('seriesManage', () => {
|
|
beforeEach(() => setActivePinia(createPinia()))
|
|
afterEach(() => vi.restoreAllMocks())
|
|
|
|
it('moveItem reorders immutably', () => {
|
|
expect(moveItem([1, 2, 3, 4], 3, 0)).toEqual([4, 1, 2, 3])
|
|
expect(moveItem([1, 2, 3], 0, 2)).toEqual([2, 3, 1])
|
|
})
|
|
|
|
it('load fetches chapters + series and picks a default target', async () => {
|
|
const s = useSeriesManageStore()
|
|
stubFetch(() => ({ status: 200, body: SERIES_BODY }))
|
|
await s.load(7)
|
|
expect(s.series).toEqual({ id: 7, name: 'V' })
|
|
expect(s.chapters.map(c => c.id)).toEqual([1])
|
|
expect(s.pageCount).toBe(1)
|
|
expect(s.targetChapterId).toBe(1)
|
|
})
|
|
|
|
it('reorderPages posts ordered ids to the chapter reorder route', async () => {
|
|
const s = useSeriesManageStore()
|
|
s.tagId = 7
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, body: init.body ? JSON.parse(init.body) : null })
|
|
if (url.includes('/reorder')) return { status: 200, body: { ok: true } }
|
|
return { status: 200, body: SERIES_BODY }
|
|
})
|
|
await s.reorderPages(3, [30, 10, 20])
|
|
const r = calls.find(c => c.url.includes('/chapters/3/reorder'))
|
|
expect(r.url).toContain('/api/series/7/chapters/3/reorder')
|
|
expect(r.body).toEqual({ image_ids: [30, 10, 20] })
|
|
})
|
|
|
|
it('moveChapter reorders via the chapter id list', async () => {
|
|
const s = useSeriesManageStore()
|
|
s.tagId = 7
|
|
s.chapters = [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, body: init.body ? JSON.parse(init.body) : null })
|
|
if (url.includes('/chapters/reorder')) return { status: 200, body: { ok: true } }
|
|
return { status: 200, body: SERIES_BODY }
|
|
})
|
|
await s.moveChapter(2, -1)
|
|
const r = calls.find(c => c.url.includes('/chapters/reorder'))
|
|
expect(r.body).toEqual({ chapter_ids: [2, 1, 3] })
|
|
})
|
|
|
|
it('addSelected posts selection + target chapter then clears', async () => {
|
|
const s = useSeriesManageStore()
|
|
s.tagId = 7
|
|
s.targetChapterId = 5
|
|
s.pickerSelection = [9, 10]
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, body: init.body ? JSON.parse(init.body) : null })
|
|
if (url.endsWith('/pages') && init.method === 'POST')
|
|
return { status: 200, body: { added_count: 2 } }
|
|
return { status: 200, body: SERIES_BODY }
|
|
})
|
|
await s.addSelected()
|
|
const add = calls.find(c => c.url.endsWith('/api/series/7/pages'))
|
|
expect(add.body).toEqual({ image_ids: [9, 10], chapter_id: 5 })
|
|
expect(s.pickerSelection).toEqual([])
|
|
})
|
|
})
|