fix(interviews): recover follow-up reads and failed saves
This commit is contained in:
@@ -25,17 +25,19 @@ import ViewStateNotice from "./ViewStateNotice";
|
||||
// become prep items after an explicit accept action.
|
||||
// docs/architecture/overview.md.
|
||||
|
||||
function Shell({ title, subtitle, loading, error, children }: {
|
||||
function Shell({ title, subtitle, loading, error, children, onRetry, keepContentOnError = false }: {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
children: React.ReactNode;
|
||||
onRetry?: () => void | Promise<void>;
|
||||
keepContentOnError?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<PageSection surface title={title} description={subtitle} level="h3">
|
||||
<ViewStateNotice title={title} loading={loading} error={error ? { kind: "error", message: error, retryable: false } : null} compact />
|
||||
{!loading && !error && children}
|
||||
<ViewStateNotice title={title} loading={loading} error={error ? { kind: "error", message: error, retryable: Boolean(onRetry) } : null} onRetry={onRetry} compact />
|
||||
{!loading && (!error || keepContentOnError) && children}
|
||||
</PageSection>
|
||||
);
|
||||
}
|
||||
@@ -453,6 +455,8 @@ export function ApplicationFollowUp({ jobId }: { jobId: number }) {
|
||||
subtitle={t("interviewFollowUpSubtitle")}
|
||||
loading={loading}
|
||||
error={error ? getApiErrorMessage(error.cause, t(error.fallback)) : null}
|
||||
onRetry={data ? undefined : load}
|
||||
keepContentOnError={data !== null}
|
||||
>
|
||||
<Stack spacing={2}>
|
||||
{data && data.openFollowUpTasks > 0 && (
|
||||
|
||||
@@ -297,6 +297,44 @@ test("prep surfaces a load error", async () => {
|
||||
|
||||
// ---------- follow-up ----------
|
||||
|
||||
test.each(['en', 'nb'] as const)('failed follow-up save retains editable %s drafts and retries only the explicit write', async language => {
|
||||
localStorage.setItem('uiLanguage', language);
|
||||
const copy = translations[language];
|
||||
mockedApi.get.mockReset(); routeGet();
|
||||
mockedApi.put.mockReset().mockRejectedValueOnce(new Error('synthetic follow-up save failure')).mockResolvedValueOnce({ data: { ...followUp, followUpAt: '2026-12-01', nextAction: 'Discuss offer Øresund' } } as any);
|
||||
render(<ApplicationFollowUp jobId={7} />);
|
||||
fireEvent.change(await screen.findByLabelText(copy.interviewFollowUpDate), { target: { value: '2026-12-01' } });
|
||||
fireEvent.change(screen.getByLabelText(copy.workspaceNextAction), { target: { value: 'Discuss offer Øresund' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: copy.save }));
|
||||
expect(await screen.findByText(copy.interviewFollowUpSaveFailed)).toBeVisible();
|
||||
expect(screen.getByLabelText(copy.interviewFollowUpDate)).toHaveValue('2026-12-01');
|
||||
expect(screen.getByLabelText(copy.workspaceNextAction)).toHaveValue('Discuss offer Øresund');
|
||||
const save = screen.getByRole('button', { name: copy.save });
|
||||
expect(save).toBeEnabled(); expect(mockedApi.put).toHaveBeenCalledTimes(1); expect(mockedApi.get).toHaveBeenCalledTimes(1);
|
||||
fireEvent.click(save);
|
||||
await waitFor(() => expect(mockedApi.put).toHaveBeenCalledTimes(2));
|
||||
await waitFor(() => expect(screen.queryByText(copy.interviewFollowUpSaveFailed)).not.toBeInTheDocument());
|
||||
expect(mockedApi.put.mock.calls).toEqual(Array(2).fill(['/jobapplications/7/follow-up', { followUpAt: '2026-12-01', nextAction: 'Discuss offer Øresund' }]));
|
||||
expect(mockedApi.get).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByLabelText(copy.workspaceNextAction)).toHaveValue('Discuss offer Øresund');
|
||||
});
|
||||
|
||||
test.each(['en', 'nb'] as const)('failed initial follow-up read offers %s GET-only retry without editable defaults', async language => {
|
||||
localStorage.setItem('uiLanguage', language);
|
||||
const copy = translations[language];
|
||||
mockedApi.get.mockReset().mockRejectedValueOnce(new Error('synthetic follow-up read failure')).mockResolvedValueOnce({ data: followUp } as any);
|
||||
mockedApi.put.mockReset();
|
||||
render(<ApplicationFollowUp jobId={7} />);
|
||||
expect(await screen.findByText(copy.interviewFollowUpLoadFailed)).toBeVisible();
|
||||
expect(screen.queryByLabelText(copy.interviewFollowUpDate)).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: copy.save })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: copy.retry }));
|
||||
expect(await screen.findByLabelText(copy.interviewFollowUpDate)).toHaveValue('2026-07-26');
|
||||
expect(screen.getByLabelText(copy.workspaceNextAction)).toHaveValue(followUp.nextAction);
|
||||
expect(mockedApi.get.mock.calls).toEqual(Array(2).fill(['/jobapplications/7/follow-up']));
|
||||
expect(mockedApi.put).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test.each(['en', 'nb'] as const)('follow-up language switch from %s preserves the unsaved date and next action without a read', async from => {
|
||||
localStorage.setItem('uiLanguage', from);
|
||||
const to = from === 'en' ? 'nb' : 'en';
|
||||
|
||||
Reference in New Issue
Block a user