Files
pleno-vue/tests/unit/edge-gateway-workflow-helpers.spec.js
T

46 lines
2.0 KiB
JavaScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { inferEdgeGatewayErrorCode, normalizeEdgeGatewayError } from "@/features/edgeGateways/edgeGatewayErrors.js";
const managerSource = readFileSync(join(process.cwd(), "src/features/edgeGateways/EdgeGatewayManager.vue"), "utf8");
const operationsSource = readFileSync(join(process.cwd(), "src/features/edgeGateways/EdgeGatewayOperationsPage.vue"), "utf8");
const manageSource = readFileSync(join(process.cwd(), "src/features/edgeGateways/EdgeGatewayManagePage.vue"), "utf8");
describe("edge gateway workflow helpers", () => {
it("exposes v2 tabs and management actions without shell controls", () => {
expect(managerSource).toContain("id: \"overview\"");
expect(managerSource).toContain("id: \"inventory\"");
expect(managerSource).toContain("id: \"operations\"");
expect(managerSource).toContain("id: \"manage\"");
expect(managerSource).toContain("`gateway-tab-${tab.id}`");
expect(operationsSource).toContain('data-testid="gateway-operation-update"');
expect(operationsSource).toContain('data-testid="gateway-operation-uninstall"');
expect(manageSource).toContain('data-testid="gateway-rotate-credentials"');
expect(managerSource).not.toContain("gateway-shell");
expect(managerSource).not.toContain("EdgeGatewayTerminal");
});
it("maps structured edge gateway errors into UI copy", () => {
expect(inferEdgeGatewayErrorCode({ response: { data: { data: { error_code: "EDGE_GATEWAY_CONFLICT" } } } })).toBe(
"EDGE_GATEWAY_CONFLICT"
);
const normalized = normalizeEdgeGatewayError({
response: {
data: {
data: {
error_code: "EDGE_GATEWAY_INVALID_TOKEN",
message: "Invalid edge gateway token",
},
},
},
});
expect(normalized.code).toBe("EDGE_GATEWAY_INVALID_TOKEN");
expect(normalized.title).toMatch(/legitimationsoplysninger/i);
expect(normalized.message).toContain("Invalid edge gateway token");
});
});