dorfteich/apps/web/e2e/trash.spec.ts
Claude Sonnet 5 a645763679
All checks were successful
CD / Build and push images (push) Successful in 2m5s
CI / Lint, typecheck, test (push) Successful in 1m45s
CI / Auth e2e pack (push) Successful in 1m50s
CI / Build container images (push) Has been skipped
CD / Deploy to Test (push) Successful in 8s
CD / Smoke tests against Test (push) Successful in 1m11s
CD / Promote to Int (push) Successful in 10s
Add page trash: soft delete, restore, and purge job (#31)
Backend: a generic maintenance-job scheduler (SchedulerService, `jobs`
table) that any later maintenance job registers with instead of
growing its own timer loop. Due-ness and the run-mutex both live in
the DB row (`lastRunAt` survives a restart; claiming a due job is one
atomic `UPDATE ... WHERE status != 'RUNNING'`), and an injectable
ClockService lets tests simulate retention elapsing without waiting or
faking the global clock.

Trash endpoints: GET /ponds/:id/trash (list), POST /pages/:id/restore,
DELETE /pages/:id/purge (manual, bypasses retention) — all sharing the
same purge logic as the scheduled daily job (default 30-day retention,
new trash.retentionDays instance setting). Purging deletes a page's
content cache, update log, and attachment files/quota; page_versions
is a placeholder until M3 exists. Direct navigation to a trashed page
now 404s with a distinguishable `page_trashed` code for editors (a
plain 404 for everyone else) instead of the generic not-found.

Attachment.pageId — added in #27 but never wired up — now gets set on
every page state save to whichever page's document currently embeds
the file, which is what lets purge find a page's files.

Frontend: a per-pond trash view (restore/purge), a "move to trash"
action with confirmation in the page menu, and a trash link in the
sidebar for pond owners. Also fixes react-query retrying 4xx responses
for several seconds by default, which was masking the trash-hint 404
in the UI (and would have affected any other not-found/permission
error the same way).

Closes #31
2026-07-08 12:48:17 +02:00

100 lines
3.9 KiB
TypeScript

import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { contextForUser } from './helpers';
/**
* Page trash pack (issue #31). Runs against the local dev stack (api +
* web); no Mailpit needed. The fixture pond accumulates pages across many
* e2e runs, so trash-list assertions always scope to this test's own
* unique title rather than matching by loose/shared text.
*/
const BASE_URL = process.env.E2E_BASE_URL ?? 'http://localhost:5173';
async function createPage(
context: Awaited<ReturnType<typeof contextForUser>>,
title: string,
): Promise<{ pondSlug: string; pageSlug: string }> {
const ponds = await context.request.get('/api/v1/ponds');
const pond = (await ponds.json()).find((p: { type: string }) => p.type === 'personal');
const created = await context.request.post(`/api/v1/ponds/${pond.id}/pages`, {
data: { title },
});
const page = await created.json();
return { pondSlug: pond.slug, pageSlug: page.slug };
}
function acceptDialogs(page: Page): void {
page.on('dialog', (dialog) => void dialog.accept());
}
/** The trash list row for an exact page title, scoping restore/purge clicks to it. */
function trashItem(page: Page, title: string) {
return page.locator('.trash-page__item').filter({ hasText: title });
}
test('deleting a page hides it from the sidebar and shows a trash hint on direct URL', async ({
browser,
}) => {
const context = await contextForUser(browser, BASE_URL, 'fixture-user');
const { pondSlug, pageSlug } = await createPage(context, `E2E Trash Delete ${Date.now()}`);
const page = await context.newPage();
acceptDialogs(page);
await page.goto(`/p/${pondSlug}/${pageSlug}`);
await page.getByRole('button', { name: /edit|bearbeiten/i }).click();
await page.getByRole('button', { name: /move to trash|papierkorb verschieben/i }).click();
// Deleting navigates away; going back to the same URL now 404s with a hint.
await page.goto(`/p/${pondSlug}/${pageSlug}`);
await expect(page.getByText(/moved to the trash|papierkorb verschoben/i)).toBeVisible();
await expect(
page.getByRole('link', { name: /view in trash|im papierkorb ansehen/i }),
).toBeVisible();
await context.close();
});
test('restoring a page from the trash brings it back', async ({ browser }) => {
const context = await contextForUser(browser, BASE_URL, 'fixture-user');
const title = `E2E Trash Restore ${Date.now()}`;
const { pondSlug, pageSlug } = await createPage(context, title);
const page = await context.newPage();
acceptDialogs(page);
await page.goto(`/p/${pondSlug}/${pageSlug}`);
await page.getByRole('button', { name: /edit|bearbeiten/i }).click();
await page.getByRole('button', { name: /move to trash|papierkorb verschieben/i }).click();
await page.goto(`/p/${pondSlug}/trash`);
const item = trashItem(page, title);
await expect(item).toBeVisible();
await item.getByRole('button', { name: /restore|wiederherstellen/i }).click();
await expect(item).toHaveCount(0);
await page.goto(`/p/${pondSlug}/${pageSlug}`);
await expect(page.locator('.editor-page__title')).toHaveValue(title);
await context.close();
});
test('purging a page from the trash removes it for good', async ({ browser }) => {
const context = await contextForUser(browser, BASE_URL, 'fixture-user');
const title = `E2E Trash Purge ${Date.now()}`;
const { pondSlug, pageSlug } = await createPage(context, title);
const page = await context.newPage();
acceptDialogs(page);
await page.goto(`/p/${pondSlug}/${pageSlug}`);
await page.getByRole('button', { name: /edit|bearbeiten/i }).click();
await page.getByRole('button', { name: /move to trash|papierkorb verschieben/i }).click();
await page.goto(`/p/${pondSlug}/trash`);
const item = trashItem(page, title);
await expect(item).toBeVisible();
await item.getByRole('button', { name: /delete forever|endgültig löschen/i }).click();
await expect(item).toHaveCount(0);
await context.close();
});