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 }, }; 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); expect(result[0].items).toEqual( expect.arrayContaining([ expect.objectContaining({ id: "ui.nav.app.dashboard", title: "app.sidebar.dashboard", path: "/test-user/dashboard", }), expect.objectContaining({ id: UI_NAV_IDS.appNotifications, title: "app.sidebar.notifications", path: "/test-user/notifications", }), ]) ); expect(result[1]).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("/email-marketing"); expect(serialized).not.toContain("/workflow-engine"); expect(serialized).not.toContain("/widgets"); expect(serialized).not.toContain("/portals"); expect(serialized).not.toContain("/sites/"); }); 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 starter = JSON.stringify(AppSidebar({ t, i18n, tenantId: "starter", appConfiguration: null, productAccess: starterProductAccess })); const pro = JSON.stringify(AppSidebar({ t, i18n, tenantId: "pro", appConfiguration: null, productAccess: proProductAccess })); const business = JSON.stringify(AppSidebar({ t, i18n, tenantId: "business", appConfiguration: null, productAccess: businessProductAccess })); 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(starter).not.toContain("/starter/settings/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(pro).toContain("/pro/settings/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(business).toContain("/business/settings/api"); expect(business).toContain("/business/workflow-engine"); }); 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); expect(serialized).toContain("/acme/dashboard"); expect(serialized).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).toContain("/acme/workflow-engine"); expect(serialized).toContain("/acme/settings/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/notifications.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/__workflows/workflow-engine.tsx", "apps/web/app/routes/app.$tenant/settings/api/index.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); }); }); });