72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
// Guards the contract the Mitarbeiter tab relies on after the invite moved from
|
|
// its own sub-page into a popup: the dialog reports trimmed field values through
|
|
// onInvite (the route turns those into the unchanged members/new form fields),
|
|
// and the plan seat limit still blocks the submit the way CheckPlanFeatureLimit
|
|
// did on the sub-page.
|
|
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import "@testing-library/jest-dom/vitest";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import type { PlanFeatureUsageDto } from "~/application/dtos/subscriptions/PlanFeatureUsageDto";
|
|
import { InviteMemberDialog, type InviteMemberInput } from "./InviteMemberDialog";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }),
|
|
}));
|
|
|
|
function renderDialog(featurePlanUsage?: PlanFeatureUsageDto) {
|
|
const onInvite = vi.fn<(input: InviteMemberInput) => void>();
|
|
render(
|
|
<InviteMemberDialog
|
|
open
|
|
onOpenChange={() => undefined}
|
|
featurePlanUsage={featurePlanUsage}
|
|
submitting={false}
|
|
errorMessage={null}
|
|
onInvite={onInvite}
|
|
/>
|
|
);
|
|
return { onInvite };
|
|
}
|
|
|
|
function submitButton(): HTMLButtonElement {
|
|
return document.querySelector("[data-ui-id='ui.settings.members.new.submit']") as HTMLButtonElement;
|
|
}
|
|
|
|
function fill(labelKey: string, value: string) {
|
|
fireEvent.change(screen.getByLabelText(labelKey), { target: { value } });
|
|
}
|
|
|
|
describe("InviteMemberDialog", () => {
|
|
it("reports the trimmed invite fields", () => {
|
|
const { onInvite } = renderDialog();
|
|
fill("models.user.email", " neu@hivegrid.de ");
|
|
fill("models.user.firstName", " Nina ");
|
|
fill("models.user.lastName", " Neu ");
|
|
fireEvent.click(submitButton());
|
|
|
|
expect(onInvite).toHaveBeenCalledWith({
|
|
email: "neu@hivegrid.de",
|
|
firstName: "Nina",
|
|
lastName: "Neu",
|
|
sendInvitationEmail: false,
|
|
});
|
|
});
|
|
|
|
it("keeps the submit disabled until e-mail and first name are set", () => {
|
|
renderDialog();
|
|
expect(submitButton()).toBeDisabled();
|
|
fill("models.user.email", "neu@hivegrid.de");
|
|
expect(submitButton()).toBeDisabled();
|
|
fill("models.user.firstName", "Nina");
|
|
expect(submitButton()).not.toBeDisabled();
|
|
});
|
|
|
|
it("blocks the invite when the plan has no seat left", () => {
|
|
renderDialog({ name: "users", message: "shared.planLimitReached", enabled: false } as PlanFeatureUsageDto);
|
|
fill("models.user.email", "neu@hivegrid.de");
|
|
fill("models.user.firstName", "Nina");
|
|
expect(submitButton()).toBeDisabled();
|
|
});
|
|
});
|