b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
128 lines
3.9 KiB
TypeScript
128 lines
3.9 KiB
TypeScript
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import * as React from "react";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
|
|
import { WelcomeModal } from "../../src/components/WelcomeModal";
|
|
import { render } from "../utils/render";
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Constants
|
|
// ---------------------------------------------------------------------------
|
|
|
|
const WELCOME_MESSAGE_REGEX = /Welcome to EmDash, Alice!/;
|
|
const ADMIN_TEXT_REGEX = /As an administrator, you can invite other users/;
|
|
|
|
vi.mock("../../src/lib/api/client", async () => {
|
|
const actual = await vi.importActual("../../src/lib/api/client");
|
|
return {
|
|
...actual,
|
|
apiFetch: vi
|
|
.fn()
|
|
.mockResolvedValue(new Response(JSON.stringify({ success: true }), { status: 200 })),
|
|
};
|
|
});
|
|
|
|
function QueryWrapper({ children }: { children: React.ReactNode }) {
|
|
const qc = new QueryClient({
|
|
defaultOptions: {
|
|
queries: { retry: false },
|
|
mutations: { retry: false },
|
|
},
|
|
});
|
|
return <QueryClientProvider client={qc}>{children}</QueryClientProvider>;
|
|
}
|
|
|
|
const noop = () => {};
|
|
|
|
describe("WelcomeModal", () => {
|
|
it("shows 'Administrator' for role >= 50", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userRole={50} />
|
|
</QueryWrapper>,
|
|
);
|
|
await expect.element(screen.getByText("Administrator", { exact: true })).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows 'Editor' for role >= 40", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userRole={40} />
|
|
</QueryWrapper>,
|
|
);
|
|
await expect.element(screen.getByText("Editor")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows 'Author' for role >= 30", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userRole={30} />
|
|
</QueryWrapper>,
|
|
);
|
|
await expect.element(screen.getByText("Author")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows 'Contributor' for role >= 20", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userRole={20} />
|
|
</QueryWrapper>,
|
|
);
|
|
await expect.element(screen.getByText("Contributor")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows 'Subscriber' for role < 20", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userRole={10} />
|
|
</QueryWrapper>,
|
|
);
|
|
await expect.element(screen.getByText("Subscriber")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows first name from userName", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userName="Alice Smith" userRole={30} />
|
|
</QueryWrapper>,
|
|
);
|
|
await expect.element(screen.getByText(WELCOME_MESSAGE_REGEX)).toBeInTheDocument();
|
|
});
|
|
|
|
it("'Get Started' button triggers dismiss mutation and calls onClose", async () => {
|
|
const onClose = vi.fn();
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={onClose} userRole={30} />
|
|
</QueryWrapper>,
|
|
);
|
|
const button = screen.getByText("Get Started").element().closest("button")!;
|
|
button.click();
|
|
// The mutation resolves and calls onClose
|
|
await vi.waitFor(() => {
|
|
expect(onClose).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
it("admin text shown only for role >= 50", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userRole={50} />
|
|
</QueryWrapper>,
|
|
);
|
|
await expect.element(screen.getByText(ADMIN_TEXT_REGEX)).toBeInTheDocument();
|
|
});
|
|
|
|
it("admin text not shown for role < 50", async () => {
|
|
const screen = await render(
|
|
<QueryWrapper>
|
|
<WelcomeModal open={true} onClose={noop} userRole={40} />
|
|
</QueryWrapper>,
|
|
);
|
|
// Check that the admin invite text is NOT present
|
|
expect(screen.container.textContent).not.toContain(
|
|
"As an administrator, you can invite other users",
|
|
);
|
|
});
|
|
});
|