Files
Mangalord/frontend/e2e/continue-reading-shelf.spec.ts
MechaCat02 bfaa166e0a fix(home): keep finished series off the Continue-reading shelf
A "Continue reading" shelf listing series the reader already finished (read
to the last page, nothing new) is odd. Expose the last-read chapter's
page_count on the read-progress list, and filter the shelf to drop entries
that are caught up (on the last page of the latest chapter with no new
chapters). Mid-chapter and has-new-chapters entries stay; the full history
view is unaffected. Finished detection is a pure, unit-tested helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 21:52:58 +02:00

125 lines
4.8 KiB
TypeScript

import { test, expect, type Page } from './fixtures';
// The homepage "Continue reading" shelf: visible with a per-manga new-chapter
// badge when the user has reading history, and absent for anonymous visitors
// (the read-progress fetch 401s → empty → hidden).
const emptyMangas = { items: [], page: { limit: 50, offset: 0, total: 0 } };
async function mockCommon(page: Page) {
await page.route('**/api/v1/auth/config', (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ self_register_enabled: true, private_mode: false })
})
);
await page.route('**/api/v1/genres*', (route) =>
route.fulfill({ status: 200, contentType: 'application/json', body: '[]' })
);
await page.route('**/api/v1/mangas*', (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(emptyMangas)
})
);
}
test('shows the continue-reading shelf with a new-chapter badge when signed in', async ({ page }) => {
await mockCommon(page);
await page.route('**/api/v1/auth/me', (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ user: { id: 'u1', username: 'reader', is_admin: false } })
})
);
await page.route('**/api/v1/me/read-progress*', (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
items: [
{
manga_id: 'm1',
manga_title: 'Berserk',
manga_cover_image_path: null,
chapter_id: 'c1',
chapter_number: 3,
chapter_page_count: 20,
page: 4,
updated_at: '2026-01-01T00:00:00Z',
new_chapters_count: 2
}
],
page: { limit: 50, offset: 0, total: 1 }
})
})
);
await page.goto('/');
const card = page.getByTestId('continue-card-m1');
await expect(card).toBeVisible();
await expect(card).toHaveAttribute('href', '/manga/m1/chapter/c1?page=4');
await expect(page.getByTestId('continue-new-badge-m1')).toContainText('2');
});
test('keeps finished series off the shelf but shows in-progress ones', async ({ page }) => {
await mockCommon(page);
await page.route('**/api/v1/auth/me', (route) =>
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: { id: 'u1', username: 'reader', is_admin: false } }) })
);
await page.route('**/api/v1/me/read-progress*', (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
items: [
// Finished: last page of the latest chapter, nothing new.
{
manga_id: 'done', manga_title: 'Finished', manga_cover_image_path: null,
chapter_id: 'dc', chapter_number: 5, chapter_page_count: 10, page: 10,
updated_at: '2026-01-02T00:00:00Z', new_chapters_count: 0
},
// In progress: mid-chapter.
{
manga_id: 'wip', manga_title: 'Ongoing', manga_cover_image_path: null,
chapter_id: 'wc', chapter_number: 2, chapter_page_count: 10, page: 3,
updated_at: '2026-01-01T00:00:00Z', new_chapters_count: 0
}
],
page: { limit: 50, offset: 0, total: 2 }
})
})
);
await page.goto('/');
await expect(page.getByTestId('continue-card-wip')).toBeVisible();
await expect(page.getByTestId('continue-card-done')).toHaveCount(0);
});
test('hides the continue-reading shelf for anonymous visitors', async ({ page }) => {
await mockCommon(page);
await page.route('**/api/v1/auth/me', (route) =>
route.fulfill({
status: 401,
contentType: 'application/json',
body: JSON.stringify({ error: { code: 'unauthenticated', message: 'no' } })
})
);
await page.route('**/api/v1/me/read-progress*', (route) =>
route.fulfill({
status: 401,
contentType: 'application/json',
body: JSON.stringify({ error: { code: 'unauthenticated', message: 'no' } })
})
);
await page.goto('/');
// The catalogue heading confirms the page rendered before asserting absence.
await expect(page.getByRole('heading', { name: 'Mangas' })).toBeVisible();
await expect(page.getByTestId('continue-shelf')).toHaveCount(0);
});