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
+139
@@ -0,0 +1,139 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
requireProjectView: vi.fn(),
|
||||
loadProjectContext: vi.fn(),
|
||||
requireProjectPermission: vi.fn(),
|
||||
projectActionErrorResponse: vi.fn(),
|
||||
loadKanbanData: vi.fn(),
|
||||
handleKanbanIntent: vi.fn(),
|
||||
kanbanIntentPermission: vi.fn(),
|
||||
getTranslations: vi.fn(),
|
||||
ProjectServiceError: class ProjectServiceError extends Error {
|
||||
readonly messageKey: string;
|
||||
|
||||
constructor(messageKey: string) {
|
||||
super(messageKey);
|
||||
this.messageKey = messageKey;
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: mocks.getTranslations,
|
||||
}));
|
||||
vi.mock("~/utils/integrations/projects/projectAccess.server", () => ({
|
||||
PROJECT_READ_PERMISSIONS: ["projects.read_all", "projects.read_own"],
|
||||
loadProjectContext: mocks.loadProjectContext,
|
||||
projectActionErrorResponse: mocks.projectActionErrorResponse,
|
||||
requireProjectPermission: mocks.requireProjectPermission,
|
||||
requireProjectView: mocks.requireProjectView,
|
||||
}));
|
||||
vi.mock("~/utils/integrations/projects/projectBoardRoute.server", () => ({
|
||||
handleKanbanIntent: mocks.handleKanbanIntent,
|
||||
kanbanIntentPermission: mocks.kanbanIntentPermission,
|
||||
loadKanbanData: mocks.loadKanbanData,
|
||||
// The loader forwards the S01 facet selection; the parser itself is covered by
|
||||
// projectFilterFacets.test.ts, so an empty selection is enough here.
|
||||
parseBoardFacetParams: () => ({ owners: [], customerTypes: [], tagIds: [], periods: [], periodFrom: null, periodTo: null, valueBands: [] }),
|
||||
}));
|
||||
vi.mock("~/utils/integrations/projects/projectService.server", () => ({
|
||||
ProjectServiceError: mocks.ProjectServiceError,
|
||||
}));
|
||||
|
||||
import { action, loader } from "./projects._index";
|
||||
|
||||
describe("projects board loader", () => {
|
||||
const ctx = {
|
||||
tenantId: "tenant-1",
|
||||
tenantSlug: "acme",
|
||||
userId: "user-1",
|
||||
permissions: ["projects.read_all"],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.requireProjectView.mockResolvedValue(ctx);
|
||||
mocks.loadProjectContext.mockResolvedValue(ctx);
|
||||
mocks.requireProjectPermission.mockReturnValue(ctx);
|
||||
mocks.kanbanIntentPermission.mockReturnValue("projects.write");
|
||||
mocks.handleKanbanIntent.mockResolvedValue({ createdProjectId: null, handover: null });
|
||||
mocks.getTranslations.mockResolvedValue({ t: (key: string) => `translated:${key}`, locale: "en" });
|
||||
});
|
||||
|
||||
it("returns the board view model when a pipeline exists", async () => {
|
||||
const board = { vm: { status: "ready", data: { columns: [] } } };
|
||||
mocks.loadKanbanData.mockResolvedValue(board);
|
||||
const request = new Request("https://app.example.test/acme/projects?onlyMine=1&q=roof");
|
||||
|
||||
const response = await loader({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
expect(mocks.loadKanbanData).toHaveBeenCalledWith({
|
||||
tenantSlug: "acme",
|
||||
tenantId: "tenant-1",
|
||||
ctx,
|
||||
pipelineId: null,
|
||||
onlyMine: true,
|
||||
includeDemoData: false,
|
||||
q: "roof",
|
||||
locale: "en",
|
||||
// The board carries the S01 facet selection into the same query.
|
||||
facets: { owners: [], customerTypes: [], tagIds: [], periods: [], periodFrom: null, periodTo: null, valueBands: [] },
|
||||
});
|
||||
await expect(response.json()).resolves.toEqual(board);
|
||||
});
|
||||
|
||||
it("renders the existing empty state without mutating data when no pipeline exists", async () => {
|
||||
mocks.loadKanbanData.mockRejectedValue(new mocks.ProjectServiceError("projects.error.pipelineRequired"));
|
||||
const request = new Request("https://app.example.test/acme/projects");
|
||||
|
||||
const response = await loader({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
await expect(response.json()).resolves.toEqual({
|
||||
noPipeline: true,
|
||||
title: "translated:projects.list.title",
|
||||
tenantSlug: "acme",
|
||||
});
|
||||
expect(mocks.getTranslations).toHaveBeenCalledWith(request);
|
||||
});
|
||||
|
||||
it("does not hide unrelated project service failures", async () => {
|
||||
const error = new mocks.ProjectServiceError("projects.error.queryFailed");
|
||||
mocks.loadKanbanData.mockRejectedValue(error);
|
||||
|
||||
await expect(
|
||||
loader({
|
||||
request: new Request("https://app.example.test/acme/projects"),
|
||||
params: { tenant: "acme" },
|
||||
context: {},
|
||||
} as never),
|
||||
).rejects.toBe(error);
|
||||
});
|
||||
|
||||
it("returns an action-specific confirmation for consequential board actions", async () => {
|
||||
const request = new Request("https://app.example.test/acme/projects", {
|
||||
method: "POST",
|
||||
body: new URLSearchParams({ _action: "archiveProject", projectId: "project-1" }),
|
||||
});
|
||||
|
||||
const response = await action({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
await expect(response.json()).resolves.toEqual({
|
||||
ok: true,
|
||||
intent: "archiveProject",
|
||||
messageKey: "projects.toast.projectArchived",
|
||||
handover: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not request a success toast for an immediately visible stage move", async () => {
|
||||
const request = new Request("https://app.example.test/acme/projects", {
|
||||
method: "POST",
|
||||
body: new URLSearchParams({ _action: "moveStage", projectId: "project-1", targetStageId: "stage-2" }),
|
||||
});
|
||||
|
||||
const response = await action({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
await expect(response.json()).resolves.toEqual({ ok: true, intent: "moveStage", handover: null });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user