test: qualify connected CV creation and responsive read recovery

This commit is contained in:
cesnimda
2026-11-18 01:05:19 +01:00
parent 5262bee15a
commit a88e260d39
2 changed files with 110 additions and 8 deletions
@@ -3,6 +3,9 @@ import AxeBuilder from '@axe-core/playwright';
import { translations } from '../src/i18n/translations';
import type { CvTheme, CvVariant, CvVariantSummary } from '../src/cvBuilder';
import { emptyStructuredCv } from '../src/profileCv';
import { readFile } from 'node:fs/promises';
import { createHash } from 'node:crypto';
import type { StructuredCvProfile } from '../src/profileCv';
const apiUrl = 'http://localhost:5302/api';
const password = 'E2ePassword123!';
@@ -257,6 +260,96 @@ test('[P7-04 PRES-C05 C08 E08] locale-retained create draft locks during held fa
qualification: 'Locale is changed through the real header after cancelling the draft dialog. First create is a controlled500; only explicit retry reaches actual HTTP creation. No model/provider or source write.' }), contentType: 'application/json' });
});
// This journey exercises the creation dialog; the import/export suite seeds variants through HTTP.
test('[P7-04 connected C01 C05 C07 C08 C10] native profile save to selected-source CV creation, scoped edit, preview and explicit PDF', async ({ page, owner }, info) => {
test.setTimeout(180_000);
const t = translations.en;
type Career = { revision: number; profile: StructuredCvProfile; cvText: string | null };
await seedSource(page, owner);
const seeded = await json<Career>(await page.request.get(`${apiUrl}/career/profile`));
seeded.profile.metadata.fields['jobs.0.title'] = { method: 'manual', reviewState: 'reviewed', sourceSnippet: 'Synthetic owner-reviewed career source note.' };
await json(await page.request.put(`${apiUrl}/career/profile`, { headers: owner.headers,
data: { expectedVersion: seeded.revision, profile: seeded.profile, cvText: seeded.cvText } }));
const before = await json<Career>(await page.request.get(`${apiUrl}/career/profile`));
expect(before.profile.metadata.fields['jobs.0.title']).toMatchObject(seeded.profile.metadata.fields['jobs.0.title']);
const beforeHistory = await json<unknown[]>(await page.request.get(`${apiUrl}/career/profile/versions`));
const sibling = await createVariant(page.request, owner, 'Untouched connected-journey sibling');
await enter(page, owner);
await page.goto('/career?section=profile');
await page.getByLabel(t.profileCvContactPhone, { exact: true }).fill('+47 900 00 077');
const savedProfile = page.waitForResponse(response => response.url() === `${apiUrl}/career/profile` && response.request().method() === 'PUT');
await page.getByRole('button', { name: t.profileSaveChanges, exact: true }).press('Enter');
const saved = await json<Career>(await savedProfile);
expect((await savedProfile).request().postDataJSON().expectedVersion).toBe(before.revision);
expect(saved.revision).toBe(before.revision + 1);
expect(saved.profile).toEqual({ ...before.profile, contact: { ...before.profile.contact, phone: '+47 900 00 077' } });
expect(saved.cvText).toBe(before.cvText);
const source = await readSource(page.request);
expect(source.canonical).toEqual(saved);
expect(source.history).toHaveLength(beforeHistory.length + 1);
const canonicalWrites: string[] = [];
const exports: string[] = [];
page.on('request', request => {
const url = new URL(request.url());
if (url.pathname === '/api/career/profile' && request.method() === 'PUT') canonicalWrites.push(url.pathname);
if (url.pathname.endsWith('/export-pdf')) exports.push(url.pathname);
});
await page.goto('/career?section=overview');
await page.getByRole('link', { name: t.careerOverviewOpenBuilder, exact: true }).click();
const dialog = await openCreate(page);
const name = 'Explicit selected-source CV — æøå';
await dialog.getByLabel(t.cvEditorName, { exact: false }).fill(name);
await dialog.getByRole('radio', { name: t.cvDashboardFromProfile, exact: true }).check();
const contact = dialog.getByRole('checkbox', { name: t.cvEditorIncludeProfileContact, exact: true });
const experience = dialog.getByRole('checkbox', { name: 'Professional Experience', exact: true });
await expect(contact).not.toBeChecked(); await expect(experience).not.toBeChecked();
await contact.check(); await experience.check();
await expect(dialog.getByRole('checkbox', { name: t.cvSectionSummary, exact: true })).not.toBeChecked();
await dialog.getByRole('button', { name: t.cvTemplateMinimalName, exact: true }).click();
const creating = page.waitForResponse(response => response.url() === `${apiUrl}/cv/variants` && response.request().method() === 'POST');
await dialog.getByRole('button', { name: t.cvDashboardCreateCv, exact: true }).press('Enter');
const created = await json<CvVariant>(await creating);
expect(created.settings).toMatchObject({ sectionsExplicit: true, includeProfileContact: true, sections: [{ key: 'experience' }] });
await expect(page).toHaveURL(new RegExp(`/career/builder/${created.id}(?:[?#]|$)`));
await expect(page.getByLabel(t.cvEditorName, { exact: true })).toHaveValue(name);
const url = `${apiUrl}/cv/variants/${created.id}`;
await page.getByRole('button', { name: t.cvEditorExpandSection.replace('{section}', t.cvSectionExperience), exact: true }).click();
const entry = page.getByRole('group', { name: t.cvSectionExperience, exact: true }).getByRole('group', { name: 'Recorded engineer', exact: true });
const tailored = 'CV-only reviewed community coordinator — æøå';
await entry.getByLabel(t.cvEditorEntryTitle, { exact: true }).fill(tailored);
await expect.poll(async () => (await json<CvVariant>(await page.request.get(url))).settings.overrides['library-source-job']?.title).toBe(tailored);
await expect(page.getByText(t.cvEditorSaved, { exact: true })).toBeVisible();
const edited = await json<CvVariant>(await page.request.get(url));
expect(edited.version).toBeGreaterThan(created.version);
const preview = page.frameLocator(`iframe[title=${JSON.stringify(t.cvEditorPreviewPage.replace('{page}', '1'))}]`).locator('body');
await expect(preview).toContainText(tailored);
await expect(preview).toContainText('+47 900 00 077');
await expect(preview).not.toContainText('Reviewed canonical summary, kept separate from CV-specific presentation.');
await info.attach('connected-selected-source-preview', { body: await page.screenshot({ fullPage: true, animations: 'disabled' }), contentType: 'image/png' });
expect(exports).toEqual([]);
const exported = page.waitForResponse(response => new URL(response.url()).pathname === `/api/cv/variants/${created.id}/export-pdf` && response.request().method() === 'POST');
const downloading = page.waitForEvent('download');
await page.getByRole('button', { name: t.cvEditorDownloadPdf, exact: true }).press('Enter');
const response = await exported;
expect(response.status()).toBe(200);
expect(new URL(response.url()).searchParams.get('expectedVersion')).toBe(String(edited.version));
expect(response.headers()['content-type']).toContain('application/pdf');
const download = await downloading;
expect(download.suggestedFilename()).toMatch(/\.pdf$/i);
const pdfPath = info.outputPath('selected-source-cv.pdf');
await download.saveAs(pdfPath); expect(await download.failure()).toBeNull();
const bytes = await readFile(pdfPath); expect(bytes.subarray(0, 5).toString()).toBe('%PDF-');
expect(exports).toEqual([`/api/cv/variants/${created.id}/export-pdf`]);
expect(canonicalWrites).toEqual([]);
expect(await readSource(page.request)).toEqual(source);
expect(await json<CvVariant>(await page.request.get(`${apiUrl}/cv/variants/${sibling.id}`))).toEqual(sibling);
expect(await json<CvVariant>(await page.request.get(url))).toEqual(edited);
await info.attach('connected-profile-to-cv-contract', { body: JSON.stringify({ created, edited, canonical: source,
pdfSha256: createHash('sha256').update(bytes).digest('hex'), canonicalWrites, exports,
qualification: 'Actual synthetic owner HTTP plus native source-selection/create/edit/preview/export. Manual source-note preservation only; no import-engine/provenance acceptance, PDF semantic/metric/fidelity or human/device qualification.' }), contentType: 'application/json' });
await info.attach('connected-selected-source-pdf', { path: pdfPath, contentType: 'application/pdf' });
});
test('[P7-04 PRES-C05 C07 C10 W07] keyboard rename duplicate and delete persist without changing source, settings or frozen packages', async ({ page, owner }, info) => {
test.setTimeout(90_000);
const sourceBefore = await seedSource(page, owner);
+17 -8
View File
@@ -105,20 +105,29 @@ test('[P7-07 Documents] stale CV opens the existing missing-source error and Bac
test('[P7-11 E08 C05] transient private CV entry recovers GET reads and keyboard focus without saving', async ({ page, session }, info) => {
const variant = await cv(page.request, session.owner, 'Read-only recovery CV');
await enter(page, session.owner);
for (const sample of [desktop, { language: 'nb', theme: 'dark', width: 390, height: 844 }] as Sample[]) {
const c = (key: string) => copy(key, {}, sample.language);
await enter(page, session.owner, sample);
let failed = true;
await page.route(`**/api/cv/variants/${variant.id}`, route => failed ? route.fulfill({ status: 503, json: { title: 'Controlled unavailable read' } }) : route.continue());
await keyboard(page, row(page, { name: variant.name, type: 'cv' }).getByRole('link', { name: copy('documentsOpenSource'), exact: true }));
const alert = page.getByRole('alert').filter({ hasText: copy('cvEditorOpenFailed') });
await keyboard(page, row(page, { name: variant.name, type: 'cv' }, sample.language).getByRole('link', { name: c('documentsOpenSource'), exact: true }));
const alert = page.getByRole('alert').filter({ hasText: c('cvEditorOpenFailed') });
await expect(alert).toBeVisible();
failed = false;
await keyboard(page, alert.getByRole('button', { name: copy('retry'), exact: true }));
const editor = page.getByRole('region', { name: copy('cvEditorEditingRegion'), exact: true });
await keyboard(page, alert.getByRole('button', { name: c('retry'), exact: true }));
const editor = page.getByRole('region', { name: c('cvEditorEditingRegion'), exact: true });
await expect(editor).toBeFocused();
await expect(page.getByLabel(copy('cvEditorName'), { exact: true })).toHaveValue(variant.name);
await expect(page.getByRole('heading', { name: c('cvEditorEditingRegion'), level: 2 })).toHaveCount(1);
await expect(page.getByLabel(c('cvEditorName'), { exact: true })).toHaveValue(variant.name);
expect((await json<CvVariant>(await page.request.get(`${apiUrl}/cv/variants/${variant.id}`))).version).toBe(variant.version);
expect(writes(session).every(value => value.method === 'POST' && value.path === `/api/cv/variants/${variant.id}/preview`)).toBe(true);
await capture(page, info, desktop, 'recovered-private-cv-entry');
for (const request of writes(session)) {
expect(request.method).toBe('POST');
expect(request.path).toBe('/api/cv/preview');
expect(request.body).toEqual({ settings: expect.any(Object) });
}
await capture(page, info, sample, 'recovered-private-cv-entry');
await info.attach(`recovered-cv-focus-viewport-${sample.language}-${sample.width}`, { body: await page.screenshot({ fullPage: false, animations: 'disabled' }), contentType: 'image/png' });
}
});
test('[P7-11 E08] unknown routes have bilingual contextual headings and preserve browser history', async ({ page, session }, info) => {