perf(jobs): avoid locale-only application refetch
This commit is contained in:
@@ -316,8 +316,8 @@ export default function JobTable({ refreshToken, pageSize, onPageSizeChange, col
|
||||
{
|
||||
initialData: { items: [], total: 0, page: 1, pageSize },
|
||||
enabled: !boardView,
|
||||
errorMessage: t("jobTableJobsLoadFailed"),
|
||||
deps: [params, refreshToken, reloadToken, pageSize, t],
|
||||
errorMessage: "", // ViewStateNotice renders the fallback in the current language.
|
||||
deps: [params, refreshToken, reloadToken, pageSize],
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -170,11 +170,13 @@ test("mobile salary follows UI language and preserves imported periods and free
|
||||
const card = (title: string) => screen.getByRole("link", { name: new RegExp(title, "i") });
|
||||
expect(normalize(card(job.jobTitle).textContent)).toContain(salary("en", translations.en.salaryPeriodYear));
|
||||
const params = lastParams();
|
||||
const readCount = calls().length;
|
||||
await act(async () => { window.dispatchEvent(new StorageEvent("storage", { key: "uiLanguage", newValue: "nb" })); });
|
||||
expect(normalize(card(job.jobTitle).textContent)).toContain(salary("nb-NO", translations.nb.salaryPeriodYear));
|
||||
expect(within(card("Second role")).getByText("0/constructor")).toBeVisible();
|
||||
expect(within(card("Third role")).getByText("Lønn etter avtale")).toBeVisible();
|
||||
expect(lastParams()).toEqual(params);
|
||||
expect(calls()).toHaveLength(readCount);
|
||||
expect(mockedApi.put).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
if (previous) Object.defineProperty(window, "matchMedia", previous);
|
||||
@@ -182,6 +184,28 @@ test("mobile salary follows UI language and preserves imported periods and free
|
||||
}
|
||||
});
|
||||
|
||||
test.each(["jobs", "trash"] as const)("language changes localize the current %s read error without a new request", async (mode) => {
|
||||
const title = mode === "jobs" ? "jobTableJobsLoadFailed" : "jobTableTrashLoadFailed";
|
||||
mockedApi.get.mockImplementation((url: string) => url === "/jobapplications"
|
||||
? Promise.reject({ response: { status: 503 } })
|
||||
: Promise.resolve({ data: [job.company] } as any));
|
||||
show(mode, "?q=platform");
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent(translations.en[title]);
|
||||
const readCount = calls().length;
|
||||
const params = lastParams();
|
||||
await act(async () => { window.dispatchEvent(new StorageEvent("storage", { key: "uiLanguage", newValue: "nb" })); });
|
||||
expect(screen.getByRole("alert")).toHaveTextContent(translations.nb[title]);
|
||||
expect(screen.queryByText(translations.en[title])).not.toBeInTheDocument();
|
||||
expect(calls()).toHaveLength(readCount);
|
||||
expect(mockedApi.put).not.toHaveBeenCalled();
|
||||
|
||||
mockedApi.get.mockResolvedValue({ data: { items: [], total: 0, page: 1, pageSize: 15 } } as any);
|
||||
fireEvent.click(screen.getByRole("button", { name: translations.nb.retry }));
|
||||
await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument());
|
||||
expect(calls()).toHaveLength(readCount + 1);
|
||||
expect(lastParams()).toEqual(params);
|
||||
});
|
||||
|
||||
test("partial bulk failure refreshes successful rows and retains only failed visible IDs", async () => {
|
||||
const other = { ...job, id: 43, jobTitle: "Second role" };
|
||||
mockedApi.get.mockImplementation((url: string) => Promise.resolve({ data: url === "/companies" ? [job.company] : url === "/jobapplications" ? { items: [job, other], total: 2, page: 1, pageSize: 15 } : [] } as any));
|
||||
|
||||
Reference in New Issue
Block a user