mirror of
https://github.com/MeshCore-Beacon/beacon-web.git
synced 2026-09-02 09:03:44 +00:00
- footer read 'v0.1' forever; it's injected from package.json at build time now - region picker shows 'Failed to load' instead of an eternal Loading when /iatas errors - selecting text in a modal and releasing over the backdrop no longer closes it (close requires the press to start on the backdrop) - Escape in a dropdown inside the mobile filter sheet closes just the dropdown, not the whole sheet - Shift+Tab right after a modal opens wraps to the last control instead of escaping the focus trap - formatCount rolls 999,999 over to 1M instead of printing 1000k - TABS list moved to lib/constants so AppShell only exports components
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { AppShell } from "../../src/components/AppShell";
|
|
import { RegionProvider } from "../../src/hooks/useRegion";
|
|
import { ALL_REGIONS } from "../../src/hooks/region-selection";
|
|
import { getIatas, getRegions } from "../../src/api/client";
|
|
import type { WsManager } from "../../src/api/ws-manager";
|
|
import pkg from "../../package.json";
|
|
|
|
vi.mock("../../src/api/client", () => ({
|
|
getIatas: vi.fn(),
|
|
getRegions: vi.fn(),
|
|
getRegion: vi.fn(),
|
|
}));
|
|
|
|
const wsManager = {
|
|
onStatusChange: () => () => {},
|
|
getStatus: () => "connected",
|
|
getLastEventTimestamp: () => Date.now(),
|
|
} as unknown as WsManager;
|
|
|
|
function renderShell() {
|
|
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
return render(
|
|
<QueryClientProvider client={client}>
|
|
<RegionProvider defaultSelection={ALL_REGIONS}>
|
|
<AppShell activeTab="Packets" onTabChange={() => {}} wsManager={wsManager}>
|
|
<div />
|
|
</AppShell>
|
|
</RegionProvider>
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.mocked(getIatas).mockReset();
|
|
vi.mocked(getRegions).mockReset().mockResolvedValue([]);
|
|
});
|
|
|
|
describe("AppShell", () => {
|
|
it("footer shows the package.json version", () => {
|
|
vi.mocked(getIatas).mockResolvedValue([]);
|
|
renderShell();
|
|
expect(screen.getByText(`BEACON v${pkg.version}`)).toBeInTheDocument();
|
|
});
|
|
|
|
it("region picker shows an error state when the IATA list fails to load", async () => {
|
|
vi.mocked(getIatas).mockRejectedValue(new Error("boom"));
|
|
renderShell();
|
|
fireEvent.click(screen.getByRole("button", { name: /REGION/ }));
|
|
|
|
await waitFor(() => expect(screen.getByText("Failed to load")).toBeInTheDocument());
|
|
expect(screen.queryByText("Loading…")).not.toBeInTheDocument();
|
|
});
|
|
});
|