FactuGES_ERP/apps/web/src/routes/resolve-route-error-page-view-model.test.ts
david 26e2ee59bd feat: add error handling and feedback state management for customer and proforma updates
- Implemented feedback state resolution for proforma list and update pages.
- Created error view models for proforma and customer updates, including handling for various error types.
- Added tests for error handling in proforma and customer list updates.
- Introduced utility functions for building error view models and resolving feedback states.
- Ensured translation support for error messages in Spanish.
- Removed duplicate error alert components in customer module.
2026-08-06 13:03:48 +02:00

73 lines
2.4 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { resolveRouteErrorPageViewModel } from "./resolve-route-error-page-view-model";
const translate = (key: string) =>
({
"routeErrors.notFound.title": "Página no encontrada",
"routeErrors.notFound.description": "La dirección no existe o ha cambiado.",
"routeErrors.forbidden.title": "No tienes acceso a esta página",
"routeErrors.forbidden.description":
"No dispones de permisos para acceder a esta sección.",
"routeErrors.server.title": "No se pudo mostrar esta página",
"routeErrors.server.description":
"Se produjo un error interno mientras se cargaba la ruta.",
"routeErrors.unavailable.title": "El servicio no está disponible",
"routeErrors.unavailable.description":
"La sección que intentas abrir no está disponible en este momento.",
"routeErrors.unknown.title": "No se pudo mostrar esta página",
"routeErrors.unknown.description":
"Ha ocurrido un error inesperado mientras se cargaba la ruta.",
})[key] ?? key;
test("path desconocido usa notFound sin retry", () => {
const viewModel = resolveRouteErrorPageViewModel({
variant: "notFound",
translate,
});
assert.equal(viewModel.variant, "notFound");
assert.equal(viewModel.canRetry, false);
});
test("403 route error usa forbidden sin retry", () => {
const viewModel = resolveRouteErrorPageViewModel({
error: new Response(null, { status: 403 }),
translate,
});
assert.equal(viewModel.variant, "forbidden");
assert.equal(viewModel.canRetry, false);
});
test("500 route error usa server con retry", () => {
const viewModel = resolveRouteErrorPageViewModel({
error: new Response(null, { status: 500 }),
translate,
});
assert.equal(viewModel.variant, "server");
assert.equal(viewModel.canRetry, true);
});
test("503 route error usa unavailable con retry", () => {
const viewModel = resolveRouteErrorPageViewModel({
error: new Response(null, { status: 503 }),
translate,
});
assert.equal(viewModel.variant, "unavailable");
assert.equal(viewModel.canRetry, true);
});
test("errores desconocidos usan unknown con retry", () => {
const viewModel = resolveRouteErrorPageViewModel({
error: new Error("technical"),
translate,
});
assert.equal(viewModel.variant, "unknown");
assert.equal(viewModel.canRetry, true);
});