1
mirror of https://github.com/jakejarvis/hoot.git synced 2025-10-18 20:14:25 -04:00
Files
hoot/components/domain/sections/dns-records-section.test.tsx

75 lines
1.9 KiB
TypeScript

/* @vitest-environment jsdom */
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { DnsRecordsSection } from "./dns-records-section";
vi.mock("@/components/domain/dns-group", () => ({
DnsGroup: ({
title,
count,
children,
}: {
title: string;
count: number;
children: React.ReactNode;
}) => (
<div>
<div>{title}</div>
<div>count:{count}</div>
{children}
</div>
),
}));
vi.mock("@/components/domain/dns-record-list", () => ({
DnsRecordList: ({ type }: { type: string }) => <div>list:{type}</div>,
}));
describe("DnsRecordsSection", () => {
it("renders groups for each type and passes counts", () => {
const records = [
{ type: "A", name: "a", value: "1.2.3.4" },
{ type: "AAAA", name: "aaaa", value: "::1" },
{ type: "MX", name: "mx", value: "mx.example.com", priority: 10 },
{ type: "TXT", name: "txt", value: "v=spf1" },
{ type: "NS", name: "ns", value: "ns1.example.com" },
] as unknown as import("@/lib/schemas").DnsRecord[];
render(
<DnsRecordsSection
records={records}
isLoading={false}
isError={false}
onRetryAction={() => {}}
/>,
);
expect(screen.getByText("A Records")).toBeInTheDocument();
const counts = screen.getAllByText("count:1");
expect(counts.length).toBe(5);
expect(screen.getByText("MX Records")).toBeInTheDocument();
});
it("shows error and loading states", () => {
render(
<DnsRecordsSection
records={null}
isLoading={false}
isError
onRetryAction={() => {}}
/>,
);
expect(screen.getByText(/Failed to load DNS/i)).toBeInTheDocument();
render(
<DnsRecordsSection
records={null}
isLoading
isError={false}
onRetryAction={() => {}}
/>,
);
expect(screen.getAllByText("DNS Records").length).toBeGreaterThan(0);
});
});