|
|
|
@@ -63,135 +63,6 @@ beforeEach(() => {
|
|
|
|
|
window.localStorage.setItem("uiLanguage", "en");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function deferredRead() {
|
|
|
|
|
let resolve!: (value: any) => void;
|
|
|
|
|
let reject!: (reason: unknown) => void;
|
|
|
|
|
const promise = new Promise<any>((yes, no) => { resolve = yes; reject = no; });
|
|
|
|
|
return { promise, resolve, reject };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test.each(['success', 'failure', 'pending-newer'] as const)('a newer preparation refresh wins against an older %s completion', async completion => {
|
|
|
|
|
mockedApi.get.mockReset(); routeGet();
|
|
|
|
|
const read = mockedApi.get.getMockImplementation()!;
|
|
|
|
|
const older = deferredRead(); const newer = deferredRead();
|
|
|
|
|
let reads = 0;
|
|
|
|
|
mockedApi.get.mockImplementation((url: string) => url.endsWith('/interview-prep') && ++reads > 1 ? (reads === 2 ? older.promise : newer.promise) : read(url));
|
|
|
|
|
const firstWrite = deferredRead(); const secondWrite = deferredRead();
|
|
|
|
|
mockedApi.patch.mockReset().mockReturnValueOnce(firstWrite.promise).mockReturnValueOnce(secondWrite.promise);
|
|
|
|
|
render(<ApplicationInterviewPrep jobId={7} />);
|
|
|
|
|
fireEvent.click(await screen.findByRole('checkbox', { name: 'Ready: Funding history' }));
|
|
|
|
|
fireEvent.click(screen.getByRole('checkbox', { name: 'Ready: Tell me about a conflict' }));
|
|
|
|
|
await act(async () => firstWrite.resolve({ data: {} }));
|
|
|
|
|
await act(async () => secondWrite.resolve({ data: {} }));
|
|
|
|
|
expect(reads).toBe(3);
|
|
|
|
|
if (completion === 'pending-newer') {
|
|
|
|
|
await act(async () => older.resolve({ data: board }));
|
|
|
|
|
const region = within(screen.getByRole('region', { name: translations.en.interviewPrepTitle }));
|
|
|
|
|
expect(region.getByRole('progressbar', { name: translations.en.loading })).toBeVisible();
|
|
|
|
|
expect(region.queryByLabelText(translations.en.interviewPrepAddLabel)).not.toBeInTheDocument();
|
|
|
|
|
}
|
|
|
|
|
const currentBoard = { ...board, groups: [{ ...board.groups[0], items: [{ ...board.groups[0].items[0], title: 'Newest board' }] }] };
|
|
|
|
|
await act(async () => newer.resolve({ data: currentBoard }));
|
|
|
|
|
expect(await screen.findByText('Newest board')).toBeVisible();
|
|
|
|
|
fireEvent.change(screen.getByLabelText(translations.en.interviewPrepAddLabel), { target: { value: 'Current draft' } });
|
|
|
|
|
if (completion === 'success') await act(async () => older.resolve({ data: board }));
|
|
|
|
|
if (completion === 'failure') await act(async () => older.reject(new Error('Older refresh failure')));
|
|
|
|
|
expect(screen.getByText('Newest board')).toBeVisible();
|
|
|
|
|
expect(screen.queryByText(translations.en.interviewPrepLoadFailed)).not.toBeInTheDocument();
|
|
|
|
|
expect(screen.getByLabelText(translations.en.interviewPrepAddLabel)).toHaveValue('Current draft');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.each(['prep', 'follow-up'] as const)('late %s write keeps its original target and cannot clear a new application draft', async surface => {
|
|
|
|
|
mockedApi.get.mockReset(); routeGet();
|
|
|
|
|
const write = deferredRead();
|
|
|
|
|
mockedApi.post.mockReset().mockReturnValueOnce(write.promise);
|
|
|
|
|
mockedApi.put.mockReset().mockReturnValueOnce(write.promise);
|
|
|
|
|
const component = (id: number) => surface === 'prep' ? <ApplicationInterviewPrep jobId={id} /> : <ApplicationFollowUp jobId={id} />;
|
|
|
|
|
const label = surface === 'prep' ? translations.en.interviewPrepAddLabel : translations.en.workspaceNextAction;
|
|
|
|
|
const view = render(component(7));
|
|
|
|
|
fireEvent.change(await screen.findByLabelText(label), { target: { value: 'Original application write' } });
|
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: translations.en[surface === 'prep' ? 'interviewPrepAdd' : 'save'] }));
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider>{component(8)}</ConfirmProvider></I18nProvider>));
|
|
|
|
|
fireEvent.change(await screen.findByLabelText(label), { target: { value: 'New application draft' } });
|
|
|
|
|
await act(async () => write.resolve({ data: surface === 'prep' ? board.groups[0].items[0] : followUp }));
|
|
|
|
|
expect(screen.getByLabelText(label)).toHaveValue('New application draft');
|
|
|
|
|
expect(surface === 'prep' ? mockedApi.post : mockedApi.put).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect((surface === 'prep' ? mockedApi.post : mockedApi.put).mock.calls[0][0]).toBe(`/jobapplications/7/${surface === 'prep' ? 'interview-prep' : 'follow-up'}`);
|
|
|
|
|
expect(mockedApi.get.mock.calls.filter(([url]) => url === '/jobapplications/7/interview-prep')).toHaveLength(surface === 'prep' ? 1 : 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.each(['prep', 'follow-up'] as const)('late %s read cannot replace the current application or its draft', async surface => {
|
|
|
|
|
mockedApi.get.mockReset(); routeGet();
|
|
|
|
|
const read = mockedApi.get.getMockImplementation()!;
|
|
|
|
|
const old = deferredRead();
|
|
|
|
|
const suffix = surface === 'prep' ? 'interview-prep' : 'follow-up';
|
|
|
|
|
mockedApi.get.mockImplementation((url: string) => url === `/jobapplications/7/${suffix}` ? old.promise : read(url));
|
|
|
|
|
const component = (id: number) => surface === 'prep' ? <ApplicationInterviewPrep jobId={id} /> : <ApplicationFollowUp jobId={id} />;
|
|
|
|
|
const view = render(component(7));
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider>{component(8)}</ConfirmProvider></I18nProvider>));
|
|
|
|
|
const label = surface === 'prep' ? translations.en.interviewPrepAddLabel : translations.en.workspaceNextAction;
|
|
|
|
|
fireEvent.change(await screen.findByLabelText(label), { target: { value: 'Current application draft' } });
|
|
|
|
|
const oldData = surface === 'prep'
|
|
|
|
|
? { ...board, groups: [{ ...board.groups[0], items: [{ ...board.groups[0].items[0], title: 'Previous application only' }] }] }
|
|
|
|
|
: { ...followUp, nextAction: 'Previous application only' };
|
|
|
|
|
await act(async () => old.resolve({ data: oldData }));
|
|
|
|
|
expect(screen.getByLabelText(label)).toHaveValue('Current application draft');
|
|
|
|
|
expect(screen.queryByText('Previous application only')).not.toBeInTheDocument();
|
|
|
|
|
expect(screen.queryByDisplayValue('Previous application only')).not.toBeInTheDocument();
|
|
|
|
|
expect(mockedApi.post).not.toHaveBeenCalled(); expect(mockedApi.put).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.each(['prep', 'follow-up'] as const)('late %s read failure cannot hide the current draft', async surface => {
|
|
|
|
|
mockedApi.get.mockReset(); routeGet();
|
|
|
|
|
const read = mockedApi.get.getMockImplementation()!;
|
|
|
|
|
const old = deferredRead();
|
|
|
|
|
const suffix = surface === 'prep' ? 'interview-prep' : 'follow-up';
|
|
|
|
|
mockedApi.get.mockImplementation((url: string) => url === `/jobapplications/7/${suffix}` ? old.promise : read(url));
|
|
|
|
|
const component = (id: number) => surface === 'prep' ? <ApplicationInterviewPrep jobId={id} /> : <ApplicationFollowUp jobId={id} />;
|
|
|
|
|
const view = render(component(7));
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider>{component(8)}</ConfirmProvider></I18nProvider>));
|
|
|
|
|
const label = surface === 'prep' ? translations.en.interviewPrepAddLabel : translations.en.workspaceNextAction;
|
|
|
|
|
fireEvent.change(await screen.findByLabelText(label), { target: { value: 'Current application draft' } });
|
|
|
|
|
await act(async () => old.reject(new Error('Previous application failure')));
|
|
|
|
|
expect(screen.queryByText(translations.en[surface === 'prep' ? 'interviewPrepLoadFailed' : 'interviewFollowUpLoadFailed'])).not.toBeInTheDocument();
|
|
|
|
|
expect(screen.getByLabelText(label)).toHaveValue('Current application draft');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.each(['prep', 'follow-up'] as const)('late %s finally cannot dismiss the current application loading state', async surface => {
|
|
|
|
|
mockedApi.get.mockReset(); routeGet();
|
|
|
|
|
const read = mockedApi.get.getMockImplementation()!;
|
|
|
|
|
const old = deferredRead(); const current = deferredRead();
|
|
|
|
|
const suffix = surface === 'prep' ? 'interview-prep' : 'follow-up';
|
|
|
|
|
mockedApi.get.mockImplementation((url: string) => url.endsWith(`/${suffix}`) ? (url.includes('/7/') ? old.promise : current.promise) : read(url));
|
|
|
|
|
const component = (id: number) => surface === 'prep' ? <ApplicationInterviewPrep jobId={id} /> : <ApplicationFollowUp jobId={id} />;
|
|
|
|
|
const view = render(component(7));
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider>{component(8)}</ConfirmProvider></I18nProvider>));
|
|
|
|
|
await act(async () => old.resolve({ data: surface === 'prep' ? board : followUp }));
|
|
|
|
|
const region = within(screen.getByRole('region', { name: translations.en[surface === 'prep' ? 'interviewPrepTitle' : 'interviewFollowUpTitle'] }));
|
|
|
|
|
expect(region.getByRole('progressbar', { name: translations.en.loading })).toBeVisible();
|
|
|
|
|
expect(region.queryByLabelText(translations.en[surface === 'prep' ? 'interviewPrepAddLabel' : 'workspaceNextAction'])).not.toBeInTheDocument();
|
|
|
|
|
await act(async () => current.resolve({ data: surface === 'prep' ? board : followUp }));
|
|
|
|
|
expect(await region.findByLabelText(translations.en[surface === 'prep' ? 'interviewPrepAddLabel' : 'workspaceNextAction'])).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('changing application resets parent drafts and a failed follow-up read retains a GET-only retry', async () => {
|
|
|
|
|
mockedApi.get.mockReset(); routeGet();
|
|
|
|
|
const read = mockedApi.get.getMockImplementation()!;
|
|
|
|
|
mockedApi.get.mockImplementation((url: string) => url === '/jobapplications/8/follow-up' ? Promise.reject(new Error('Current read failure')) : read(url));
|
|
|
|
|
const view = render(<ApplicationInterviewPrep jobId={7} />);
|
|
|
|
|
fireEvent.change(await screen.findByLabelText(translations.en.interviewPrepAddLabel), { target: { value: 'Application seven draft' } });
|
|
|
|
|
await screen.findByDisplayValue(followUp.nextAction);
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>));
|
|
|
|
|
expect(await screen.findByLabelText(translations.en.interviewPrepAddLabel)).toHaveValue('');
|
|
|
|
|
expect(await screen.findByText(translations.en.interviewFollowUpLoadFailed)).toBeVisible();
|
|
|
|
|
const region = within(screen.getByRole('region', { name: translations.en.interviewFollowUpTitle }));
|
|
|
|
|
expect(region.queryByLabelText(translations.en.workspaceNextAction)).not.toBeInTheDocument();
|
|
|
|
|
mockedApi.get.mockImplementation(read);
|
|
|
|
|
fireEvent.click(region.getByRole('button', { name: translations.en.retry }));
|
|
|
|
|
expect(await region.findByLabelText(translations.en.workspaceNextAction)).toHaveValue(followUp.nextAction);
|
|
|
|
|
expect(mockedApi.put).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.each(['en', 'nb'] as const)('pending preparation deletion follows %s without a preparation reload or answer loss', async from => {
|
|
|
|
|
localStorage.setItem('uiLanguage', from);
|
|
|
|
|
const to = from === 'en' ? 'nb' : 'en';
|
|
|
|
@@ -481,7 +352,7 @@ test('late generation cannot offer another application the previous application
|
|
|
|
|
fireEvent.change(screen.getByLabelText(translations.en.coverAiAdditionalInstructions), { target: { value: 'Private instructions for application seven' } });
|
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: translations.en.interviewAiGenerate }));
|
|
|
|
|
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledTimes(1));
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>));
|
|
|
|
|
view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>);
|
|
|
|
|
await act(async () => finish({ data: { result: { text: 'Only for application seven' } } }));
|
|
|
|
|
const assistant = within(screen.getByRole('region', { name: translations.en.interviewAiTitle }));
|
|
|
|
|
expect(assistant.queryByText('Only for application seven')).not.toBeInTheDocument();
|
|
|
|
@@ -497,7 +368,7 @@ test('completed AI suggestion is scoped to its application instead of becoming a
|
|
|
|
|
await screen.findByText('Backend CV');
|
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: translations.en.interviewAiGenerate }));
|
|
|
|
|
expect(await screen.findByText('Prepared for application seven only')).toBeVisible();
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>));
|
|
|
|
|
view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>);
|
|
|
|
|
const assistant = within(screen.getByRole('region', { name: translations.en.interviewAiTitle }));
|
|
|
|
|
expect(assistant.queryByText('Prepared for application seven only')).not.toBeInTheDocument();
|
|
|
|
|
expect(assistant.queryByRole('button', { name: translations.en.interviewAiAddToPrep })).not.toBeInTheDocument();
|
|
|
|
@@ -514,7 +385,7 @@ test('late accepted suggestion does not reload the previous application board in
|
|
|
|
|
await screen.findByText('Application seven suggestion');
|
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: translations.en.interviewAiAddToPrep }));
|
|
|
|
|
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledTimes(2));
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>));
|
|
|
|
|
view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>);
|
|
|
|
|
await waitFor(() => expect(mockedApi.get).toHaveBeenCalledWith('/jobapplications/8/interview-prep'));
|
|
|
|
|
await act(async () => finish({ data: board.groups[0].items[0] }));
|
|
|
|
|
expect(mockedApi.get.mock.calls.filter(([url]) => url === '/jobapplications/7/interview-prep')).toHaveLength(1);
|
|
|
|
@@ -573,7 +444,7 @@ test.each(['en', 'nb'] as const)('changing application hides the previous linked
|
|
|
|
|
mockedApi.get.mockImplementation((url: string) => url === '/jobapplications/8/cv' ? pending as any : read(url));
|
|
|
|
|
const view = render(<ApplicationInterviewPrep jobId={7} />);
|
|
|
|
|
await screen.findByText('Backend CV');
|
|
|
|
|
await act(async () => view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>));
|
|
|
|
|
view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>);
|
|
|
|
|
const assistant = within(screen.getByRole('region', { name: translations[language].interviewAiTitle }));
|
|
|
|
|
expect(assistant.queryByText('Backend CV')).not.toBeInTheDocument();
|
|
|
|
|
expect(assistant.getByRole('progressbar', { name: translations[language].loading })).toBeVisible();
|
|
|
|
|