fix(ui): clarify document errors and retain readable actions

This commit is contained in:
cesnimda
2026-10-20 20:29:22 +02:00
parent ab89b6984c
commit 584530b694
16 changed files with 777 additions and 30 deletions
@@ -203,6 +203,43 @@ test("another user's variant is refused by the server and never rendered", async
renderAt(3);
expect(await screen.findByText(/Could not open this CV/i)).toBeInTheDocument();
expect(screen.getByText('This CV is unavailable or you no longer have access to it.')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();
});
test('a denied CV read has localized permission context without a write or retry', async () => {
routeGet(() => Promise.reject({ response: { status: 403 } }));
renderAt(3);
expect(await screen.findByText('You do not have permission to open this CV.')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'CV Builder', level: 2 })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();
expect(mockedApi.post).not.toHaveBeenCalled();
expect(mockedApi.put).not.toHaveBeenCalled();
});
test('a temporary CV opening failure retries reads and restores focus to the editor without saving', async () => {
let attempt = 0;
routeGet(() => ++attempt === 1 ? Promise.reject({ response: { status: 503 } }) : Promise.resolve({ data: variant }));
renderAt(3);
const retry = await screen.findByRole('button', { name: 'Retry' });
retry.focus(); fireEvent.click(retry);
await screen.findByDisplayValue('Backend CV');
await waitFor(() => expect(screen.getByRole('region', { name: 'CV editing controls' })).toHaveFocus());
expect(attempt).toBe(2);
expect(mockedApi.put).not.toHaveBeenCalled();
expect(mockedApi.post.mock.calls.every(call => String(call[0]).endsWith('/preview'))).toBe(true);
});
test('Bokmål history localizes known sources while preserving unknown metadata and versions', async () => {
localStorage.setItem('uiLanguage', 'nb');
const sources = ['autosave', 'manual', 'restore', 'create', 'custom-import', 'constructor'];
routeGet(() => Promise.resolve({ data: variant }), { sections: [] }, sources.map((source, index) => ({ version: index + 1, isCurrent: index === 3, source, createdAtUtc: variant.updatedAtUtc })));
renderAt(3);
await screen.findByDisplayValue('Backend CV');
fireEvent.click(screen.getByRole('tab', { name: 'Historikk' }));
for (const label of ['Automatisk lagring', 'Manuell', 'Gjenopprettet versjon', 'Opprettet', 'custom-import', 'constructor']) expect(await screen.findByText(new RegExp(` · ${label}$`))).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Gjenopprett versjon 5' })).toBeInTheDocument();
expect(mockedApi.put).not.toHaveBeenCalled();
});
test('invalid names are explained and are not silently autosaved', async () => {
@@ -241,6 +278,8 @@ test('session undo and redo restore content edits before autosave', async () =>
renderAt(3);
await openContentTab();
expect(screen.getByRole('button', { name: 'Undo' }).parentElement).not.toHaveAttribute('aria-label');
expect(screen.getByRole('button', { name: 'Redo' }).parentElement).not.toHaveAttribute('aria-label');
const headline = await screen.findByLabelText('Headline override');
fireEvent.change(headline, { target: { value: 'Platform Engineer' } });
expect(screen.getByRole('button', { name: 'Undo' })).toBeEnabled();