import { fireEvent, render } from "@solidjs/testing-library"; import * as Menubar from "."; const commonUI = () => ( <> Test 1 Item 1 Item 2 {"Sub 3 >"} Item 4 Item 5 Test 2 Item A Item B {"Sub C >"} Item D Item E Test 3 Item Z Item Y {"Sub X >"} Item W Item V External ); describe("Menubar", () => { it.skip("renders correctly", async () => { // Can't be tested as jsdom doesn't support onPointer events. // Test code should be valid for the future. const { getByText, queryByText } = render(commonUI); expect(getByText("Test 1")).toBeVisible(); expect(getByText("Test 2")).toBeVisible(); expect(getByText("Test 3")).toBeVisible(); getByText("Test 1").click(); expect(getByText("Test 1")).toHaveAttribute("data-highlighted", "true"); expect(getByText("Item 1")).toBeVisible(); expect(getByText("Item 2")).toBeVisible(); expect(getByText("Sub 3")).toBeVisible(); getByText("Test 2").click(); expect(getByText("Test 1")).not.toHaveAttribute("data-highlighted", "true"); expect(getByText("Test 2")).toHaveAttribute("data-highlighted", "true"); expect(queryByText("Item 1")).not.toBeInTheDocument(); expect(queryByText("Item 2")).not.toBeInTheDocument(); expect(queryByText("Sub 3")).not.toBeInTheDocument(); expect(getByText("Item A")).toBeVisible(); expect(getByText("Item B")).toBeVisible(); expect(getByText("Sub C")).toBeVisible(); fireEvent.click(getByText("Sub C")); expect(getByText("Item D")).toBeVisible(); expect(getByText("Item E")).toBeVisible(); fireEvent.click(getByText("External")); expect(getByText("Test 2")).not.toHaveAttribute("data-highlighted", "true"); expect(queryByText("Item A")).not.toBeInTheDocument(); expect(queryByText("Item B")).not.toBeInTheDocument(); expect(queryByText("Sub C")).not.toBeInTheDocument(); }); it.skip("handles keyboard navigation correctly", async () => { // Can't be tested as jsdom doesn't support onPointer events. // Test code should be valid for the future. const { getByText, queryByText } = render(commonUI); expect(getByText("Test 1")).toHaveAttribute("tabindex", "0"); expect(getByText("Test 2")).toHaveAttribute("tabindex", "-1"); expect(getByText("Test 3")).toHaveAttribute("tabindex", "-1"); expect(getByText("Test 1")).not.toHaveAttribute("data-highlighted", "true"); fireEvent.focus(getByText("Test 1")); expect(queryByText("Item 1")).not.toBeInTheDocument(); expect(getByText("Test 1")).toHaveAttribute("data-highlighted", "true"); fireEvent.keyPress(getByText("Test 1"), { key: "ArrowRight", code: "ArrowRight", }); expect(queryByText("Item A")).not.toBeInTheDocument(); expect(getByText("Test 1")).not.toHaveAttribute("data-highlighted", "true"); expect(getByText("Test 2")).toHaveAttribute("data-highlighted", "true"); expect(getByText("Test 1")).toHaveAttribute("tabindex", "-1"); expect(getByText("Test 2")).toHaveAttribute("tabindex", "0"); expect(getByText("Test 2")).toHaveFocus(); fireEvent.keyPress(getByText("Test 2"), { key: "ArrowRight", code: "ArrowRight", }); expect(queryByText("Item Z")).not.toBeInTheDocument(); expect(getByText("Test 2")).not.toHaveAttribute("data-highlighted", "true"); expect(getByText("Test 3")).toHaveAttribute("data-highlighted", "true"); expect(getByText("Test 2")).toHaveAttribute("tabindex", "-1"); expect(getByText("Test 3")).toHaveAttribute("tabindex", "0"); expect(getByText("Test 3")).toHaveFocus(); fireEvent.keyPress(getByText("Test 3"), { key: "ArrowRight", code: "ArrowRight", }); expect(getByText("Test 1")).toHaveFocus(); fireEvent.keyPress(getByText("Test 1"), { key: "ArrowDown", code: "ArrowDown", }); expect(getByText("Item 1")).toBeVisible(); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowRight", code: "ArrowRight", }); expect(getByText("Item A")).toBeVisible(); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowDown", code: "ArrowDown", }); expect(getByText("Item A")).toHaveFocus(); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowDown", code: "ArrowDown", }); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowDown", code: "ArrowDown", }); expect(getByText("Sub C")).toHaveFocus(); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowRight", code: "ArrowRight", }); expect(getByText("Item D")).toHaveFocus(); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowLeft", code: "ArrowLeft", }); expect(getByText("Sub C")).toHaveFocus(); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowRight", code: "ArrowRight", }); fireEvent.keyPress(document.activeElement as Element, { key: "ArrowRight", code: "ArrowRight", }); expect(getByText("Item Z")).toBeVisible(); }); it.skip("handles hover correctly", async () => { // Can't be tested as jsdom doesn't support onPointer events. // Test code should be valid for the future. const { getByText, queryByText } = render(commonUI); fireEvent.mouseEnter(getByText("Test 2")); expect(getByText("Test 1")).toHaveAttribute("tabindex", "0"); expect(queryByText("Item A")).not.toBeInTheDocument(); getByText("Test 1").click(); expect(getByText("Item 1")).toBeVisible(); getByText("Test 2").click(); expect(queryByText("Item 1")).not.toBeInTheDocument(); expect(getByText("Item A")).toBeVisible(); }); });