availability-dashboard-ui.test.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @vitest-environment happy-dom
  3. */
  4. import type { ReactNode } from "react";
  5. import { act } from "react";
  6. import { createRoot } from "react-dom/client";
  7. import { NextIntlClientProvider } from "next-intl";
  8. import { describe, expect, test, vi } from "vitest";
  9. import { AvailabilityDashboard } from "@/app/[locale]/dashboard/availability/_components/availability-dashboard";
  10. vi.mock("@/app/[locale]/dashboard/availability/_components/overview/overview-section", () => ({
  11. OverviewSection: () => <div data-testid="overview-section" />,
  12. }));
  13. vi.mock("@/app/[locale]/dashboard/availability/_components/provider/provider-tab", () => ({
  14. ProviderTab: () => <div data-testid="provider-tab" />,
  15. }));
  16. vi.mock("@/app/[locale]/dashboard/availability/_components/endpoint/endpoint-tab", () => ({
  17. EndpointTab: () => <div data-testid="endpoint-tab" />,
  18. }));
  19. function renderWithIntl(node: ReactNode) {
  20. const container = document.createElement("div");
  21. document.body.appendChild(container);
  22. const root = createRoot(container);
  23. act(() => {
  24. root.render(
  25. <NextIntlClientProvider
  26. locale="en"
  27. timeZone="UTC"
  28. messages={{
  29. dashboard: {
  30. availability: {
  31. tabs: { provider: "Provider", endpoint: "Endpoint" },
  32. states: { fetchFailed: "Fetch failed" },
  33. actions: {
  34. probeAll: "Probe All",
  35. probing: "Probing",
  36. probeSuccess: "Probe success",
  37. probeFailed: "Probe failed",
  38. },
  39. },
  40. },
  41. }}
  42. >
  43. {node}
  44. </NextIntlClientProvider>
  45. );
  46. });
  47. return {
  48. container,
  49. unmount: () => {
  50. act(() => root.unmount());
  51. container.remove();
  52. },
  53. };
  54. }
  55. describe("AvailabilityDashboard UI", () => {
  56. test("does not render Probe All floating button", async () => {
  57. vi.stubGlobal(
  58. "fetch",
  59. vi.fn(async () => ({
  60. ok: true,
  61. json: async () => ({ providers: [], systemAvailability: 0 }),
  62. }))
  63. );
  64. const { container, unmount } = renderWithIntl(<AvailabilityDashboard />);
  65. expect(container.textContent).not.toContain("Probe All");
  66. unmount();
  67. });
  68. });