978959bdc4
Operator feedback: thumbnails too small to judge order, no obvious way to mark
'this installment is Part 2', and the permanent two-pane picker was busy and
competed with the ordering work.
- Full-width parts, each a card with a big page grid (150px, contain so whole
pages are visible) and drag-to-reorder; positional page number as a badge.
- Editable Part # (hero field) backed by new series_chapter.stated_part —
separate from the auto-managed chapter_number, mirroring the page_number vs
stated_page split so reorder/delete renumbering can't wipe a hand-set part.
Missing-Part hints when consecutive parts' stated_part jump >1.
- Each part labels its source post (derived from pages' primary_post_id) and
shows the printed-page range with clear labels.
- Picker demoted to an on-demand right slide-over ('Add pages') with a target-
part selector; part actions (move/merge/delete) collapsed into an overflow ⋮.
alembic 0042 adds series_chapter.stated_part (nullable int).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
123 lines
4.4 KiB
JavaScript
123 lines
4.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('setChapterPart patches stated_part on the chapter', async () => {
|
|
const s = useSeriesManageStore()
|
|
s.tagId = 7
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, method: init.method, body: init.body ? JSON.parse(init.body) : null })
|
|
if (init.method === 'PATCH') return { status: 200, body: { ok: true } }
|
|
return { status: 200, body: SERIES_BODY }
|
|
})
|
|
await s.setChapterPart(1, 2)
|
|
const p = calls.find(c => c.method === 'PATCH')
|
|
expect(p.url).toContain('/api/series/7/chapters/1')
|
|
expect(p.body).toEqual({ stated_part: 2 })
|
|
})
|
|
|
|
it('load surfaces part_gaps and partGapAfter looks them up', async () => {
|
|
const s = useSeriesManageStore()
|
|
stubFetch(() => ({
|
|
status: 200,
|
|
body: { ...SERIES_BODY, part_gaps: [{ after_chapter_id: 1, start: 2, end: 2 }] }
|
|
}))
|
|
await s.load(7)
|
|
expect(s.partGaps).toHaveLength(1)
|
|
expect(s.partGapAfter(1)).toEqual({ after_chapter_id: 1, start: 2, end: 2 })
|
|
expect(s.partGapAfter(99)).toBeNull()
|
|
})
|
|
|
|
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([])
|
|
})
|
|
})
|