31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
import "@testing-library/jest-dom/vitest";
|
|
import { render } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import Captcha from "./Captcha";
|
|
|
|
describe("Captcha CAP status contract", () => {
|
|
it("reports solve, reset and client errors to the enclosing form", () => {
|
|
const onStatusChange = vi.fn();
|
|
const { container } = render(
|
|
<Captcha enabled provider="cap" instanceUrl="https://captcha.example.test" sitekey="registration" onStatusChange={onStatusChange} />
|
|
);
|
|
const widget = container.querySelector("cap-widget");
|
|
|
|
expect(widget).not.toBeNull();
|
|
expect(onStatusChange).toHaveBeenLastCalledWith("pending");
|
|
widget!.dispatchEvent(new CustomEvent("solve"));
|
|
expect(onStatusChange).toHaveBeenLastCalledWith("solved");
|
|
widget!.dispatchEvent(new CustomEvent("reset"));
|
|
expect(onStatusChange).toHaveBeenLastCalledWith("pending");
|
|
widget!.dispatchEvent(new CustomEvent("error"));
|
|
expect(onStatusChange).toHaveBeenLastCalledWith("error");
|
|
});
|
|
|
|
it("renders nothing when the public provider configuration is incomplete", () => {
|
|
const { container } = render(<Captcha enabled provider="cap" />);
|
|
expect(container).toBeEmptyDOMElement();
|
|
});
|
|
});
|