diff --git a/frontend/e2e/bookmarks-load-more.spec.ts b/frontend/e2e/bookmarks-load-more.spec.ts new file mode 100644 index 0000000..157b6f7 --- /dev/null +++ b/frontend/e2e/bookmarks-load-more.spec.ts @@ -0,0 +1,73 @@ +import { test, expect, type Page } from './fixtures'; + +// The bookmarks list pages the results: the first 50 load with the page, and a +// "Load more" button fetches the next page (offset-based) and appends it, so +// bookmarks past the first page are reachable rather than silently truncated. + +function bookmark(i: number) { + return { + id: `bm-${i}`, + manga_id: `m-${i}`, + manga_title: `Manga ${i}`, + manga_cover_image_path: null, + chapter_id: null, + chapter_number: null, + page: null, + created_at: '2026-01-01T00:00:00Z' + }; +} + +async function authed(page: Page) { + await page.route('**/api/v1/auth/config', (r) => + r.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ self_register_enabled: true, private_mode: false }) + }) + ); + await page.route('**/api/v1/auth/me', (r) => + r.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ + user: { id: 'u1', username: 'reader', created_at: '2026-01-01T00:00:00Z', is_admin: false } + }) + }) + ); + await page.route('**/api/v1/auth/me/preferences', (r) => + r.fulfill({ status: 200, contentType: 'application/json', body: '{}' }) + ); + await page.route('**/api/v1/files/**', (r) => r.fulfill({ status: 200, body: '' })); +} + +test('bookmarks list loads more pages on demand', async ({ page }) => { + await authed(page); + // total = 60: first page 50 (offset 0), second page 10 (offset 50). + await page.route('**/api/v1/me/bookmarks*', (r) => { + const url = new URL(r.request().url()); + const offset = Number(url.searchParams.get('offset') ?? '0'); + const items = + offset === 0 + ? Array.from({ length: 50 }, (_, i) => bookmark(i)) + : Array.from({ length: 10 }, (_, i) => bookmark(50 + i)); + return r.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ items, page: { limit: 50, offset, total: 60 } }) + }); + }); + + await page.goto('/bookmarks'); + + // First page rendered; more remain so the button shows. + await expect(page.getByText('Manga 0')).toBeVisible(); + await expect(page.getByText('Manga 49')).toBeVisible(); + await expect(page.getByText('Manga 50')).toHaveCount(0); + const loadMore = page.getByTestId('load-more'); + await expect(loadMore).toBeVisible(); + + // Load the rest; the button disappears once everything is shown. + await loadMore.click(); + await expect(page.getByText('Manga 59')).toBeVisible(); + await expect(loadMore).toHaveCount(0); +}); diff --git a/frontend/e2e/collections-load-more.spec.ts b/frontend/e2e/collections-load-more.spec.ts new file mode 100644 index 0000000..81ea52d --- /dev/null +++ b/frontend/e2e/collections-load-more.spec.ts @@ -0,0 +1,74 @@ +import { test, expect, type Page } from './fixtures'; + +// The collections grid pages results: a "Load more" button fetches the next +// page (offset-based) and appends it, so collections past the first page are +// reachable rather than silently truncated at the old 200 cap. + +function collection(i: number) { + return { + id: `col-${i}`, + user_id: 'u1', + name: `Collection ${i}`, + description: null, + created_at: '2026-01-01T00:00:00Z', + updated_at: '2026-01-01T00:00:00Z', + manga_count: 0, + sample_covers: [] + }; +} + +async function authed(page: Page) { + await page.route('**/api/v1/auth/config', (r) => + r.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ self_register_enabled: true, private_mode: false }) + }) + ); + await page.route('**/api/v1/auth/me', (r) => + r.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ + user: { id: 'u1', username: 'reader', created_at: '2026-01-01T00:00:00Z', is_admin: false } + }) + }) + ); + await page.route('**/api/v1/auth/me/preferences', (r) => + r.fulfill({ status: 200, contentType: 'application/json', body: '{}' }) + ); + await page.route('**/api/v1/me/bookmarks*', (r) => + r.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ items: [], page: { limit: 50, offset: 0, total: 0 } }) + }) + ); +} + +test('collections grid loads more pages on demand', async ({ page }) => { + await authed(page); + await page.route('**/api/v1/me/collections*', (r) => { + const offset = Number(new URL(r.request().url()).searchParams.get('offset') ?? '0'); + const items = + offset === 0 + ? Array.from({ length: 60 }, (_, i) => collection(i)) + : Array.from({ length: 5 }, (_, i) => collection(60 + i)); + return r.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ items, page: { limit: 60, offset, total: 65 } }) + }); + }); + + await page.goto('/collections'); + + await expect(page.getByText('Collection 0')).toBeVisible(); + await expect(page.getByText('Collection 64')).toHaveCount(0); + const loadMore = page.getByTestId('load-more'); + await expect(loadMore).toBeVisible(); + + await loadMore.click(); + await expect(page.getByText('Collection 64')).toBeVisible(); + await expect(loadMore).toHaveCount(0); +}); diff --git a/frontend/package.json b/frontend/package.json index b64131a..9aa9fb7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "mangalord-frontend", - "version": "0.127.1", + "version": "0.127.2", "private": true, "type": "module", "scripts": { diff --git a/frontend/src/lib/components/LoadMore.svelte b/frontend/src/lib/components/LoadMore.svelte new file mode 100644 index 0000000..0698a98 --- /dev/null +++ b/frontend/src/lib/components/LoadMore.svelte @@ -0,0 +1,83 @@ + + +{@render children(all)} + +{#if hasMore} +
{error}
+ {/if} +No bookmarks yet.
{:else} -