- Added pnpm-workspace.yaml to define package structure. - Created prepare-local-env.py script for local environment setup. - Introduced tsconfig.json for TypeScript configuration. - Added turbo.json for task management with Turbo.
83 lines
3.3 KiB
TypeScript
83 lines
3.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
|
|
import { identityKeys } from "@metis/identity/client";
|
|
import type { SessionResponseDTO, UserDTO } from "@metis/identity/common";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { I18nextProvider } from "react-i18next";
|
|
|
|
import { App } from "./app";
|
|
import { createAppI18n } from "./i18n";
|
|
|
|
const user: UserDTO = {
|
|
id: "c90b4d83-b06a-4d27-a402-e64899a2dfc2",
|
|
name: "Usuario de prueba",
|
|
email: "user@example.test",
|
|
active: true,
|
|
isInitialAdmin: false,
|
|
};
|
|
async function renderPage(language: string, session?: SessionResponseDTO) {
|
|
const { instance, initialization } = createAppI18n(language);
|
|
await initialization;
|
|
const client = new QueryClient({
|
|
defaultOptions: { queries: { retry: false, staleTime: Number.POSITIVE_INFINITY } },
|
|
});
|
|
if (session) {
|
|
client.setQueryData(identityKeys.session, session);
|
|
}
|
|
try {
|
|
return renderToStaticMarkup(
|
|
<I18nextProvider i18n={instance}>
|
|
<QueryClientProvider client={client}>
|
|
<App />
|
|
</QueryClientProvider>
|
|
</I18nextProvider>
|
|
);
|
|
} finally {
|
|
client.clear();
|
|
}
|
|
}
|
|
test("el acceso protege el contenido y traduce la carga de sesión", async () => {
|
|
for (const [language, pending] of [
|
|
["es", "Comprobando acceso"],
|
|
["en", "Checking access"],
|
|
] as const) {
|
|
const markup = await renderPage(language);
|
|
assert.equal(markup.includes("Tu espacio de soporte"), false);
|
|
assert.equal(markup.includes("Your support workspace"), false);
|
|
assert.match(markup, /role="combobox"/);
|
|
assert.ok(markup.includes(language === "es" ? "Español" : "English"));
|
|
assert.ok(markup.includes(pending));
|
|
assert.ok(markup.includes('role="status"'));
|
|
}
|
|
});
|
|
test("la configuración única y el login presentan sus formularios traducidos sin acceso al contenido", async () => {
|
|
for (const [language, setupTitle, loginTitle] of [
|
|
["es", "Configura Metis Desk", "Accede a Metis Desk"],
|
|
["en", "Set up Metis Desk", "Sign in to Metis Desk"],
|
|
] as const) {
|
|
const snapshot = { user: null, csrfToken: "a".repeat(64), setupRequired: true };
|
|
const setup = await renderPage(language, snapshot);
|
|
assert.ok(setup.includes(setupTitle));
|
|
assert.match(setup, /autoComplete="new-password"/);
|
|
assert.match(setup, /minLength="8"/);
|
|
assert.equal(setup.includes("Tu espacio de soporte"), false);
|
|
const login = await renderPage(language, { ...snapshot, setupRequired: false });
|
|
assert.ok(login.includes(loginTitle));
|
|
assert.match(login, /autoComplete="current-password"/);
|
|
assert.match(login, /minLength="1"/);
|
|
assert.equal(login.includes('autoComplete="name"'), false);
|
|
}
|
|
});
|
|
test("solo el administrador inicial ve la navegación de gestión de usuarios", async () => {
|
|
const snapshot = { user, csrfToken: "a".repeat(64), setupRequired: false };
|
|
const normal = await renderPage("es", snapshot);
|
|
assert.ok(normal.includes("Tu espacio de soporte"));
|
|
assert.ok(normal.includes("Mi contraseña"));
|
|
assert.ok(normal.includes("Salir"));
|
|
assert.equal(normal.includes(">Usuarios</button>"), false);
|
|
const admin = await renderPage("es", { ...snapshot, user: { ...user, isInitialAdmin: true } });
|
|
assert.ok(admin.includes(">Usuarios</button>"));
|
|
});
|