test: replace false-green checks with behavioral coverage (#6282)
* test: replace false-green checks with behavioral coverage * test: complete behavior-focused audit coverage
This commit is contained in:
1 parent
c7ab7aa6da
commit
74942bd190
91 files changed
+1891
-1391
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { runInNewContext } from "node:vm";
|
||||
import { Window } from "happy-dom";
|
||||
|
||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
@@ -339,43 +339,24 @@ const ACCIDENTALLY_SPANISH_SETTINGS_KEYS = [
|
||||
"settings.oauth.signInHelp",
|
||||
];
|
||||
const INDEX_HTML = readFileSync(resolve(process.cwd(), "index.html"), "utf8");
|
||||
const PREBOOT_SCRIPT = INDEX_HTML.match(
|
||||
/<script>\s*(\(function \(\) \{\s*var localeKey = "nanobot\.locale";[\s\S]*?\}\)\(\);)\s*<\/script>/,
|
||||
)?.[1];
|
||||
const BOOT_COPY_MARKUP = '<span data-boot-copy>Loading nanobot…</span>';
|
||||
|
||||
function runPrebootLocale(storedLocale: string) {
|
||||
if (!PREBOOT_SCRIPT) throw new Error("Could not find the preboot locale script in index.html");
|
||||
|
||||
const documentElement = { lang: "" };
|
||||
const meta = {
|
||||
content: "",
|
||||
setAttribute(name: string, value: string) {
|
||||
if (name === "content") this.content = value;
|
||||
},
|
||||
};
|
||||
const boot = { textContent: "" };
|
||||
|
||||
runInNewContext(PREBOOT_SCRIPT, {
|
||||
localStorage: {
|
||||
getItem: (key: string) => key === LOCALE_STORAGE_KEY ? storedLocale : null,
|
||||
},
|
||||
navigator: { languages: [], language: "en" },
|
||||
document: {
|
||||
documentElement,
|
||||
querySelector: (selector: string) => {
|
||||
if (selector === '[data-i18n-meta="description"]') return meta;
|
||||
if (selector === "[data-boot-copy]") return boot;
|
||||
return null;
|
||||
},
|
||||
},
|
||||
async function runPrebootLocale(storedLocale: string) {
|
||||
const preboot = new Window({
|
||||
url: "http://preboot.test",
|
||||
settings: { disableJavaScriptFileLoading: true, disableCSSFileLoading: true },
|
||||
});
|
||||
|
||||
return {
|
||||
lang: documentElement.lang,
|
||||
boot: boot.textContent,
|
||||
description: meta.content,
|
||||
};
|
||||
try {
|
||||
preboot.localStorage.setItem(LOCALE_STORAGE_KEY, storedLocale);
|
||||
// Parse the shipped document and execute inline scripts in parser order.
|
||||
// External/module loading stays disabled: React must not repair the splash.
|
||||
preboot.document.write(INDEX_HTML);
|
||||
return {
|
||||
lang: preboot.document.documentElement.lang,
|
||||
boot: preboot.document.querySelector('[role="status"]')?.textContent.trim(),
|
||||
description: preboot.document.querySelector('meta[name="description"]')?.getAttribute("content"),
|
||||
};
|
||||
} finally {
|
||||
await preboot.happyDOM.close();
|
||||
}
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
@@ -406,13 +387,6 @@ function interpolationKeys(value: unknown): string[] {
|
||||
}
|
||||
|
||||
describe("webui i18n", () => {
|
||||
it("runs preboot localization after the splash copy exists", () => {
|
||||
expect(INDEX_HTML.indexOf(BOOT_COPY_MARKUP)).toBeGreaterThan(-1);
|
||||
expect(INDEX_HTML.indexOf(PREBOOT_SCRIPT ?? "")).toBeGreaterThan(
|
||||
INDEX_HTML.indexOf(BOOT_COPY_MARKUP),
|
||||
);
|
||||
});
|
||||
|
||||
it.each(supportedLocales)("localizes compaction states in $code", async ({ code }) => {
|
||||
await setAppLanguage(code);
|
||||
const copy = resources[code].common.thread.compaction;
|
||||
@@ -437,9 +411,9 @@ describe("webui i18n", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps preboot copy aligned with every registered locale", () => {
|
||||
it("localizes the parsed splash in document order for every registered locale", async () => {
|
||||
for (const { code } of supportedLocales) {
|
||||
const result = runPrebootLocale(code);
|
||||
const result = await runPrebootLocale(code);
|
||||
const expected = resources[code].common.app;
|
||||
|
||||
expect({ code, ...result }).toEqual({
|
||||
@@ -451,11 +425,11 @@ describe("webui i18n", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("normalizes Portuguese locales before the app bundle loads", () => {
|
||||
it("normalizes Portuguese locales before the app bundle loads", async () => {
|
||||
const expected = resources["pt-BR"].common.app;
|
||||
|
||||
for (const locale of ["pt", "pt-PT"]) {
|
||||
expect(runPrebootLocale(locale)).toEqual({
|
||||
expect(await runPrebootLocale(locale)).toEqual({
|
||||
lang: "pt-BR",
|
||||
boot: expected.loading.boot,
|
||||
description: expected.meta.description,
|
||||
|
||||
Reference in new issue
Block a user