Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,153 @@
import "@testing-library/jest-dom";
import React from "react";
import { fireEvent, render, screen, within } from "@testing-library/react";
import { createMemoryRouter, RouterProvider } from "react-router";
import { beforeAll, describe, expect, it, vi } from "vitest";
import { UI_ACTION_IDS } from "~/application/ui/uiRegistry";
import { SidebarProvider } from "~/components/ui/sidebar";
import { NavActions } from "./nav-actions";
const fetcherSubmit = vi.fn();
beforeAll(() => {
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(),
removeListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
});
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (value: string) => value }),
}));
vi.mock("~/utils/data/useRootData", () => ({
useRootData: () => ({
appConfiguration: {
app: { features: { tenantFeedback: true } },
notifications: { enabled: false },
onboarding: { enabled: false },
},
chatWebsiteId: null,
userSession: { lightOrDarkMode: "light" },
}),
}));
vi.mock("~/utils/data/useAppOrAdminData", () => ({
useAppOrAdminData: () => ({
currentTenant: { id: "tenant-1", slug: "acme" },
entities: [],
permissions: ["app.settings.subscription.view", "app.settings.subscription.update"],
user: { id: "user-1" },
onboardingSession: null,
}),
}));
vi.mock("~/utils/data/useAppData", () => ({
useAppData: () => ({ mySubscription: { products: [] } }),
}));
vi.mock("react-router", async () => {
const actual = await vi.importActual<typeof import("react-router")>("react-router");
return {
...actual,
useFetcher: () => ({
data: undefined,
submit: fetcherSubmit,
Form: (props: React.ComponentProps<"form">) => <form {...props} />,
}),
};
});
function renderNavActions({ layout, initialEntry }: { layout: "admin" | "app" | "docs"; initialEntry: string }) {
const element = (
<SidebarProvider>
<NavActions layout={layout} onOpenCommandPalette={vi.fn()} setOnboardingModalOpen={vi.fn()} />
</SidebarProvider>
);
const router = createMemoryRouter(
[
{ path: "/:tenant/*", element },
{ path: "/*", element },
],
{ initialEntries: [initialEntry] }
);
return render(<RouterProvider router={router} />);
}
describe("NavActions UI IDs", () => {
it("renders stable header action IDs for search and more", () => {
renderNavActions({ layout: "app", initialEntry: "/acme/dashboard" });
expect(document.querySelector(`[data-ui-id="${UI_ACTION_IDS.search}"]`)).toBeInTheDocument();
expect(document.querySelector(`[data-ui-id="${UI_ACTION_IDS.more}"]`)).toBeInTheDocument();
});
it("keeps icon-only header actions named, focusable, and mobile-scroll safe", () => {
renderNavActions({ layout: "app", initialEntry: "/acme/dashboard" });
const search = screen.getByRole("button", { name: "shared.search" });
const more = screen.getByRole("button", { name: "shared.openMenu" });
const feedback = screen.getByRole("button", { name: "feedback.title" });
const actionStrip = search.parentElement;
expect(actionStrip).toHaveClass("min-w-0", "max-w-[calc(100vw-4rem)]", "overflow-x-auto", "md:overflow-visible");
expect(search).toHaveClass("size-10", "shrink-0", "focus-visible:ring-[3px]");
expect(more).toHaveClass("size-10", "shrink-0", "data-[state=open]:bg-accent");
expect(feedback).toHaveClass("size-10", "shrink-0");
// The decorative search icon (a Subframe Feather icon: <span aria-hidden><svg/></span>)
// is hidden from assistive tech at the icon wrapper, which contains the svg.
const hiddenSearchIcon = search.querySelector("[aria-hidden='true']");
expect(hiddenSearchIcon).not.toBeNull();
expect(hiddenSearchIcon?.querySelector("svg")).not.toBeNull();
});
});
describe("NavActions host-aware links", () => {
it("renders tenant profile and subscription paths without legacy app prefix", () => {
renderNavActions({ layout: "app", initialEntry: "/acme/dashboard" });
fireEvent.click(document.querySelector(`[data-ui-id="${UI_ACTION_IDS.more}"]`)!);
const profile = screen.getByRole("link", { name: /app\.navbar\.profile/i });
const subscription = screen.getByRole("link", { name: /app\.navbar\.subscription/i });
expect(profile).toHaveAttribute("href", "/acme/settings/profile");
expect(subscription).toHaveAttribute("href", "/acme/settings/subscription");
expect(profile.getAttribute("href")).not.toContain("/app/");
expect(subscription.getAttribute("href")).not.toContain("/app/");
});
it("renders admin profile path without legacy admin prefix", () => {
renderNavActions({ layout: "admin", initialEntry: "/dashboard" });
fireEvent.click(document.querySelector(`[data-ui-id="${UI_ACTION_IDS.more}"]`)!);
const profile = screen.getByRole("link", { name: /app\.navbar\.profile/i });
expect(profile).toHaveAttribute("href", "/settings/profile");
expect(profile.getAttribute("href")).not.toContain("/admin/settings");
});
it("submits feedback to the tenant-root action without legacy app prefix", () => {
renderNavActions({ layout: "app", initialEntry: "/acme/dashboard" });
fireEvent.click(document.querySelector(`[data-ui-id="${UI_ACTION_IDS.feedback}"]`)!);
fireEvent.change(screen.getByPlaceholderText("feedback.placeholder"), { target: { value: "Helpful feedback" } });
fireEvent.submit(within(screen.getByRole("dialog")).getByRole("button", { name: "feedback.send" }).closest("form")!);
expect(fetcherSubmit).toHaveBeenCalledWith(expect.any(HTMLFormElement), {
method: "post",
action: "/acme",
});
expect(fetcherSubmit.mock.calls[0][1].action).not.toContain("/app/");
});
});