fix(i18n): refresh pending CV rename and delete copy
This commit is contained in:
@@ -102,6 +102,44 @@ async function selectAction(name: string) {
|
||||
fireEvent.click(item);
|
||||
}
|
||||
|
||||
test.each([
|
||||
['rename', 'en', 'nb'], ['rename', 'nb', 'en'],
|
||||
['delete', 'en', 'nb'], ['delete', 'nb', 'en'],
|
||||
] as const)('pending CV %s follows %s to %s while preserving its decision and draft', async (action, from, to) => {
|
||||
localStorage.setItem('uiLanguage', from);
|
||||
mockedApi.get.mockImplementation(async url => ({ data: url === '/cv/themes' ? themes : url === '/cv/variants' ? [existingCv] : [] }) as any);
|
||||
renderPage();
|
||||
await screen.findByText(existingCv.name);
|
||||
fireEvent.click(screen.getByRole('button', { name: translations[from].cvDashboardActionsFor.replace('{name}', existingCv.name) }));
|
||||
fireEvent.click(await screen.findByRole('menuitem', { name: translations[from][action === 'rename' ? 'cvDashboardRename' : 'cvDashboardDelete'] }));
|
||||
const titleKey = action === 'rename' ? 'cvDashboardRenameCv' : 'cvDashboardDeleteCv';
|
||||
const labelKey = action === 'rename' ? 'cvDashboardRename' : 'cvDashboardDeleteCv';
|
||||
const opened = await screen.findByRole('dialog', { name: translations[from][titleKey] });
|
||||
const input = action === 'rename' ? within(opened).getByRole('textbox') as HTMLInputElement : null;
|
||||
if (input) {
|
||||
await waitFor(() => expect(input).toHaveFocus());
|
||||
expect(input).toHaveValue(existingCv.name);
|
||||
fireEvent.change(input, { target: { value: 'Søknad 東京 <draft>' } });
|
||||
input.setSelectionRange(1, 5);
|
||||
}
|
||||
const reads = mockedApi.get.mock.calls.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(action === 'rename' ? translations[to].cvDashboardRenameMessage : translations[to].cvDashboardDeleteMessage.replace('{name}', existingCv.name));
|
||||
expect(within(opened).getByRole('button', { name: translations[to][labelKey] })).toBeVisible();
|
||||
if (input) {
|
||||
expect(input).toHaveValue('Søknad 東京 <draft>');
|
||||
expect(input).toHaveFocus();
|
||||
expect([input.selectionStart, input.selectionEnd]).toEqual([1, 5]);
|
||||
}
|
||||
expect(mockedApi.get).toHaveBeenCalledTimes(reads);
|
||||
fireEvent.click(within(opened).getByRole('button', { name: translations[to].cancel }));
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
expect(mockedApi.put).not.toHaveBeenCalled();
|
||||
expect(mockedApi.delete).not.toHaveBeenCalled();
|
||||
expect(mockNavigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test.each(['unmount', 'session'] as const)('late CV creation cannot navigate after %s', async boundary => {
|
||||
const write = deferred<any>();
|
||||
mockedApi.post.mockImplementationOnce(() => write.promise);
|
||||
|
||||
@@ -151,9 +151,9 @@ export default function CvBuilderPage() {
|
||||
if (!active) return;
|
||||
const variant = variants.find((item) => item.id === id);
|
||||
try {
|
||||
if (!(await confirmAction(t("cvDashboardDeleteMessage", { name: variant?.name ?? t("cvDashboardThisCv") }), {
|
||||
title: t("cvDashboardDeleteCv"),
|
||||
confirmLabel: t("cvDashboardDeleteCv"),
|
||||
if (!(await confirmAction({ key: "cvDashboardDeleteMessage", params: { name: variant?.name ?? t("cvDashboardThisCv") } }, {
|
||||
title: { key: "cvDashboardDeleteCv" },
|
||||
confirmLabel: { key: "cvDashboardDeleteCv" },
|
||||
destructive: true,
|
||||
})) || !active()) return;
|
||||
setPending(true);
|
||||
@@ -173,7 +173,7 @@ export default function CvBuilderPage() {
|
||||
if (!active) return;
|
||||
const current = variants.find((item) => item.id === id);
|
||||
try {
|
||||
const nextName = await promptForValue(t("cvDashboardRenameMessage"), current?.name ?? "", { title: t("cvDashboardRenameCv"), confirmLabel: t("cvDashboardRename") });
|
||||
const nextName = await promptForValue({ key: "cvDashboardRenameMessage" }, current?.name ?? "", { title: { key: "cvDashboardRenameCv" }, confirmLabel: { key: "cvDashboardRename" } });
|
||||
if (!active() || !nextName?.trim() || nextName.trim() === current?.name) return;
|
||||
setPending(true);
|
||||
const variant = await cvBuilderApi.get(id);
|
||||
|
||||
Reference in New Issue
Block a user