fix(i18n): preserve current inbox confirmation and safety copy

This commit is contained in:
cesnimda
2026-11-17 18:36:02 +01:00
parent 7afbaf4713
commit 259bafdae4
3 changed files with 122 additions and 22 deletions
@@ -105,19 +105,117 @@ async function closeConfirmation(actionKey: string) {
function renderPage(initialPath = '/') {
return render(
<ToastProvider>
<ConfirmProvider>
<I18nProvider>
<I18nProvider>
<ConfirmProvider>
<MemoryRouter initialEntries={[initialPath]}>
<LocationProbe />
<CorrespondenceInboxPage />
</MemoryRouter>
</I18nProvider>
</ConfirmProvider>
</ConfirmProvider>
</I18nProvider>
</ToastProvider>,
);
}
describe('CorrespondenceInboxPage', () => {
test.each((['en', 'nb'] as const).flatMap(from => ['', 'recorded-thread'].map(threadId => [from, threadId] as const)))('pending send confirmation follows %s with literal fields and thread %s', async (from, threadId) => {
localStorage.setItem('uiLanguage', from);
const to = from === 'en' ? 'nb' : 'en';
const stored = savedComposeDraft({ threadId, subject: '<subject> Øresund & 東京', bodyText: 'Literal message body', to: 'literal@example.test' });
composeReads([stored]);
mockedApi.post.mockResolvedValue({ data: { attemptId: 'recorded-attempt', status: 'pending', duplicate: false } } as any);
renderPage();
fireEvent.click(await screen.findByRole('button', { name: copy('emailInboxResumeDraft', { name: stored.subject }) }));
const opener = screen.getByRole('button', { name: copy('emailInboxReviewSend') });
act(() => opener.focus()); fireEvent.click(opener);
const dialog = await screen.findByRole('dialog', { name: copy('emailInboxConfirmSendTitle') });
const reads = mockedApi.get.mock.calls.length;
await changeLanguage(to);
expect(screen.getByRole('dialog', { name: copy('emailInboxConfirmSendTitle') })).toBe(dialog);
expect(dialog).toHaveAccessibleDescription(copy('emailInboxConfirmSendMessage', { provider: 'Gmail', from: 'owner@gmail.test', to: stored.to, subject: stored.subject, thread: threadId || copy('emailInboxNewMessage') }).replace(/\s+/g, ' '));
expect(dialog.querySelector('subject')).toBeNull();
expect(mockedApi.get).toHaveBeenCalledTimes(reads);
expect(mockedApi.post).not.toHaveBeenCalled(); expect(mockedApi.delete).not.toHaveBeenCalled();
await closeConfirmation('cancel');
await waitFor(() => expect(opener).toHaveFocus());
expect(composeField('emailInboxSubject')).toHaveValue(stored.subject);
expect(composeField('emailInboxMessage')).toHaveValue(stored.bodyText);
fireEvent.click(opener); await closeConfirmation('emailInboxSendEmail');
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledTimes(1));
expect(mockedApi.post).toHaveBeenCalledWith('/email/send', { jobApplicationId: 42, provider: 'gmail', clientRequestId: stored.clientRequestId, to: stored.to, subject: stored.subject, bodyText: stored.bodyText, threadId: threadId || null, confirmed: true });
expect(mockedApi.delete).not.toHaveBeenCalled(); expect(mockedApi.put).not.toHaveBeenCalled();
});
test.each((['en', 'nb'] as const).flatMap(from => ['', '<company> Øresund'].map(companyName => [from, companyName] as const)))('pending unlink follows %s with literal/fallback company %s', async (from, companyName) => {
localStorage.setItem('uiLanguage', from);
const to = from === 'en' ? 'nb' : 'en';
const read = mockedApi.get.getMockImplementation()!;
mockedApi.get.mockImplementation((url: string, config?: any) => url === '/correspondence/page' ? Promise.resolve({ data: pageData([messageItem({ companyName })]) } as any) : read(url, config));
mockedApi.post.mockResolvedValue({ data: {} } as any);
renderPage();
const opener = await screen.findByRole('button', { name: copy('emailInboxUnlinkThread') });
act(() => opener.focus()); fireEvent.click(opener);
const dialog = await screen.findByRole('dialog', { name: copy('emailInboxUnlinkTitle') });
const reads = mockedApi.get.mock.calls.length;
await changeLanguage(to);
expect(screen.getByRole('dialog', { name: copy('emailInboxUnlinkTitle') })).toBe(dialog);
expect(dialog).toHaveAccessibleDescription(copy('emailInboxUnlinkMessage', { job: companyName || copy('emailInboxThisJob') }));
expect(dialog.querySelector('company')).toBeNull();
expect(mockedApi.get).toHaveBeenCalledTimes(reads); expect(mockedApi.post).not.toHaveBeenCalled();
await closeConfirmation('cancel');
await waitFor(() => expect(opener).toHaveFocus());
fireEvent.click(opener); await closeConfirmation('emailInboxUnlinkThread');
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledTimes(1));
expect(mockedApi.post).toHaveBeenCalledWith('/gmail/unlink-thread', { jobApplicationId: 42, threadId: 'thread-1', note: 'Unlinked from Job email hub', nextDecision: 'review' });
expect(mockedApi.delete).not.toHaveBeenCalled(); expect(mockedApi.put).not.toHaveBeenCalled();
});
test.each((['en', 'nb'] as const).flatMap(from => (['replace', 'discard'] as const).flatMap(action => (['saved', 'unsaved', 'uncertain'] as const).map(state => [from, action, state] as const))))('pending draft %s / %s / %s keeps current copy and decision', async (from, action, state) => {
localStorage.setItem('uiLanguage', from);
const to = from === 'en' ? 'nb' : 'en';
const original = savedComposeDraft();
const replacement = savedComposeDraft({ id: 'other-owned', subject: 'Replacement draft', bodyText: 'Replacement body', clientRequestId: 'replacement-owned-attempt' });
composeReads([original, replacement]);
mockedApi.post.mockResolvedValue({ data: { attemptId: 'original-owned-attempt', status: 'pending', duplicate: false } } as any);
mockedApi.delete.mockResolvedValue({ data: null } as any);
renderPage();
fireEvent.click(await screen.findByRole('button', { name: copy('emailInboxResumeDraft', { name: original.subject }) }));
if (state === 'unsaved') fireEvent.change(composeField('emailInboxMessage'), { target: { value: 'Unsaved body Øresund' } });
if (state === 'uncertain') {
fireEvent.click(screen.getByRole('button', { name: copy('emailInboxReviewSend') }));
await closeConfirmation('emailInboxSendEmail');
await screen.findByText(copy('emailInboxDeliveryUncertain'));
}
const body = state === 'unsaved' ? 'Unsaved body Øresund' : original.bodyText;
const titleKey = action === 'replace' ? 'emailInboxReplaceDraftTitle' : 'emailInboxDiscardDraftTitle';
const actionKey = action === 'replace' ? 'emailInboxReplaceDraft' : 'emailInboxDiscardDraft';
const messageKey = action === 'discard' ? 'emailInboxDiscardDraftMessage' : state === 'unsaved' ? 'emailInboxUnsavedDraftLost' : 'emailInboxCurrentDraftSaved';
const opener = screen.getByRole('button', { name: action === 'replace' ? copy('emailInboxResumeDraft', { name: replacement.subject }) : copy('emailInboxDiscardDraft') });
act(() => opener.focus()); fireEvent.click(opener);
const dialog = await screen.findByRole('dialog', { name: copy(titleKey) });
const reads = mockedApi.get.mock.calls.length;
const writes = state === 'uncertain' ? 1 : 0;
await changeLanguage(to);
expect(screen.getByRole('dialog', { name: copy(titleKey) })).toBe(dialog);
expect(dialog).toHaveAccessibleDescription(((state === 'uncertain' ? copy('emailInboxDeliveryUncertain') + '\n\n' : '') + copy(messageKey)).replace(/\s+/g, ' '));
expect(within(dialog).getByRole('button', { name: copy(actionKey) })).toBeEnabled();
expect(mockedApi.get).toHaveBeenCalledTimes(reads);
expect(mockedApi.post).toHaveBeenCalledTimes(writes); expect(mockedApi.delete).not.toHaveBeenCalled();
await closeConfirmation('cancel');
await waitFor(() => expect(opener).toHaveFocus());
expect(composeField('emailInboxMessage')).toHaveValue(body);
expect(composeField('emailInboxSubject')).toHaveValue(original.subject);
fireEvent.click(opener); await closeConfirmation(actionKey);
if (action === 'replace') {
expect(composeField('emailInboxMessage')).toHaveValue(replacement.bodyText);
expect(mockedApi.delete).not.toHaveBeenCalled();
} else {
await waitFor(() => expect(mockedApi.delete).toHaveBeenCalledTimes(1));
expect(mockedApi.delete).toHaveBeenCalledWith('/email/drafts/compose-owned', { params: { revision: 4 } });
}
expect(mockedApi.post).toHaveBeenCalledTimes(writes); expect(mockedApi.put).not.toHaveBeenCalled();
});
test.each(['en', 'nb'] as const)('%s label counts keep singular/plural grammar through a live locale change', async language => {
const original = mockedApi.get.getMockImplementation();
mockedApi.get.mockImplementation((url: string, config?: any) => url === '/correspondence/page'
@@ -643,16 +741,16 @@ describe('CorrespondenceInboxPage', () => {
test('legacy Gmail review route redirects into the consolidated hub filter', async () => {
render(
<ToastProvider>
<ConfirmProvider>
<I18nProvider>
<I18nProvider>
<ConfirmProvider>
<MemoryRouter initialEntries={['/correspondence/review']}>
<Routes>
<Route path="/correspondence/review" element={<Navigate to="/correspondence?view=review" replace />} />
<Route path="/correspondence" element={<CorrespondenceInboxPage />} />
</Routes>
</MemoryRouter>
</I18nProvider>
</ConfirmProvider>
</ConfirmProvider>
</I18nProvider>
</ToastProvider>,
);
@@ -904,7 +1002,7 @@ describe('CorrespondenceInboxPage', () => {
test('typing an inbox search keeps one natural Back step to the prior screen and preserves filter context', async () => {
render(
<ToastProvider><ConfirmProvider><I18nProvider>
<ToastProvider><I18nProvider><ConfirmProvider>
<MemoryRouter initialEntries={['/previous-screen', '/correspondence?source=workflow&direction=inbound&linkState=linked#inbox']} initialIndex={1}>
<LocationProbe />
<HistoryBackControl />
@@ -913,7 +1011,7 @@ describe('CorrespondenceInboxPage', () => {
<Route path="/correspondence" element={<CorrespondenceInboxPage />} />
</Routes>
</MemoryRouter>
</I18nProvider></ConfirmProvider></ToastProvider>,
</ConfirmProvider></I18nProvider></ToastProvider>,
);
const search = await screen.findByRole('textbox', { name: copy('correspondenceSearch') });
await screen.findByText('Interview invite');
+2
View File
@@ -474,6 +474,7 @@ export const translations = {
emailInboxProviderCopyUnavailable: "The provider copy is unavailable. Showing the saved JobTracker copy.",
emailInboxMessageLoadFailed: "Failed to load this message.",
emailInboxReplaceDraftTitle: "Replace email draft?",
emailInboxUncertainDraftDecision: "{warning}\n\n{decision}",
emailInboxReplaceReplyMessage: "Starting this reply will discard the draft you are currently editing.",
emailInboxReplaceDraft: "Replace draft",
emailInboxYourMessage: "Your message",
@@ -3719,6 +3720,7 @@ export const translations = {
emailInboxProviderCopyUnavailable: "Kopien hos leverandøren er utilgjengelig. Viser den lagrede JobTracker-kopien.",
emailInboxMessageLoadFailed: "Kunne ikke laste denne meldingen.",
emailInboxReplaceDraftTitle: "Erstatt e-postutkast?",
emailInboxUncertainDraftDecision: "{warning}\n\n{decision}",
emailInboxReplaceReplyMessage: "Når du starter dette svaret, forkastes utkastet du redigerer nå.",
emailInboxReplaceDraft: "Erstatt utkast",
emailInboxYourMessage: "Meldingen din",
@@ -422,9 +422,9 @@ export default function CorrespondenceInboxPage() {
const saved = !!current?.id && !draftDirty;
const unresolved = sendResult && ["uncertain", "pending", "sending"].includes(sendResult.status);
return confirm({
title: t("emailInboxReplaceDraftTitle"),
message: (unresolved ? t("emailInboxDeliveryUncertain") + "\n\n" : "") + t(saved ? "emailInboxCurrentDraftSaved" : "emailInboxUnsavedDraftLost"),
confirmLabel: t("emailInboxReplaceDraft"),
title: { key: "emailInboxReplaceDraftTitle" },
message: unresolved ? { key: "emailInboxUncertainDraftDecision", params: { warning: { key: "emailInboxDeliveryUncertain" }, decision: { key: saved ? "emailInboxCurrentDraftSaved" : "emailInboxUnsavedDraftLost" } } } : { key: saved ? "emailInboxCurrentDraftSaved" : "emailInboxUnsavedDraftLost" },
confirmLabel: { key: "emailInboxReplaceDraft" },
destructive: !saved,
});
};
@@ -519,9 +519,9 @@ export default function CorrespondenceInboxPage() {
composeOperation.current = true;
try {
if ((captured.id || hasDraftContent(captured) || sendResult) && !(await confirm({
title: t("emailInboxDiscardDraftTitle"),
message: (sendResult && ["uncertain", "pending", "sending"].includes(sendResult.status) ? t("emailInboxDeliveryUncertain") + "\n\n" : "") + t("emailInboxDiscardDraftMessage"),
confirmLabel: t("emailInboxDiscardDraft"), destructive: true,
title: { key: "emailInboxDiscardDraftTitle" },
message: sendResult && ["uncertain", "pending", "sending"].includes(sendResult.status) ? { key: "emailInboxUncertainDraftDecision", params: { warning: { key: "emailInboxDeliveryUncertain" }, decision: { key: "emailInboxDiscardDraftMessage" } } } : { key: "emailInboxDiscardDraftMessage" },
confirmLabel: { key: "emailInboxDiscardDraft" }, destructive: true,
}))) return;
if (!isCurrentDraft(captured)) return;
setComposeBusy(true);
@@ -567,9 +567,9 @@ export default function CorrespondenceInboxPage() {
composeOperation.current = true;
try {
if (!(await confirm({
title: t("emailInboxConfirmSendTitle"),
message: t("emailInboxConfirmSendMessage", { provider: captured.providerName, from: captured.fromAddress, to: captured.to.trim(), subject: captured.subject.trim(), thread: captured.threadId || t("emailInboxNewMessage") }),
confirmLabel: t("emailInboxSendEmail"),
title: { key: "emailInboxConfirmSendTitle" },
message: { key: "emailInboxConfirmSendMessage", params: { provider: captured.providerName, from: captured.fromAddress, to: captured.to.trim(), subject: captured.subject.trim(), thread: captured.threadId || { key: "emailInboxNewMessage" } } },
confirmLabel: { key: "emailInboxSendEmail" },
})) || !isCurrentDraft(captured)) return;
setComposeBusy(true); setSending(true); setSendError(null);
draftPanel.current?.focus({ preventScroll: true });
@@ -637,9 +637,9 @@ export default function CorrespondenceInboxPage() {
unlinkPending.current = true;
try {
if (!(await confirm({
title: t("emailInboxUnlinkTitle"),
message: t("emailInboxUnlinkMessage", { job: item.companyName || t("emailInboxThisJob") }),
confirmLabel: t("emailInboxUnlinkThread"),
title: { key: "emailInboxUnlinkTitle" },
message: { key: "emailInboxUnlinkMessage", params: { job: item.companyName || { key: "emailInboxThisJob" } } },
confirmLabel: { key: "emailInboxUnlinkThread" },
destructive: true,
})) || !mounted.current) return;
setUnlinkingThreadId(item.externalThreadId);