Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,101 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import FeatureDisabledRoute, { getFeatureDisabledDashboardPath, getSafeFeatureLabel } from "./feature-disabled";
|
||||
|
||||
vi.mock("~/components/brand/Logo", () => ({ default: () => <div data-testid="logo">Logo</div> }));
|
||||
vi.mock("~/components/public/PublicFooter", () => ({ default: () => <footer data-testid="public-footer">Footer</footer> }));
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, options?: Record<string, unknown>) => {
|
||||
const messages: Record<string, string> = {
|
||||
"access.featureDisabled.eyebrow": "Feature disabled",
|
||||
"access.featureDisabled.title": "Feature unavailable.",
|
||||
"access.featureDisabled.namedDescription": "{{feature}} is currently disabled.",
|
||||
"access.featureDisabled.description": "This feature is currently disabled.",
|
||||
"access.featureDisabled.fullDescription": "{{featureCopy}} Contact your administrator if you need access.",
|
||||
"access.featureDisabled.backToDashboard": "Back to dashboard",
|
||||
};
|
||||
let value = typeof options?.defaultValue === "string" ? options.defaultValue : messages[key] ?? key;
|
||||
for (const [name, replacement] of Object.entries(options ?? {})) {
|
||||
value = value.replaceAll(`{{${name}}}`, String(replacement));
|
||||
}
|
||||
return value;
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
function renderRoute(search = "") {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[`/feature-disabled${search}`]}>
|
||||
<FeatureDisabledRoute />
|
||||
</MemoryRouter>
|
||||
);
|
||||
}
|
||||
|
||||
describe("feature-disabled route", () => {
|
||||
it("renders default feature-disabled copy through the shared 403 shell", () => {
|
||||
renderRoute();
|
||||
|
||||
expect(screen.getByTestId("error-page")).toHaveAttribute("data-error-status", "403");
|
||||
expect(screen.getByText("Feature disabled")).toBeInTheDocument();
|
||||
expect(screen.getByRole("heading", { name: "Feature unavailable." })).toBeInTheDocument();
|
||||
expect(screen.getByText("This feature is currently disabled. Contact your administrator if you need access.")).toBeInTheDocument();
|
||||
expect(screen.getByRole("link", { name: "Back to dashboard" })).toHaveAttribute("href", "/dashboard");
|
||||
});
|
||||
|
||||
it("displays a safe query label", () => {
|
||||
renderRoute("?feature=Advanced%20reports");
|
||||
|
||||
expect(screen.getByText("Advanced reports is currently disabled. Contact your administrator if you need access.")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("routes the dashboard action through the tenant app path when a safe tenant is present", () => {
|
||||
renderRoute("?tenant=acme");
|
||||
|
||||
expect(screen.getByRole("link", { name: "Back to dashboard" })).toHaveAttribute("href", "/acme/dashboard");
|
||||
});
|
||||
|
||||
it("falls back to the neutral dashboard action for unsafe tenant query values", () => {
|
||||
renderRoute("?tenant=acme%2F..%2Fadmin");
|
||||
|
||||
expect(screen.getByRole("link", { name: "Back to dashboard" })).toHaveAttribute("href", "/dashboard");
|
||||
});
|
||||
|
||||
it("falls back for script-like feature labels", () => {
|
||||
renderRoute("?feature=%3Cscript%3Ealert(1)%3C%2Fscript%3E");
|
||||
|
||||
expect(screen.getByText("This feature is currently disabled. Contact your administrator if you need access.")).toBeInTheDocument();
|
||||
expect(screen.queryByText(/script/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("falls back for secret-like feature labels", () => {
|
||||
renderRoute("?feature=billing.enterprise.secret_feature");
|
||||
|
||||
expect(screen.getByText("This feature is currently disabled. Contact your administrator if you need access.")).toBeInTheDocument();
|
||||
expect(screen.queryByText("billing.enterprise.secret_feature")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("accepts long but bounded feature labels for mobile-safe wrapping", () => {
|
||||
const label = "VeryLongUnbrokenFeatureNameThatShouldStillWrapSafelyOnSmallMobileScreens";
|
||||
|
||||
expect(getSafeFeatureLabel(label)).toBe(label);
|
||||
});
|
||||
|
||||
it("rejects overlong feature labels before rendering them", () => {
|
||||
expect(getSafeFeatureLabel("a".repeat(81))).toBeUndefined();
|
||||
});
|
||||
|
||||
it("trims safe feature labels before rendering", () => {
|
||||
expect(getSafeFeatureLabel(" Advanced reports ")).toBe("Advanced reports");
|
||||
});
|
||||
|
||||
it("keeps tenant dashboard links constrained to safe tenant slugs", () => {
|
||||
expect(getFeatureDisabledDashboardPath("acme-team")).toBe("/acme-team/dashboard");
|
||||
expect(getFeatureDisabledDashboardPath("Acme")).toBe("/dashboard");
|
||||
expect(getFeatureDisabledDashboardPath("acme/../../admin")).toBe("/dashboard");
|
||||
expect(getFeatureDisabledDashboardPath("a".repeat(64))).toBe("/dashboard");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user