Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+84
@@ -0,0 +1,84 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
requireSession: vi.fn(),
|
||||
loadDataset: vi.fn(),
|
||||
loadInteractions: vi.fn(),
|
||||
portalPath: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/components/screens/customer-portal/CustomerPortalInterimPages", () => ({ CustomerPortalUploadPage: () => null }));
|
||||
vi.mock("~/services/customer-portal/portal-data.server", () => ({
|
||||
requirePortalSessionContext: mocks.requireSession,
|
||||
loadPortalProjectDataset: mocks.loadDataset,
|
||||
portalNotFound: () => new Response(null, { status: 404 }),
|
||||
}));
|
||||
vi.mock("~/services/customer-portal/portal-interactions-data.server", () => ({ loadPortalProjectInteractionsVM: mocks.loadInteractions }));
|
||||
vi.mock("~/services/customer-portal/portal-origin.server", () => ({ portalPublicPath: mocks.portalPath }));
|
||||
vi.mock("~/locale/i18next.server", () => ({ getTranslations: vi.fn(async () => ({ t: (key: string) => `translated:${key}` })) }));
|
||||
|
||||
import { loader } from "./upload";
|
||||
|
||||
const origin = { origin: "https://portal.example.test", tenantSlug: "acme", customHost: false };
|
||||
const session = {
|
||||
identity: {
|
||||
tenantId: "tenant-a",
|
||||
portalUserId: "portal-user-a",
|
||||
portalTitle: "Acme Kundenportal",
|
||||
viewerFirstName: "Karla",
|
||||
viewerLastName: "Kunde",
|
||||
},
|
||||
origin,
|
||||
responseHeaders: new Headers({ "Set-Cookie": "portal=renewed" }),
|
||||
};
|
||||
|
||||
describe("customer portal upload page loader", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.requireSession.mockResolvedValue(session);
|
||||
mocks.portalPath.mockImplementation((_origin: unknown, suffix?: string) => `/acme${suffix ? `/${suffix}` : ""}`);
|
||||
mocks.loadDataset.mockResolvedValue({
|
||||
projects: [
|
||||
{ id: "project-a", projectNumber: "P-1001", name: "Heizung" },
|
||||
{ id: "project-b", projectNumber: "P-1002", name: "Solar" },
|
||||
],
|
||||
});
|
||||
mocks.loadInteractions.mockResolvedValue({ status: "ready", data: { projectId: "project-b" } });
|
||||
});
|
||||
|
||||
it("selects only an accessible project and builds standard/custom-host-safe actions", async () => {
|
||||
const response = await loader({
|
||||
request: new Request("https://portal.example.test/acme/upload?projectId=project-b"),
|
||||
params: { tenant: "acme" },
|
||||
context: {},
|
||||
} as never);
|
||||
const data = (await response.json()) as {
|
||||
selectedProjectId: string;
|
||||
viewerLabel: string;
|
||||
projectOptions: Array<{ id: string; label: string }>;
|
||||
paths: Record<string, string>;
|
||||
};
|
||||
|
||||
expect(data.selectedProjectId).toBe("project-b");
|
||||
expect(data.viewerLabel).toBe("Karla Kunde");
|
||||
expect(data.projectOptions).toEqual([
|
||||
{ id: "project-a", label: "P-1001 · Heizung" },
|
||||
{ id: "project-b", label: "P-1002 · Solar" },
|
||||
]);
|
||||
expect(data.paths).toEqual({
|
||||
dashboard: "/acme",
|
||||
projects: "/acme/projects",
|
||||
upload: "/acme/upload",
|
||||
settings: "/acme/settings",
|
||||
logout: "/acme/logout",
|
||||
});
|
||||
expect(mocks.loadInteractions).toHaveBeenCalledWith({
|
||||
identity: session.identity,
|
||||
projectId: "project-b",
|
||||
projectLabel: "Solar",
|
||||
pendingFilename: "translated:customerPortal.upload.pendingFilename",
|
||||
uploadAction: "/acme/projects/project-b/upload",
|
||||
complaintAction: expect.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user