Files
beacon-web/tests/components/ModalOverlay.test.tsx
T
MrAlders0n 39641b6339 ui: footer version from package.json plus a batch of interaction fixes
- 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
2026-06-10 07:03:16 -04:00

42 lines
1.5 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { ModalOverlay } from "../../src/components/ModalOverlay";
function renderOverlay(onClose: () => void) {
render(
<ModalOverlay label="Test panel" onClose={onClose}>
<p data-testid="panel-text">selectable panel text</p>
</ModalOverlay>,
);
return screen.getByRole("dialog", { name: "Test panel" });
}
describe("ModalOverlay", () => {
it("closes when a click starts and ends on the backdrop", () => {
const onClose = vi.fn();
const backdrop = renderOverlay(onClose);
fireEvent.mouseDown(backdrop);
fireEvent.click(backdrop);
expect(onClose).toHaveBeenCalledTimes(1);
});
it("stays open when a drag starts inside the panel and releases over the backdrop", () => {
// regression: selecting text in the panel and releasing over the backdrop fired a click on the
// backdrop (the common ancestor) and closed the modal
const onClose = vi.fn();
const backdrop = renderOverlay(onClose);
fireEvent.mouseDown(screen.getByTestId("panel-text"));
fireEvent.click(backdrop);
expect(onClose).not.toHaveBeenCalled();
});
it("does not close on clicks inside the panel", () => {
const onClose = vi.fn();
renderOverlay(onClose);
const text = screen.getByTestId("panel-text");
fireEvent.mouseDown(text);
fireEvent.click(text);
expect(onClose).not.toHaveBeenCalled();
});
});