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,77 @@
|
||||
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 PageFeatureDisabled from "./PageFeatureDisabled";
|
||||
import PagePlanRequired from "./PagePlanRequired";
|
||||
|
||||
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.planRequired.eyebrow": "Plan required",
|
||||
"access.planRequired.title": "Upgrade your plan to continue.",
|
||||
"access.planRequired.namedDescription": "This feature requires a higher subscription plan for {{tenant}}. Review your subscription to restore access.",
|
||||
"access.planRequired.description": "This feature requires a higher subscription plan. Review your subscription to restore access.",
|
||||
"access.planRequired.manageSubscription": "Manage subscription",
|
||||
"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 renderAccessPage(page: React.ReactNode) {
|
||||
return render(<MemoryRouter>{page}</MemoryRouter>);
|
||||
}
|
||||
|
||||
describe("access-state pages", () => {
|
||||
it("renders the plan-required page with shared 403 shell and subscription action", () => {
|
||||
renderAccessPage(<PagePlanRequired tenantSlug="acme" subscriptionPath="/settings/subscription" />);
|
||||
|
||||
expect(screen.getByTestId("error-page")).toHaveAttribute("data-error-status", "403");
|
||||
expect(screen.getByText("Plan required")).toBeInTheDocument();
|
||||
expect(screen.getByRole("heading", { name: "Upgrade your plan to continue." })).toBeInTheDocument();
|
||||
expect(screen.getByText("This feature requires a higher subscription plan for acme. Review your subscription to restore access.")).toBeInTheDocument();
|
||||
expect(screen.getByRole("link", { name: "Manage subscription" })).toHaveAttribute("href", "/settings/subscription");
|
||||
});
|
||||
|
||||
it("renders stable plan-required copy without optional tenant or action props", () => {
|
||||
renderAccessPage(<PagePlanRequired />);
|
||||
|
||||
expect(screen.getByTestId("error-page")).toHaveAttribute("data-error-status", "403");
|
||||
expect(screen.getByText("This feature requires a higher subscription plan. Review your subscription to restore access.")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("link", { name: "Manage subscription" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(/secret/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the feature-disabled page with a safe dashboard action", () => {
|
||||
renderAccessPage(<PageFeatureDisabled featureLabel="Advanced reports" dashboardPath="/teams/acme/dashboard" />);
|
||||
|
||||
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("Advanced reports is currently disabled. Contact your administrator if you need access.")).toBeInTheDocument();
|
||||
expect(screen.getByRole("link", { name: "Back to dashboard" })).toHaveAttribute("href", "/teams/acme/dashboard");
|
||||
});
|
||||
|
||||
it("renders stable feature-disabled copy without raw feature keys or custom paths", () => {
|
||||
renderAccessPage(<PageFeatureDisabled />);
|
||||
|
||||
expect(screen.getByTestId("error-page")).toHaveAttribute("data-error-status", "403");
|
||||
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");
|
||||
expect(screen.queryByText("billing.enterprise.secret_feature")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import Page404 from "./Page404";
|
||||
|
||||
const translations = vi.hoisted<Record<string, string>>(() => ({
|
||||
"404.eyebrow": "404 error",
|
||||
}));
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string) => translations[key] ?? key,
|
||||
}),
|
||||
}));
|
||||
|
||||
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> }));
|
||||
|
||||
function renderPage404(props: React.ComponentProps<typeof Page404> = {}) {
|
||||
return render(
|
||||
<MemoryRouter>
|
||||
<Page404 {...props} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
}
|
||||
|
||||
describe("Page404", () => {
|
||||
it("delegates to the shared 404 error page while preserving custom title and controls", () => {
|
||||
renderPage404({ title: "Missing project", withFooter: false, withGoBack: false });
|
||||
|
||||
expect(screen.getByTestId("error-page")).toHaveAttribute("data-error-status", "404");
|
||||
expect(screen.getByRole("heading", { name: "Missing project" })).toBeInTheDocument();
|
||||
expect(screen.getByText("404 error")).toBeInTheDocument();
|
||||
expect(screen.queryByTestId("public-footer")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /go back/i })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { ErrorPage } from "~/components/ui/errors/ErrorPage";
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
eyebrow?: string;
|
||||
description?: string;
|
||||
withLogo?: boolean;
|
||||
withFooter?: boolean;
|
||||
withGoBack?: boolean;
|
||||
customBackButton?: React.ReactNode;
|
||||
logo?: string | undefined;
|
||||
}
|
||||
export default function Page404({ title, eyebrow, description, withLogo = true, withFooter = true, withGoBack = true, customBackButton, logo }: Props) {
|
||||
return (
|
||||
<ErrorPage
|
||||
status={404}
|
||||
title={title}
|
||||
eyebrow={eyebrow}
|
||||
description={description}
|
||||
withLogo={withLogo}
|
||||
withFooter={withFooter}
|
||||
withGoBack={withGoBack}
|
||||
customBackButton={customBackButton}
|
||||
logo={logo}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { ErrorPage } from "~/components/ui/errors/ErrorPage";
|
||||
|
||||
export interface PageFeatureDisabledProps {
|
||||
featureLabel?: string;
|
||||
dashboardPath?: string;
|
||||
}
|
||||
|
||||
export default function PageFeatureDisabled({ featureLabel, dashboardPath = "/dashboard" }: PageFeatureDisabledProps) {
|
||||
const { t } = useTranslation();
|
||||
const featureCopy = featureLabel
|
||||
? t("access.featureDisabled.namedDescription", { feature: featureLabel })
|
||||
: t("access.featureDisabled.description");
|
||||
|
||||
return (
|
||||
<ErrorPage
|
||||
status={403}
|
||||
eyebrow={t("access.featureDisabled.eyebrow")}
|
||||
title={t("access.featureDisabled.title")}
|
||||
description={t("access.featureDisabled.fullDescription", {
|
||||
featureCopy,
|
||||
})}
|
||||
withGoBack={false}
|
||||
actionSlot={
|
||||
<Link to={dashboardPath} className="text-primary hover:text-primary/90 text-sm font-medium underline">
|
||||
{t("access.featureDisabled.backToDashboard")}
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import PageMaintenanceMode from "./PageMaintenanceMode";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string) =>
|
||||
({
|
||||
"shared.maintenance.title": "Maintenance in progress",
|
||||
"shared.maintenance.description": "We're doing scheduled maintenance.",
|
||||
"shared.clickHereToTryAgain": "Try again",
|
||||
"503.eyebrow": "503 error",
|
||||
})[key] ?? key,
|
||||
}),
|
||||
}));
|
||||
|
||||
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> }));
|
||||
|
||||
function renderPageMaintenanceMode() {
|
||||
return render(
|
||||
<MemoryRouter>
|
||||
<PageMaintenanceMode />
|
||||
</MemoryRouter>
|
||||
);
|
||||
}
|
||||
|
||||
describe("PageMaintenanceMode", () => {
|
||||
it("renders the shared 503 error-page shell with translated copy", () => {
|
||||
renderPageMaintenanceMode();
|
||||
|
||||
const page = screen.getByTestId("error-page");
|
||||
expect(page).toHaveAttribute("data-error-status", "503");
|
||||
expect(screen.getByText("503 error")).toBeInTheDocument();
|
||||
expect(screen.getByRole("heading", { name: "Maintenance in progress" })).toBeInTheDocument();
|
||||
expect(screen.getByText("We're doing scheduled maintenance.")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders a retry action without exposing diagnostics by default", () => {
|
||||
renderPageMaintenanceMode();
|
||||
|
||||
expect(screen.getByRole("link", { name: "Try again" })).toHaveAttribute("href", "/");
|
||||
expect(screen.queryByText("stack trace details")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { ErrorPage } from "~/components/ui/errors/ErrorPage";
|
||||
|
||||
export default function PageMaintenanceMode() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<ErrorPage
|
||||
status={503}
|
||||
title={t("shared.maintenance.title")}
|
||||
description={t("shared.maintenance.description")}
|
||||
withGoBack={false}
|
||||
actionSlot={
|
||||
<Link to="." className="text-muted-foreground dark:text-muted-foreground text-sm underline">
|
||||
{t("shared.clickHereToTryAgain")}
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { ErrorPage } from "~/components/ui/errors/ErrorPage";
|
||||
|
||||
export interface PagePlanRequiredProps {
|
||||
tenantSlug?: string;
|
||||
subscriptionPath?: string;
|
||||
}
|
||||
|
||||
export default function PagePlanRequired({ tenantSlug, subscriptionPath }: PagePlanRequiredProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<ErrorPage
|
||||
status={403}
|
||||
eyebrow={t("access.planRequired.eyebrow")}
|
||||
title={t("access.planRequired.title")}
|
||||
description={
|
||||
tenantSlug
|
||||
? t("access.planRequired.namedDescription", {
|
||||
tenant: tenantSlug,
|
||||
})
|
||||
: t("access.planRequired.description")
|
||||
}
|
||||
withGoBack={false}
|
||||
actionSlot={
|
||||
subscriptionPath ? (
|
||||
<Link to={subscriptionPath} className="text-primary hover:text-primary/90 text-sm font-medium underline">
|
||||
{t("access.planRequired.manageSubscription")}
|
||||
</Link>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user