fix(ui): reconcile shared accessibility and read recovery
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
|
||||
import { api } from './api';
|
||||
import { AccountPlanProvider } from './accountPlan';
|
||||
@@ -15,7 +15,7 @@ jest.mock('./api', () => ({
|
||||
|
||||
const mockedApi = api as jest.Mocked<typeof api>;
|
||||
|
||||
beforeEach(() => jest.clearAllMocks());
|
||||
beforeEach(() => { jest.clearAllMocks(); localStorage.clear(); });
|
||||
|
||||
test('recruiter status suggestions require an explicit apply action', async () => {
|
||||
const applied = jest.fn();
|
||||
@@ -50,8 +50,56 @@ test('strategy snapshot shows saved output and queues regeneration only on reque
|
||||
|
||||
render(<I18nProvider><ToastProvider><AccountPlanProvider value={{ plan: 'pro', canUseAi: true, canUseProThemes: true }}><ApplicationStrategySnapshot jobId={42} /></AccountPlanProvider></ToastProvider></I18nProvider>);
|
||||
expect(await screen.findByText('Lead with delivery evidence.')).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Strategy snapshot', level: 2 })).toBeVisible();
|
||||
expect(mockedApi.post).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Regenerate' }));
|
||||
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledWith('/jobapplications/42/focus-plan/operations', { attachmentIds: null }));
|
||||
expect(await screen.findByText('queued')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
function strategy(jobId = 42) {
|
||||
return <I18nProvider><ToastProvider><AccountPlanProvider value={{ plan: 'free', canUseAi: false, canUseProThemes: false }}><ApplicationStrategySnapshot jobId={jobId} /></AccountPlanProvider></ToastProvider></I18nProvider>;
|
||||
}
|
||||
|
||||
test('failed strategy reads stay distinct from empty, localize without refetching and retry only the read', async () => {
|
||||
let finishOperation!: (result: any) => void;
|
||||
mockedApi.get.mockImplementation((url: string) => url.endsWith('/operation') ? new Promise(resolve => { finishOperation = resolve; }) : Promise.reject({ response: { status: 503 } }));
|
||||
render(strategy());
|
||||
expect(await screen.findByText('Strategy snapshot could not be loaded.')).toBeVisible();
|
||||
expect(screen.getByRole('button', { name: 'Retry' })).toBeDisabled();
|
||||
await act(async () => finishOperation({ data: null }));
|
||||
expect(screen.queryByText('No strategy snapshot yet. Generate one when you want AI-assisted planning.')).not.toBeInTheDocument();
|
||||
expect(mockedApi.post).not.toHaveBeenCalled();
|
||||
const calls = mockedApi.get.mock.calls.length;
|
||||
act(() => window.dispatchEvent(new StorageEvent('storage', { key: 'uiLanguage', newValue: 'nb' })));
|
||||
expect(await screen.findByText('Kunne ikke hente strategisammendraget.')).toBeVisible();
|
||||
expect(mockedApi.get).toHaveBeenCalledTimes(calls);
|
||||
mockedApi.get.mockResolvedValueOnce({ data: { strategicSummary: 'Saved plan', immediatePriorities: [], proofPointsToLeadWith: [], cvBulletIdeas: [], coverLetterAngles: [], followUpApproach: [] } } as any);
|
||||
const retry = screen.getByRole('button', { name: 'Prøv igjen' });
|
||||
act(() => retry.focus()); fireEvent.click(retry);
|
||||
expect(await screen.findByDisplayValue('Saved plan')).toBeVisible();
|
||||
expect(mockedApi.get.mock.calls.slice(calls).map(call => call[0])).toEqual(['/jobapplications/42/focus-plan']);
|
||||
expect(screen.getByRole('heading', { name: 'Strategioversikt', level: 2 })).toHaveFocus();
|
||||
expect(mockedApi.post).not.toHaveBeenCalled();
|
||||
expect(screen.getByRole('button', { name: 'Krever Pro' })).toBeDisabled();
|
||||
});
|
||||
|
||||
test('only the explicit not-generated response is an intentional empty strategy', async () => {
|
||||
mockedApi.get.mockRejectedValue({ response: { status: 404, data: { code: 'strategy_not_generated' } } });
|
||||
render(strategy());
|
||||
expect(await screen.findByText('No strategy snapshot yet. Generate one when you want AI-assisted planning.')).toBeVisible();
|
||||
expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();
|
||||
expect(mockedApi.post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('a late strategy response cannot replace another job and denial never offers read retry', async () => {
|
||||
let finish!: (result: any) => void;
|
||||
mockedApi.get.mockImplementation((url: string) => url === '/jobapplications/42/focus-plan' ? new Promise(resolve => { finish = resolve; }) : Promise.reject({ response: { status: 403 } }));
|
||||
const view = render(strategy());
|
||||
view.rerender(strategy(43));
|
||||
expect(await screen.findByText('Strategy snapshot could not be loaded.')).toBeVisible();
|
||||
await act(async () => finish({ data: { strategicSummary: 'Do not show old owner plan', immediatePriorities: [], proofPointsToLeadWith: [], cvBulletIdeas: [], coverLetterAngles: [], followUpApproach: [] } }));
|
||||
expect(screen.queryByDisplayValue('Do not show old owner plan')).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();
|
||||
expect(mockedApi.post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user