Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+21
-17
@@ -1,7 +1,8 @@
|
||||
// @vitest-environment jsdom
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { createMemoryRouter, RouterProvider } from "react-router";
|
||||
|
||||
import { CreateWorkspacePage, type CreateWorkspacePageProps } from "./CreateWorkspacePage";
|
||||
|
||||
@@ -12,42 +13,45 @@ vi.mock("react-i18next", () => ({
|
||||
function baseProps(overrides: Partial<CreateWorkspacePageProps> = {}): CreateWorkspacePageProps {
|
||||
return {
|
||||
csrf: "csrf-token",
|
||||
creationRequestKey: "d7077797-054b-497a-b1ce-8e4f36257a96",
|
||||
error: undefined,
|
||||
backHref: "/select-tenant",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function renderPage(props: CreateWorkspacePageProps) {
|
||||
const router = createMemoryRouter([{ path: "/", element: <CreateWorkspacePage {...props} />, action: async () => null }], {
|
||||
initialEntries: ["/"],
|
||||
});
|
||||
return render(<RouterProvider router={router} />);
|
||||
}
|
||||
|
||||
describe("CreateWorkspacePage (interim-UI)", () => {
|
||||
it("renders the create surface + form/name/submit/back markers and the csrf field", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<CreateWorkspacePage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
const { container } = renderPage(baseProps());
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.page"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.form"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.name"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.submit"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.back"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('input[type="hidden"][name="csrf"][value="csrf-token"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('input[type="hidden"][name="creationRequestKey"][value="d7077797-054b-497a-b1ce-8e4f36257a96"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the error alert with its marker when an error is passed", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<CreateWorkspacePage {...baseProps({ error: "Something went wrong" })} />
|
||||
</Router>,
|
||||
);
|
||||
const { container } = renderPage(baseProps({ error: "Something went wrong" }));
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.error"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("omits the error alert when there is no error", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<CreateWorkspacePage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
const { container } = renderPage(baseProps());
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.error"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("disables the submit button and shows clear progress while creation is submitting", () => {
|
||||
const { getByRole } = renderPage(baseProps({ isSubmitting: true }));
|
||||
|
||||
expect(getByRole("button", { name: "shared.creating" })).toBeDisabled();
|
||||
});
|
||||
});
|
||||
+15
-8
@@ -5,7 +5,9 @@
|
||||
// once David's D-P2 delta ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { AppLink } from "~/components/app/AppLink";
|
||||
import { FeatherArrowLeft } from "@subframe/core";
|
||||
import { Form } from "react-router";
|
||||
import { AuthShell } from "~/components/auth/AuthShell";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
@@ -15,13 +17,17 @@ import { TextInput } from "~/ui/components/TextInput";
|
||||
export type CreateWorkspacePageProps = {
|
||||
/** CSRF token for the server-driven create action. */
|
||||
csrf: string;
|
||||
/** Server-generated key that makes duplicate submissions replay-safe. */
|
||||
creationRequestKey: string;
|
||||
/** Error message from the last failed submit (route passes it only while idle). */
|
||||
error?: string;
|
||||
/** Prevents duplicate submits while the server is creating the workspace. */
|
||||
isSubmitting?: boolean;
|
||||
/** Back target: the tenant picker when the user already has workspaces, else login. */
|
||||
backHref: string;
|
||||
};
|
||||
|
||||
export function CreateWorkspacePage({ csrf, error, backHref }: CreateWorkspacePageProps) {
|
||||
export function CreateWorkspacePage({ csrf, creationRequestKey, error, isSubmitting = false, backHref }: CreateWorkspacePageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
@@ -31,28 +37,29 @@ export function CreateWorkspacePage({ csrf, error, backHref }: CreateWorkspacePa
|
||||
titleAlign="start"
|
||||
dataUiId="ui.account.create.page"
|
||||
footer={
|
||||
<a href={backHref} className="no-underline" data-ui-id="ui.account.create.back">
|
||||
<AppLink href={backHref} className="no-underline" data-ui-id="ui.account.create.back">
|
||||
<LinkButton size="small" icon={<FeatherArrowLeft />}>
|
||||
{t("shared.goBack")}
|
||||
</LinkButton>
|
||||
</a>
|
||||
</AppLink>
|
||||
}
|
||||
>
|
||||
<form method="post" className="flex w-full flex-col gap-4" data-ui-id="ui.account.create.form">
|
||||
{/* The action intent is vestigial (the /new-account action reads only name+csrf) but stays
|
||||
<Form method="post" className="flex w-full flex-col gap-4" data-ui-id="ui.account.create.form">
|
||||
{/* The action intent is vestigial (the /new-account action reads name, request key and csrf) but stays
|
||||
in the wire payload as a stable contract other consumers/tests assert. */}
|
||||
<input type="hidden" name="action" value="create" readOnly />
|
||||
<input type="hidden" name="csrf" value={csrf} readOnly />
|
||||
<input type="hidden" name="creationRequestKey" value={creationRequestKey} readOnly />
|
||||
<TextInput className="h-auto w-full flex-none" fillContainer showLabel label={t("shared.name")}>
|
||||
<TextInput.Input name="name" required placeholder={t("shared.name")} data-ui-id="ui.account.create.name" />
|
||||
</TextInput>
|
||||
|
||||
{error ? <Alert variant="error" notDismissible title={error} data-ui-id="ui.account.create.error" /> : null}
|
||||
|
||||
<Button type="submit" className="h-9 w-full flex-none" data-ui-id="ui.account.create.submit">
|
||||
{t("shared.create")}
|
||||
<Button type="submit" disabled={isSubmitting} className="h-9 w-full flex-none" data-ui-id="ui.account.create.submit">
|
||||
{t(isSubmitting ? "shared.creating" : "shared.create")}
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
</AuthShell>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user