dorfteich/apps/web/e2e/backlinks.spec.ts
Claude Opus 4.8 6c38abc20c
All checks were successful
CD / Build and push images (push) Successful in 3m3s
CI / Lint, typecheck, test (push) Successful in 2m15s
CI / Auth e2e pack (push) Successful in 2m49s
CI / Build container images (push) Has been skipped
CD / Deploy to Test (push) Successful in 8s
CD / Smoke tests against Test (push) Successful in 1m12s
CD / Promote to Int (push) Successful in 11s
Add backlinks panel and phantom-pages view (#48)
Make wikilink relations visible: what links here, and which linked pages
do not exist yet.

- shared: `BacklinkView` gains a plain-text `snippet` for context.
- api: `LinksService` includes a short snippet (from the content cache) with
  each backlink and phantom referrer.
- web:
  - `BacklinksPanel` below a page in read mode: a collapsible "Linked from"
    list (title + snippet, links to the source), hidden when empty. Appears
    on load from the #47 index.
  - `PhantomPagesView` in pond settings: wikilink targets that do not exist
    yet, each with its referrers and a create shortcut that makes the page
    under the phantom slug — resolving those links (#47) and navigating to it.
  - i18n `links` namespace (de + en); backlinks + missing-pages styles.
- e2e `backlinks.spec.ts` (new CI pack): a link created in the editor appears
  as a backlink on the target; the missing-pages view lists a phantom slug and
  creating it navigates to the new page.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PGdhRiwU1WRL4XxJfZYipY
2026-07-09 13:05:32 +02:00

87 lines
3.7 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { contextForUser } from './helpers';
/**
* Backlinks + missing-pages pack (issue #48). Drives the editor to create
* wikilinks (persisted via collab, indexed by #47), then checks the read-mode
* "Linked from" panel and the pond's missing-pages view. Language-independent
* selectors (CSS classes + page titles/slugs).
*/
const BASE_URL = process.env.E2E_BASE_URL ?? 'http://localhost:5173';
type Ctx = Awaited<ReturnType<typeof contextForUser>>;
async function personalPond(context: Ctx): Promise<{ id: string; slug: string }> {
const ponds = await context.request.get('/api/v1/ponds');
const pond = (await ponds.json()).find((p: { type: string }) => p.type === 'personal');
return { id: pond.id, slug: pond.slug };
}
async function createPage(context: Ctx, pondId: string, title: string): Promise<{ slug: string }> {
const created = await context.request.post(`/api/v1/ponds/${pondId}/pages`, { data: { title } });
return created.json();
}
/** Types a `[[query` in the editor and picks the first suggestion. */
async function insertWikilink(page: import('@playwright/test').Page, query: string): Promise<void> {
const body = page.locator('.editor-content .ProseMirror');
await body.click();
await page.keyboard.type(`[[${query}`);
await expect(page.locator('.wikilink-suggest')).toBeVisible();
await page.keyboard.press('Enter');
}
test('a backlink appears on the target page after another page links it', async ({ browser }) => {
const context = await contextForUser(browser, BASE_URL, 'fixture-user');
const pond = await personalPond(context);
const ts = Date.now();
const targetTitle = `BL Target ${ts}`;
const sourceTitle = `BL Source ${ts}`;
const target = await createPage(context, pond.id, targetTitle);
const source = await createPage(context, pond.id, sourceTitle);
const page = await context.newPage();
await page.goto(`/p/${pond.slug}/${source.slug}`);
await page.locator('.editor-page__mode-toggle').click();
await insertWikilink(page, targetTitle);
// Reload disconnects the collab session, flushing the store → page_links row.
await page.reload();
await expect(page.locator('.editor-content a.wikilink', { hasText: targetTitle })).toBeVisible();
// Open the target in read mode: the "Linked from" panel lists the source.
await page.goto(`/p/${pond.slug}/${target.slug}`);
const backlinks = page.locator('.backlinks');
await expect(backlinks).toBeVisible();
await expect(backlinks.locator('.backlinks__link', { hasText: sourceTitle })).toBeVisible();
await context.close();
});
test('missing-pages view lists a phantom target and creates it', async ({ browser }) => {
const context = await contextForUser(browser, BASE_URL, 'fixture-user');
const pond = await personalPond(context);
const ts = Date.now();
const ghostSlug = `ghost-page-${ts}`;
const source = await createPage(context, pond.id, `Ghost Source ${ts}`);
const page = await context.newPage();
await page.goto(`/p/${pond.slug}/${source.slug}`);
await page.locator('.editor-page__mode-toggle').click();
// No page matches, so the only suggestion is the create-phantom hint.
await insertWikilink(page, ghostSlug);
await page.reload();
await expect(page.locator('.editor-content a.wikilink.wikilink--phantom')).toBeVisible();
// The pond's missing-pages view lists the phantom slug.
await page.goto(`/p/${pond.slug}/settings`);
const item = page.locator('.phantom-pages__item', { hasText: ghostSlug });
await expect(item).toBeVisible();
// Creating it navigates to the new page (slug = phantom slug).
await item.getByRole('button').click();
await expect(page).toHaveURL(new RegExp(`/p/${pond.slug}/${ghostSlug}$`));
await context.close();
});