fix(i18n): keep pending application trash confirmations current

This commit is contained in:
cesnimda
2026-11-17 08:06:16 +01:00
parent ae320088ff
commit 9d08f0340c
3 changed files with 27 additions and 3 deletions
@@ -7,6 +7,7 @@ import { api } from "./api";
import JobTable from "./components/JobTable";
import { ConfirmProvider } from "./confirm";
import { I18nProvider } from "./i18n/I18nProvider";
import { translations } from "./i18n/translations";
import { PromptProvider } from "./prompt";
import { ToastProvider } from "./toast";
import ApplicationWorkspacePage from "./views/ApplicationWorkspacePage";
@@ -235,6 +236,7 @@ test("row controls do not trigger navigation", async () => {
renderTable();
const row = await screen.findByRole("row", { name: /open backend developer/i });
fireEvent.click(screen.getByRole("button", { name: translations.en.jobTableSelectionMode }));
const checkbox = within(row).getByRole("checkbox");
fireEvent.click(checkbox);
+2 -2
View File
@@ -405,9 +405,9 @@ export default function JobTable({ refreshToken, pageSize, onPageSizeChange, col
if (jobsToDelete.length === 0) return false;
if (jobsToDelete.length === 1) {
const job = jobsToDelete[0];
return confirmAction(t("jobTableMoveOneConfirm", { title: job.jobTitle, company: job.company?.name ?? t("jobTableCompany") }), { title: t("jobTableMoveToTrashTitle"), confirmLabel: t("jobTableMove"), destructive: true });
return confirmAction({ key: "jobTableMoveOneConfirm", params: { title: job.jobTitle, company: job.company?.name ?? t("jobTableCompany") } }, { title: { key: "jobTableMoveToTrashTitle" }, confirmLabel: { key: "jobTableMove" }, destructive: true });
}
return confirmAction(t("jobTableMoveManyConfirm", { count: jobsToDelete.length }), { title: t("jobTableMoveJobsToTrashTitle"), confirmLabel: t("jobTableMove"), destructive: true });
return confirmAction({ key: "jobTableMoveManyConfirm", params: { count: jobsToDelete.length } }, { title: { key: "jobTableMoveJobsToTrashTitle" }, confirmLabel: { key: "jobTableMove" }, destructive: true });
};
const softDelete = async (job: JobApplication) => {
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import "@testing-library/jest-dom";
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { MemoryRouter, useLocation, useNavigate } from "react-router-dom";
import { api } from "./api";
import JobTable from "./components/JobTable";
@@ -42,6 +42,28 @@ beforeEach(() => {
});
});
test.each(([1, 2] as const).flatMap(count => (['en', 'nb'] as const).map(from => [count, from, from === 'en' ? 'nb' : 'en'] as const)))('pending trash confirmation for %s jobs follows %s to %s without changing selection', async (count, from, to) => {
localStorage.setItem('uiLanguage', from);
show();
await waitFor(() => expect(document.querySelector('[data-job-row-id="1"]')).not.toBeNull());
fireEvent.click(screen.getByRole('button', { name: translations[from].jobTableSelectionMode }));
for (const job of jobs.slice(0, count)) fireEvent.click(screen.getAllByRole('checkbox', { name: translations[from].jobTableSelectJob.replace('{title}', job.jobTitle) })[0]);
fireEvent.click(screen.getByRole('button', { name: translations[from].jobTableDeleteSelected }));
const titleKey = count === 1 ? 'jobTableMoveToTrashTitle' : 'jobTableMoveJobsToTrashTitle';
const opened = await screen.findByRole('dialog', { name: translations[from][titleKey] });
const readsBefore = reads('/jobapplications').length;
await act(async () => { window.dispatchEvent(new StorageEvent('storage', { key: 'uiLanguage', newValue: to })); });
expect(screen.getByRole('dialog', { name: translations[to][titleKey] })).toBe(opened);
expect(opened).toHaveAccessibleDescription(count === 1 ? translations[to].jobTableMoveOneConfirm.replace('{title}', jobs[0].jobTitle).replace('{company}', jobs[0].company.name) : translations[to].jobTableMoveManyConfirm.replace('{count}', String(count)));
expect(within(opened).getByRole('button', { name: translations[to].jobTableMove })).toBeVisible();
expect(mockedApi.delete).not.toHaveBeenCalled();
expect(reads('/jobapplications')).toHaveLength(readsBefore);
fireEvent.click(within(opened).getByRole('button', { name: translations[to].cancel }));
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
expect(mockedApi.delete).not.toHaveBeenCalled();
for (const job of jobs.slice(0, count)) expect(screen.getAllByRole('checkbox', { name: translations[to].jobTableSelectJob.replace('{title}', job.jobTitle) })[0]).toBeChecked();
});
test.each((['en', 'nb'] as const).flatMap(language => ['table', 'board'].flatMap(view => [0, 1, 2].map(count => [language, view, count] as const))))('localised matching count: %s %s %s retains membership when language changes', async (language, view, count) => {
localStorage.setItem('uiLanguage', language);
mockedApi.get.mockImplementation(url => Promise.resolve({ data: url === '/companies' ? [jobs[0].company] : url === '/jobapplications/board' ? jobs.slice(0, count) : { items: jobs.slice(0, count), total: count, page: 1, pageSize: 15 } } as any));