import React from "react";
import { render } from "@testing-library/react-native";
import { AccessibilityInfo } from "react-native";
import { HelperText } from ".";
import { Icon } from "../../Icon";
describe("HelperText", () => {
describe("neutral status (default)", () => {
it("renders the message as subdued supporting text without an alert icon or role", () => {
const { getByText, queryByRole } = render(
,
);
expect(getByText("Pick a status")).toBeDefined();
expect(queryByRole("alert")).toBeNull();
});
it("renders identically when status is explicitly neutral", () => {
const { getByText, queryByRole } = render(
,
);
expect(getByText("Pick a status")).toBeDefined();
expect(queryByRole("alert")).toBeNull();
});
});
describe("critical status", () => {
it("renders the alert icon, error text, alert role, and assertive live region", () => {
const { getByText, getByRole, UNSAFE_getByType } = render(
,
);
expect(getByText("Pick a status before continuing")).toBeDefined();
const alertWrapper = getByRole("alert");
expect(alertWrapper.props.accessibilityLiveRegion).toBe("assertive");
// Confirms the alert icon is present alongside the message.
const icon = UNSAFE_getByType(Icon);
expect(icon.props.name).toBe("alert");
expect(icon.props.size).toBe("small");
expect(icon.props.color).toBe("critical");
});
});
describe("leaf invariants", () => {
it("does not fire imperative accessibility announcements", () => {
jest.spyOn(AccessibilityInfo, "announceForAccessibility");
render();
render();
expect(AccessibilityInfo.announceForAccessibility).not.toHaveBeenCalled();
jest.mocked(AccessibilityInfo.announceForAccessibility).mockRestore();
});
it("renders successfully outside of any Atlantis context", () => {
// Renders bare (no providers) and asserts no warning or throw.
const warn = jest.spyOn(console, "warn").mockImplementation(() => {
// swallow warnings; we'll inspect the spy below
});
const error = jest.spyOn(console, "error").mockImplementation(() => {
// swallow errors; we'll inspect the spy below
});
expect(() => render()).not.toThrow();
expect(warn).not.toHaveBeenCalled();
expect(error).not.toHaveBeenCalled();
warn.mockRestore();
error.mockRestore();
});
});
});