Files
govoplan-core/webui/conformance/tests/help-center.spec.ts
T

73 lines
4.9 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
async function installHelp(page: Page, language = "en") {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
await page.route("**/api/v1/docs/context?**", (route) => {
const topic = (id: string, title: string, metadata = {}) => ({
id, title, source_module_id: "forms", kind: "reference", anchor_id: `topic-${id}`, summary: "Application guidance", body: "Public service application instructions", order: 1,
active: true, layer: "configured", target_layer: "configured", links: [], unlocks: [], related_modules: [], area_module_ids: ["forms", "services"],
metadata: { tags: ["Application", "Antrag"], ...metadata }, blockers: { modules: [], capabilities: [], scopes: [], configuration: [] }
});
return route.fulfill({ json: {
actor: { documentation_type: new URL(route.request().url()).searchParams.get("type") ?? "user", available_documentation_types: ["user", "admin"] },
versions: { supported_versions: [], installed_versions: {}, fallback_policy: "Installed versions" },
topic_groups: { system: [], pattern: [], workflow: [], reference: [topic("service", "Service application"), topic("field", "Application field", { parent_topic_id: "service" })] },
layers: { configured: { modules: [{ id: "forms", name: language === "de" ? "Formulare" : "Forms" }, { id: "services", name: language === "de" ? "Leistungen" : "Services" }], routes: [], permissions: [] },
available: { routes: [] }, evidence: { optional_modules: [], sources: [] } }
} });
});
await page.goto(`/?help-center&language=${language}`);
await expect(page.locator(".docs-tree-page").filter({ hasText: "Service application" }).first()).toBeVisible();
return errors;
}
test("help keeps repeated topic selection and expansion local to the clicked occurrence", async ({ page }) => {
const errors = await installHelp(page);
const area = page.locator(".docs-tree-node").filter({ has: page.locator(":scope > .docs-tree-row > .docs-tree-page", { hasText: /^Services$/ }) }).first();
await area.locator(":scope > .docs-tree-row > .docs-tree-toggle").click();
const repeated = area.locator(".docs-tree-node").filter({ has: page.locator(":scope > .docs-tree-row > .docs-tree-page", { hasText: /^Service application$/ }) }).first();
await repeated.locator(":scope > .docs-tree-row > .docs-tree-page").click();
await expect(page.locator(".docs-tree-page.is-active")).toHaveCount(1);
await expect(repeated.locator(":scope > .docs-tree-row > .docs-tree-page")).toHaveClass(/is-active/);
await repeated.locator(":scope > .docs-tree-row > .docs-tree-toggle").click();
await expect(page.locator(".docs-tree-page").filter({ hasText: /^Application field$/ })).toHaveCount(1);
await page.reload();
await expect(area.locator(".docs-tree-page.is-active")).toHaveText("Service application");
await expect(page.locator(".docs-tree-page.is-active")).toHaveCount(1);
expect(errors).toEqual([]);
});
for (const language of ["en", "de"]) test(`help finds topics from tags and localized area names (${language})`, async ({ page }) => {
const errors = await installHelp(page, language);
const search = page.getByRole("searchbox");
await search.fill(language === "de" ? "leistungen antrag" : "services application");
const results = page.getByRole("region", { name: language === "de" ? "Passende Hilfethemen" : "Matching help topics" });
await expect(results.getByRole("option", { name: "Service application", exact: true })).toHaveCount(1);
await expect(results.getByRole("option", { name: "Application field", exact: true })).toHaveCount(1);
await search.fill("not-found-tag");
await expect(results.getByRole("option")).toHaveCount(0);
await search.fill("antrag");
await results.getByRole("option", { name: "Service application", exact: true }).click();
await expect(search).toHaveValue("");
await expect(page.locator(".docs-page-main h2")).toHaveText("Service application");
await expect(page.locator(".docs-tree-page.is-active")).toHaveCount(1);
expect(errors).toEqual([]);
});
test("help tag dropdown shares list filtering and all/none behavior", async ({ page }) => {
const errors = await installHelp(page);
await page.getByRole("button", { name: "Areas and tags", exact: true }).click();
const filter = page.getByRole("dialog", { name: "Areas and tags", exact: true });
await filter.getByRole("button", { name: /clear all|deselect all|select none/i }).click();
const results = page.getByRole("region", { name: "Matching help topics" });
await expect(results.getByRole("option")).toHaveCount(0);
await filter.getByRole("checkbox", { name: "Services", exact: true }).check();
await expect(results.getByRole("option")).toHaveCount(2);
await filter.getByRole("button", { name: "Select all", exact: true }).click();
await expect(results).toHaveCount(0);
await page.keyboard.press("Escape");
await expect(filter).toHaveCount(0);
expect(errors).toEqual([]);
});