The 15 test files whose fake t returned the bare key (the 12 of the issue, plus the three category render tests added by #423) now mock react-i18next with i18nMock. Assertions naming a displayed text are rewritten in the marked form, t(key[options]), so a text that skipped t fails them. Components without such an assertion get one: PriceFetchControl, PriceFetchConsentToggle (rendered through the hook harness, its loading slot preset), CategoryDetailPanel, SourceList and SourceCard, and the region label of OnboardingChecklist. Each component was proved by a mutation removing one t call: every one turns at least one test red (exit 1). Refs #389 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
// Render tests for the key entry form of the License card (#347). No jsdom needed:
|
|
// react-dom/server renders in vitest's node environment, and `t` echoes its key.
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
|
|
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
|
|
vi.mock("react-i18next", async () => (await import("../../test/i18nMock")).i18nMock());
|
|
|
|
import LicenseKeyForm from "./LicenseKeyForm";
|
|
|
|
function render(validationError: string | null, busy = false): string {
|
|
return renderToStaticMarkup(
|
|
<LicenseKeyForm
|
|
value="SR-BASE-x"
|
|
onChange={() => {}}
|
|
onSubmit={() => {}}
|
|
onCancel={() => {}}
|
|
validating={false}
|
|
busy={busy}
|
|
validationError={validationError}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
describe("LicenseKeyForm", () => {
|
|
it("names a refused key in the app language", () => {
|
|
const html = render('{"code":"invalid_prefix"}');
|
|
expect(html).toContain("t(license.errors.invalidPrefix)");
|
|
expect(html).not.toContain("{"code"");
|
|
});
|
|
|
|
it("never prints a raw backend string", () => {
|
|
const html = render("License key must start with SR-BASE- or SR-PREMIUM-");
|
|
expect(html).toContain("t(license.errors.unknown)");
|
|
expect(html).not.toContain("License key must start");
|
|
});
|
|
|
|
it("shows no error line before a submission is refused", () => {
|
|
expect(render(null)).not.toContain("t(license.errors.");
|
|
});
|
|
|
|
it("blocks the submission while a machine activation runs", () => {
|
|
// The activation writes the token of the key it read (#364 review).
|
|
expect(render(null, true)).toMatch(/<button type="submit" disabled=""/);
|
|
expect(render(null, false)).not.toMatch(/<button type="submit" disabled=""/);
|
|
});
|
|
});
|