From a081f0b565c60d836faa74a4e6312a7f1203ea86 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Sat, 21 Nov 2026 19:23:27 +0000 Subject: [PATCH] test(e2e): write the GEMMA plate peers and previous-catalogue import specs Two Playwright specs the open tasks name and the repository lacked, written from the changes' scenarios and not run: - spec-coverage/gemma-plate-peers.spec.ts (REQ-GPL-002): the peers endpoint counts only organisations of the same type and inhabitants band and names none; the table and side panel cases are fixme until the layer lands. - spec-coverage/legacy-catalogue-import.spec.ts (REQ-LCM-001 to 003): every case fixme until the profile, endpoints, dialog and fixture exist. Assisted-by: ClaudeCode:claude-opus-5-5 --- .../tasks.md | 1 + .../spec-coverage/gemma-plate-peers.spec.ts | 206 ++++++++++++++++++ .../legacy-catalogue-import.spec.ts | 160 ++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 tests/e2e/spec-coverage/gemma-plate-peers.spec.ts create mode 100644 tests/e2e/spec-coverage/legacy-catalogue-import.spec.ts diff --git a/openspec/changes/landscape-migrate-from-previous-catalogue/tasks.md b/openspec/changes/landscape-migrate-from-previous-catalogue/tasks.md index 3ced65387..f4cc67a86 100644 --- a/openspec/changes/landscape-migrate-from-previous-catalogue/tasks.md +++ b/openspec/changes/landscape-migrate-from-previous-catalogue/tasks.md @@ -38,6 +38,7 @@ - GIVEN the modal WHEN used THEN it has three steps: file, preview (rows with match or create, a checkbox per row) and result (created, updated, skipped with reasons) - [ ] Implement - [ ] Test (vitest `legacyCatalogueImportModal.spec.js`, Playwright `legacy-catalogue-import.spec.ts`) + - Written 21 Nov: `tests/e2e/spec-coverage/legacy-catalogue-import.spec.ts` from the four scenarios, every case marked fixme until the profile, the endpoints, the dialog and the fixture exist; not run. ### Task 5: Documentation - **spec_ref**: openspec/changes/landscape-migrate-from-previous-catalogue/specs/legacy-catalogue-migration/spec.md diff --git a/tests/e2e/spec-coverage/gemma-plate-peers.spec.ts b/tests/e2e/spec-coverage/gemma-plate-peers.spec.ts new file mode 100644 index 000000000..92db221cc --- /dev/null +++ b/tests/e2e/spec-coverage/gemma-plate-peers.spec.ts @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: EUPL-1.2 +// SPDX-FileCopyrightText: 2026 Conduction B.V. +/** + * The GEMMA plate layer "What comparable organisations use" (board + * SkGemmaPlaat, REQ-GPL-002): per reference component the organisation's own + * applications and what organisations of the same type and inhabitants band + * use, with counts, never naming an organisation, and "fewer than 3" for a + * count below three. + * + * Seeds, all carrying this run's RUN_ID, two reference components in the + * GEMMA register and, in the voorzieningen register: + * - the own municipality (45,000 inhabitants) using "own app" for the case + * component and nothing for the knowledge component; + * - three comparable municipalities (30,000 to 60,000) using "peer app" for + * the case component and "knowledge app" for the knowledge component, and + * one of them also "rare app" for the case component; + * - one municipality outside the band (200,000) using "peer app", which must + * not raise its count. + * Exactly those rows are removed afterwards. The counting rules are covered + * by tests/Unit/Service/PeerUsageServiceTest.php. + * + * The endpoint scenario runs against development. The two plate scenarios + * read the layer switch, table and side panel line of task 4, which are not + * on development yet, so they are marked fixme until that task lands. + * + * Written from the change's scenarios; not yet run against a live instance. + * + * @spec openspec/changes/gemma-plate-views-peers-and-definitions/specs/gemma-plate/spec.md#requirement-the-plate-shows-what-comparable-organisations-use-req-gpl-002 + */ +import type { APIRequestContext, Page } from '@playwright/test' +import type { VoorzieningenConfig } from '../workflows/_fixtures.ts' + +import { expect, test } from '@playwright/test' +import { + createObject, + deleteObject, + newApiContext, + resolveConfig, + RUN_ID, +} from '../workflows/_fixtures.ts' +import { dismissSupportDialog, gotoAppRoute } from './_helpers.ts' + +const GEMMA_REGISTER = 'vng-gemma' +const PEERS = '/index.php/apps/stackiq/api/reference-component-coverage/peers' + +let apiCtx: APIRequestContext +let cfg: VoorzieningenConfig +const seeded: Array<[string, string, string]> = [] +const ids: Record = {} + +const own = `${RUN_ID} own municipality` +const peerNames = [1, 2, 3].map((n) => `${RUN_ID} comparable municipality ${n}`) +const outsider = `${RUN_ID} large municipality` +const caseComponent = `${RUN_ID} case handling component` +const knowledgeComponent = `${RUN_ID} knowledge base component` +const ownApp = `${RUN_ID} own app` +const peerApp = `${RUN_ID} peer app` +const knowledgeApp = `${RUN_ID} knowledge app` +const rareApp = `${RUN_ID} rare app` + +/** + * Create a row and remember it for cleanup. + * + * @param register The register slug. + * @param schema The schema slug. + * @param data The object. + * @return The new id. + */ +async function seed( + register: string, + schema: string, + data: Record, +): Promise { + const id = await createObject(apiCtx, register, schema, data) + seeded.push([register, schema, id]) + return id +} + +/** + * Register a usage of a module for reference components. + * + * @param consumer The organisation id. + * @param module The module id. + * @param components The reference component ids. + * @return The new id. + */ +async function use(consumer: string, module: string, components: string[]): Promise { + return seed(cfg.register, 'usage', { + consumer, + module, + status: 'In production', + usedForReferenceComponents: components, + }) +} + +/** + * Open the plate for the own municipality and switch the peers layer on. + * + * @param page The page. + */ +async function openPlateWithPeers(page: Page): Promise { + await gotoAppRoute(page, '/gemma-plaat') + await dismissSupportDialog(page) + await page.getByRole('combobox', { name: 'Organisation' }).fill(own) + await page.locator('.vs__dropdown-option', { hasText: own }).first().click() + await page.getByTestId('gemma-plate-layer-peers').getByRole('switch').check() + await expect(page.getByTestId('gemma-plate-peers')).toBeVisible({ timeout: 30000 }) +} + +test.beforeAll(async () => { + apiCtx = await newApiContext() + cfg = await resolveConfig(apiCtx) + + for (const [key, name] of [['case', caseComponent], ['knowledge', knowledgeComponent]]) { + ids[key] = await seed(GEMMA_REGISTER, 'element', { + identifier: `${RUN_ID}-${key}`, + type: 'ApplicationComponent', + properties: [], + name, + gemmaType: 'referentiecomponent', + grouping: RUN_ID, + }) + } + + for (const [key, name] of [['own', ownApp], ['peer', peerApp], ['knowledge', knowledgeApp], ['rare', rareApp]]) { + ids[`app-${key}`] = await seed(cfg.register, 'module', { name }) + } + + ids.own = await seed(cfg.register, 'organization', { name: own, type: 'Municipality', inhabitants: 45000 }) + await use(ids.own, ids['app-own'], [ids.case]) + + for (const [index, name] of peerNames.entries()) { + const peer = await seed(cfg.register, 'organization', { + name, + type: 'Municipality', + inhabitants: 32000 + (index * 10000), + }) + await use(peer, ids['app-peer'], [ids.case]) + await use(peer, ids['app-knowledge'], [ids.knowledge]) + if (index === 0) { + await use(peer, ids['app-rare'], [ids.case]) + } + } + + const large = await seed(cfg.register, 'organization', { name: outsider, type: 'Municipality', inhabitants: 200000 }) + await use(large, ids['app-peer'], [ids.case]) +}) + +test.afterAll(async () => { + if (!apiCtx) return + for (const [register, schema, id] of seeded.reverse()) { + await deleteObject(apiCtx, register, schema, id) + } + await apiCtx.dispose() +}) + +// @e2e gemma-plate::a-municipality-compares-its-case-handling +// @e2e gemma-plate::a-rare-choice-stays-anonymous +test('the peers endpoint counts comparable organisations only and never names one', async () => { + const response = await apiCtx.get(`${PEERS}?organisation=${encodeURIComponent(ids.own)}`) + expect(response.ok()).toBeTruthy() + const body = await response.text() + + // No organisation is ever named, not the peers and not the one outside the band. + for (const name of [...peerNames, outsider]) { + expect(body).not.toContain(name) + } + + const json = JSON.parse(body) + expect(json?.comparable?.type).toBe('Municipality') + expect(json?.comparable?.band).toEqual({ min: 30000, max: 60000 }) + + const serialised = JSON.stringify(json) + expect(serialised).toContain(peerApp) + expect(serialised).toContain(knowledgeApp) + expect(serialised).toContain(rareApp) +}) + +// @e2e gemma-plate::a-municipality-compares-its-case-handling +// @e2e gemma-plate::a-rare-choice-stays-anonymous +test.fixme('the table shows own applications and what comparable organisations use', async ({ page }) => { + await openPlateWithPeers(page) + + const table = page.getByTestId('gemma-plate-peers') + await expect(table).toContainText('What comparable organisations use: Municipality') + const row = table.locator('tr', { hasText: caseComponent }) + await expect(row.locator('.peer-usage__own')).toContainText(ownApp) + await expect(row.locator('.peer-usage__peers')).toContainText(`${peerApp} (3)`) + await expect(row.locator('.peer-usage__peers')).toContainText(`${rareApp} (fewer than 3)`) + for (const name of [...peerNames, outsider]) { + await expect(table).not.toContainText(name) + } +}) + +// @e2e gemma-plate::a-gap-that-peers-fill +test.fixme('a gap shows in the side panel with what comparable organisations use for it', async ({ page }) => { + await openPlateWithPeers(page) + + const tile = page.getByTestId('gemma-plate-groups').getByRole('button', { name: new RegExp(knowledgeComponent) }) + await expect(tile).toHaveAttribute('data-state', 'gap') + await tile.click() + + const detail = page.getByTestId('gemma-plate-detail') + await expect(detail).toContainText(knowledgeComponent) + await expect(detail.getByTestId('gemma-plate-detail-peers')).toContainText(`${knowledgeApp} (3)`) +}) diff --git a/tests/e2e/spec-coverage/legacy-catalogue-import.spec.ts b/tests/e2e/spec-coverage/legacy-catalogue-import.spec.ts new file mode 100644 index 000000000..30a3e0e78 --- /dev/null +++ b/tests/e2e/spec-coverage/legacy-catalogue-import.spec.ts @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: EUPL-1.2 +// SPDX-FileCopyrightText: 2026 Conduction B.V. +/** + * Bringing over what an organisation registered in the previous + * Softwarecatalogus (board SkApplicaties; REQ-LCM-001 to REQ-LCM-003): the + * Applications actions menu opens a three-step dialog (file, preview, result) + * that reads the previous catalogue's export, shows per row whether supplier, + * product and usage are matched or created, writes nothing before the user + * confirms, and updates instead of duplicating on a second run. + * + * Not built yet: the import profile, the preview and apply endpoints + * (`POST /api/legacy-import/preview`, `POST /api/legacy-import/apply`), the + * dialog and the fixture `tests/fixtures/vng-swc-export.xlsx` are tasks 1 to 4 + * of the change. Every scenario is marked fixme until they exist; the labels + * below follow the spec and the dialog may name them differently once built. + * + * Seeds, carrying this run's RUN_ID, the organisation the user imports for. + * The rows the import creates are found by their `legacyId` and removed + * afterwards. + * + * Written from the change's scenarios; not yet run against a live instance. + * + * @spec openspec/changes/landscape-migrate-from-previous-catalogue/specs/legacy-catalogue-migration/spec.md + */ +import type { APIRequestContext, Page } from '@playwright/test' +import type { VoorzieningenConfig } from '../workflows/_fixtures.ts' + +import { expect, test } from '@playwright/test' +import * as path from 'path' +import { + createObject, + deleteObject, + findAll, + newApiContext, + resolveConfig, + RUN_ID, +} from '../workflows/_fixtures.ts' +import { APP_MAIN, dismissSupportDialog, gotoAppRoute } from './_helpers.ts' + +const FIXTURES = path.resolve(__dirname, '../../fixtures') +const EXPORT_FILE = path.join(FIXTURES, 'vng-swc-export.xlsx') +const MENU_ITEM = 'Bring over from the previous Softwarecatalogus' + +let apiCtx: APIRequestContext +let cfg: VoorzieningenConfig +let organisationId = '' +const organisation = `${RUN_ID} Gemeente Zuiddrecht` + +/** + * Open the import dialog from the Applications actions menu. + * + * @param page The page. + */ +async function openImport(page: Page): Promise { + await gotoAppRoute(page, '/modules') + await dismissSupportDialog(page) + await page.locator(APP_MAIN).getByRole('button', { name: 'Actions' }).first().click() + await page.getByRole('menuitem', { name: MENU_ITEM }).click() + await expect(page.getByRole('dialog', { name: MENU_ITEM })).toBeVisible({ timeout: 30000 }) +} + +/** + * Pick a file in the dialog's first step and go to the preview. + * + * @param page The page. + * @param file The file to upload. + */ +async function pickFile(page: Page, file: string): Promise { + const dialog = page.getByRole('dialog', { name: MENU_ITEM }) + await dialog.locator('input[type="file"]').setInputFiles(file) + await dialog.getByRole('button', { name: 'Preview' }).click() +} + +/** + * Usages of this run's organisation that came from the previous catalogue. + * + * @return The usages with a legacyId. + */ +async function importedUsages(): Promise>> { + const usages = await findAll(apiCtx, cfg.register, 'usage', '') + return usages.filter((usage) => usage.consumer === organisationId && usage.legacyId) +} + +test.beforeAll(async () => { + apiCtx = await newApiContext() + cfg = await resolveConfig(apiCtx) + organisationId = await createObject(apiCtx, cfg.register, 'organization', { name: organisation, type: 'Municipality' }) +}) + +test.afterAll(async () => { + if (!apiCtx) return + if (organisationId) { + for (const usage of await importedUsages()) { + await deleteObject(apiCtx, cfg.register, 'usage', String(usage.id)) + } + await deleteObject(apiCtx, cfg.register, 'organization', organisationId) + } + await apiCtx.dispose() +}) + +// @e2e legacy-catalogue-migration::opening-the-import +test.fixme('the preview opens and nothing is written before the user confirms', async ({ page }) => { + await openImport(page) + await pickFile(page, EXPORT_FILE) + + const dialog = page.getByRole('dialog', { name: MENU_ITEM }) + await expect(dialog.getByTestId('legacy-import-preview')).toBeVisible({ timeout: 30000 }) + expect(await importedUsages()).toHaveLength(0) +}) + +// @e2e legacy-catalogue-migration::a-file-that-is-not-an-export +test.fixme('a spreadsheet without the expected columns is refused with their names', async ({ page }) => { + await openImport(page) + await pickFile(page, path.join(FIXTURES, 'cmdb', 'topdesk-export-anonymised.xlsx')) + + const dialog = page.getByRole('dialog', { name: MENU_ITEM }) + await expect(dialog.getByRole('alert')).toContainText('missing', { timeout: 30000 }) + await expect(dialog.getByTestId('legacy-import-preview')).toHaveCount(0) + expect(await importedUsages()).toHaveLength(0) +}) + +// @e2e legacy-catalogue-migration::a-known-supplier-and-product +// @e2e legacy-catalogue-migration::an-unknown-product +test.fixme('the preview shows matched and created per row', async ({ page }) => { + await openImport(page) + await pickFile(page, EXPORT_FILE) + + const preview = page.getByRole('dialog', { name: MENU_ITEM }).getByTestId('legacy-import-preview') + await expect(preview.getByText('matched').first()).toBeVisible({ timeout: 30000 }) + await expect(preview.getByText('create').first()).toBeVisible() +}) + +// @e2e legacy-catalogue-migration::the-first-run +// @e2e legacy-catalogue-migration::running-it-again +test.fixme('the result counts created and skipped rows, and a second run duplicates nothing', async ({ page }) => { + await openImport(page) + await pickFile(page, EXPORT_FILE) + + const dialog = page.getByRole('dialog', { name: MENU_ITEM }) + const rows = dialog.getByTestId('legacy-import-preview').getByRole('checkbox') + await expect(rows.first()).toBeVisible({ timeout: 30000 }) + const total = await rows.count() + await rows.first().uncheck() + await dialog.getByRole('button', { name: 'Import' }).click() + + const result = dialog.getByTestId('legacy-import-result') + await expect(result).toContainText(`created ${total - 1}`, { timeout: 60000 }) + await expect(result).toContainText('skipped 1') + const first = await importedUsages() + expect(first).toHaveLength(total - 1) + + // The same export again: updated, never duplicated. + await openImport(page) + await pickFile(page, EXPORT_FILE) + await dialog.getByRole('button', { name: 'Import' }).click() + await expect(dialog.getByTestId('legacy-import-result')).toContainText('created 0', { timeout: 60000 }) + const second = await importedUsages() + expect(second.length).toBeLessThanOrEqual(total) + expect(new Set(second.map((usage) => usage.legacyId)).size).toBe(second.length) +})