319 lines
14 KiB
TypeScript
319 lines
14 KiB
TypeScript
import { existsSync } from "node:fs";
|
|
import { vi, describe, it, expect } from "vitest";
|
|
import { AppSidebar } from "./AppSidebar";
|
|
import { UI_NAV_IDS } from "~/application/ui/uiRegistry";
|
|
import { resolveRepoPath } from "~/utils/testing/repoPaths";
|
|
|
|
// R-P6B-β (AD-2): the generic entity-builder is gone, so AppSidebar no longer
|
|
// renders dynamic per-entity / entity-group nav. Only typed product features and
|
|
// static targets remain.
|
|
|
|
describe("AppSidebar", () => {
|
|
const starterProductAccess = {
|
|
dashboard: { allowed: true },
|
|
"crm-basic": { allowed: true },
|
|
projects: { allowed: true },
|
|
automation: { allowed: false },
|
|
"email-marketing": { allowed: false },
|
|
api: { allowed: false },
|
|
"workflow-engine": { allowed: false },
|
|
"ai-credits": { allowed: true },
|
|
};
|
|
const proProductAccess = {
|
|
dashboard: { allowed: true },
|
|
"crm-basic": { allowed: true },
|
|
projects: { allowed: true },
|
|
automation: { allowed: false },
|
|
"email-marketing": { allowed: true },
|
|
"email-inbox": { allowed: true },
|
|
api: { allowed: true },
|
|
"workflow-engine": { allowed: false },
|
|
"ai-credits": { allowed: true },
|
|
};
|
|
const businessProductAccess = {
|
|
dashboard: { allowed: true },
|
|
"crm-basic": { allowed: true },
|
|
projects: { allowed: true },
|
|
automation: { allowed: true },
|
|
"email-marketing": { allowed: true },
|
|
"email-inbox": { allowed: true },
|
|
api: { allowed: true },
|
|
"workflow-engine": { allowed: true },
|
|
"ai-credits": { allowed: true },
|
|
};
|
|
const fullProductAccess = {
|
|
...businessProductAccess,
|
|
leads: { allowed: true },
|
|
tasks: { allowed: true },
|
|
files: { allowed: true },
|
|
hr: { allowed: true },
|
|
forms: { allowed: true },
|
|
booking: { allowed: true },
|
|
integrations: { allowed: true },
|
|
chat: { allowed: true },
|
|
};
|
|
|
|
it("returns the expected static sidebar items", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
|
|
const result = AppSidebar({ t, i18n, tenantId: "test-user", appConfiguration: null });
|
|
const serialized = JSON.stringify(result);
|
|
const secondary = result.find((group) => group.isSecondary);
|
|
|
|
expect(result).toEqual(expect.arrayContaining([expect.objectContaining({ id: "ui.nav.app.overview", title: "" })]));
|
|
expect(result[0].items).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: "ui.nav.app.dashboard",
|
|
title: "app.sidebar.dashboard",
|
|
path: "/test-user/dashboard",
|
|
}),
|
|
])
|
|
);
|
|
expect(secondary).toMatchObject({
|
|
title: "",
|
|
path: "",
|
|
isSecondary: true,
|
|
items: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: "ui.nav.app.settings",
|
|
title: "app.sidebar.settings",
|
|
path: "/test-user/settings",
|
|
redirectTo: "/test-user/settings/profile",
|
|
}),
|
|
expect.objectContaining({
|
|
id: "ui.nav.app.switchToAdmin",
|
|
title: "admin.switchToAdmin",
|
|
path: "/dashboard",
|
|
adminOnly: true,
|
|
}),
|
|
]),
|
|
});
|
|
expect(serialized).not.toContain("ui.nav.app.entity.");
|
|
expect(serialized).not.toContain("ui.nav.app.entityGroup.");
|
|
expect(serialized).not.toContain("/app/");
|
|
expect(serialized).not.toContain("/admin/");
|
|
expect(serialized).not.toContain("/blog");
|
|
expect(serialized).not.toContain("/pricing");
|
|
expect(serialized).not.toContain("/search");
|
|
expect(serialized).not.toContain("/notifications");
|
|
expect(serialized).not.toContain("/email-marketing");
|
|
expect(serialized).not.toContain("/workflow-engine");
|
|
expect(serialized).not.toContain("/widgets");
|
|
expect(serialized).not.toContain("/portals");
|
|
expect(serialized).not.toContain("/sites/");
|
|
});
|
|
|
|
it("groups plan-backed product links into clear app navigation sections", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
|
|
const result = AppSidebar({ t, i18n, tenantId: "business", appConfiguration: null, productAccess: businessProductAccess });
|
|
|
|
expect(result).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ id: "ui.nav.app.overview", title: "" }),
|
|
expect.objectContaining({ id: "ui.nav.app.customers", title: "app.sidebar.sections.customers" }),
|
|
expect.objectContaining({ id: "ui.nav.app.projects", title: "app.sidebar.sections.projects" }),
|
|
expect.objectContaining({ id: "ui.nav.app.communication", title: "app.sidebar.sections.communication" }),
|
|
expect.objectContaining({ id: "ui.nav.app.automationPlatform", title: "app.sidebar.sections.automationPlatform" }),
|
|
])
|
|
);
|
|
|
|
expect(result.find((group) => group.id === "ui.nav.app.overview")?.items?.map((item) => item.id)).toEqual([UI_NAV_IDS.appDashboard]);
|
|
expect(result.find((group) => group.id === "ui.nav.app.customers")?.items?.map((item) => item.id)).toEqual([UI_NAV_IDS.appCrm]);
|
|
expect(result.find((group) => group.id === "ui.nav.app.projects")?.items?.map((item) => item.id)).toEqual([
|
|
UI_NAV_IDS.appProjects,
|
|
UI_NAV_IDS.appPlantafel,
|
|
]);
|
|
expect(result.find((group) => group.id === "ui.nav.app.communication")?.items?.map((item) => item.id)).toEqual([
|
|
UI_NAV_IDS.appEmails,
|
|
UI_NAV_IDS.appEmailMarketing,
|
|
]);
|
|
expect(result.find((group) => group.id === "ui.nav.app.automationPlatform")?.items?.map((item) => item.id)).toEqual([UI_NAV_IDS.appAutomation]);
|
|
expect(result.find((group) => group.id === "ui.nav.app.apiDeveloper")).toBeUndefined();
|
|
});
|
|
|
|
it("renders plan-backed core feature links from product access decisions", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
|
|
const starterResult = AppSidebar({ t, i18n, tenantId: "starter", appConfiguration: null, productAccess: starterProductAccess });
|
|
const proResult = AppSidebar({ t, i18n, tenantId: "pro", appConfiguration: null, productAccess: proProductAccess });
|
|
const businessResult = AppSidebar({ t, i18n, tenantId: "business", appConfiguration: null, productAccess: businessProductAccess });
|
|
const starter = JSON.stringify(starterResult);
|
|
const pro = JSON.stringify(proResult);
|
|
const business = JSON.stringify(businessResult);
|
|
const primaryPaths = (groups: ReturnType<typeof AppSidebar>) =>
|
|
groups.filter((group) => !group.isSecondary).flatMap((group) => group.items?.map((item) => item.path) ?? []);
|
|
|
|
expect(starter).toContain("/starter/contacts");
|
|
expect(starter).toContain("/starter/projects");
|
|
expect(starter).not.toContain("/starter/settings/credits");
|
|
expect(starter).not.toContain("/starter/email-marketing");
|
|
expect(starter).not.toContain("/starter/emails");
|
|
expect(starter).not.toContain("/starter/automations");
|
|
expect(primaryPaths(starterResult)).not.toContain("/starter/api");
|
|
expect(starter).not.toContain("/starter/workflow-engine");
|
|
|
|
expect(pro).toContain("/pro/contacts");
|
|
expect(pro).toContain("/pro/projects");
|
|
expect(pro).toContain("/pro/email-marketing");
|
|
expect(pro).toContain("/pro/emails");
|
|
expect(pro).not.toContain("/pro/automations");
|
|
expect(primaryPaths(proResult)).not.toContain("/pro/api");
|
|
expect(pro).not.toContain("/pro/workflow-engine");
|
|
|
|
expect(business).toContain("/business/contacts");
|
|
expect(business).toContain("/business/projects");
|
|
expect(business).toContain("/business/email-marketing");
|
|
expect(business).toContain("/business/automations");
|
|
expect(primaryPaths(businessResult)).not.toContain("/business/api");
|
|
expect(business).not.toContain("/business/workflow-engine");
|
|
});
|
|
|
|
it("shows telephony only with product access and carries the read permission gate", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
const withoutTelephony = AppSidebar({ t, i18n, tenantId: "acme", appConfiguration: null, productAccess: businessProductAccess });
|
|
const withTelephony = AppSidebar({
|
|
t,
|
|
i18n,
|
|
tenantId: "acme",
|
|
appConfiguration: null,
|
|
productAccess: { ...businessProductAccess, telephony: { allowed: true } },
|
|
});
|
|
|
|
expect(JSON.stringify(withoutTelephony)).not.toContain("/acme/calls");
|
|
expect(withTelephony.flatMap((group) => group.items ?? [])).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: UI_NAV_IDS.appTelephony,
|
|
title: "telephony.nav.title",
|
|
path: "/acme/calls",
|
|
permission: "telephony.read_own",
|
|
}),
|
|
])
|
|
);
|
|
});
|
|
|
|
it("shows team chat only with product access and carries the member read gate", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
const withoutChat = AppSidebar({ t, i18n, tenantId: "acme", appConfiguration: null, productAccess: businessProductAccess });
|
|
const withChat = AppSidebar({
|
|
t,
|
|
i18n,
|
|
tenantId: "acme",
|
|
appConfiguration: null,
|
|
productAccess: { ...businessProductAccess, chat: { allowed: true } },
|
|
});
|
|
|
|
expect(JSON.stringify(withoutChat)).not.toContain("/acme/chat");
|
|
expect(withChat.flatMap((group) => group.items ?? [])).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: UI_NAV_IDS.appChat,
|
|
title: "chat.nav.title",
|
|
path: "/acme/chat",
|
|
permission: "chat.read_own_channels",
|
|
}),
|
|
])
|
|
);
|
|
});
|
|
|
|
it("keeps balanced global destinations while consolidating the appointment area", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
const result = AppSidebar({ t, i18n, tenantId: "full", appConfiguration: null, productAccess: fullProductAccess });
|
|
const globalItems = result.filter((group) => !group.isSecondary).flatMap((group) => group.items ?? []);
|
|
|
|
expect(globalItems.map((item) => item.id)).toEqual([
|
|
UI_NAV_IDS.appDashboard,
|
|
"ui.nav.app.tasks",
|
|
UI_NAV_IDS.appCrm,
|
|
UI_NAV_IDS.appLeads,
|
|
UI_NAV_IDS.appProjects,
|
|
UI_NAV_IDS.appPlantafel,
|
|
"ui.nav.app.files",
|
|
UI_NAV_IDS.appEmails,
|
|
UI_NAV_IDS.appEmailMarketing,
|
|
UI_NAV_IDS.appForms,
|
|
"ui.nav.app.appointments",
|
|
UI_NAV_IDS.appChat,
|
|
"ui.nav.app.hr",
|
|
UI_NAV_IDS.appPasswordSafe,
|
|
UI_NAV_IDS.appAutomation,
|
|
]);
|
|
// WF-P8 S00: boards start page is the consolidated module entry, so the
|
|
// projects group is back to at most three entries.
|
|
expect(result.find((group) => group.id === "ui.nav.app.projects")?.items).toHaveLength(3);
|
|
expect(globalItems.find((item) => item.id === "ui.nav.app.appointments")?.contextItems).toHaveLength(3);
|
|
expect(globalItems.find((item) => item.id === UI_NAV_IDS.appPasswordSafe)).toMatchObject({
|
|
path: "/full/passwords",
|
|
anyPermissions: ["hr.passwordsafe.use", "hr.passwordsafe.admin"],
|
|
});
|
|
});
|
|
|
|
it("reaches the lead statistics through the leads sub-sidenav, not through the inbox screen", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
|
|
const result = AppSidebar({ t, i18n, tenantId: "acme", appConfiguration: null, productAccess: fullProductAccess });
|
|
const leads = result.flatMap((group) => group.items ?? []).find((item) => item.id === UI_NAV_IDS.appLeads);
|
|
|
|
expect(leads?.contextItems?.map((item) => item.path)).toEqual([
|
|
"/acme/leads",
|
|
"/acme/leads-statistics",
|
|
"/acme/admin/lead-sources",
|
|
"/acme/admin/lead-anti-spam",
|
|
]);
|
|
// Same permission as the inbox: everyone who sees leads sees their statistics.
|
|
expect(leads?.contextItems?.find((item) => item.id === "ui.nav.app.leads.statistics")).toMatchObject({
|
|
title: "leads.statistics.title",
|
|
permission: "leads.read_own",
|
|
});
|
|
// The statistics path must stay highlighted as part of the leads workspace —
|
|
// that is also what puts "Leads" in front of the breadcrumb.
|
|
expect(leads?.activePaths).toContain("/acme/leads-statistics");
|
|
expect(existsSync(resolveRepoPath("apps/web/app/routes/app.$tenant/leads-statistics.tsx"))).toBe(true);
|
|
});
|
|
|
|
it("keeps static tenant sidebar targets backed by registered route files", () => {
|
|
const t = vi.fn().mockImplementation((v: string) => v) as any;
|
|
const i18n = { exists: vi.fn().mockReturnValue(false) } as any;
|
|
const result = AppSidebar({ t, i18n, tenantId: "acme", appConfiguration: null, productAccess: businessProductAccess });
|
|
const serialized = JSON.stringify(result);
|
|
const primaryPaths = result.filter((group) => !group.isSecondary).flatMap((group) => group.items?.map((item) => item.path) ?? []);
|
|
|
|
expect(serialized).toContain("/acme/dashboard");
|
|
expect(serialized).not.toContain("/acme/notifications");
|
|
expect(serialized).toContain("/acme/contacts");
|
|
expect(serialized).toContain("/acme/projects");
|
|
expect(serialized).toContain("/acme/automations");
|
|
expect(serialized).toContain("/acme/email-marketing");
|
|
expect(serialized).not.toContain("/acme/workflow-engine");
|
|
expect(primaryPaths).not.toContain("/acme/api");
|
|
expect(serialized).not.toContain("/acme/settings/credits");
|
|
expect(serialized).toContain("/acme/settings");
|
|
expect(serialized).toContain("/acme/settings/profile");
|
|
expect(serialized).not.toContain("/app/");
|
|
expect(serialized).not.toContain("/admin/");
|
|
|
|
[
|
|
"apps/web/app/routes/app.$tenant/dashboard.tsx",
|
|
"apps/web/app/routes/app.$tenant/contacts._index.tsx",
|
|
"apps/web/app/routes/app.$tenant/projects._index.tsx",
|
|
"apps/web/app/routes/app.$tenant/automations._index.tsx",
|
|
"apps/web/app/routes/app.$tenant/automations.$id.edit.tsx",
|
|
"apps/web/app/routes/app.$tenant/automations.templates._index.tsx",
|
|
"apps/web/app/routes/app.$tenant/email-marketing.tsx",
|
|
"apps/web/app/routes/app.$tenant/settings.tsx",
|
|
"apps/web/app/routes/app.$tenant/settings/profile.tsx",
|
|
].forEach((routeFile) => {
|
|
expect(existsSync(resolveRepoPath(routeFile))).toBe(true);
|
|
});
|
|
});
|
|
});
|