import * as React from "react"; import { render } from "../render"; import { focus } from "../focus"; import { useAllEvents } from "./useAllEvents"; test("focus", async () => { const stack = [] as any[]; const Test = () => { const ref1 = React.useRef(null); const ref2 = React.useRef(null); useAllEvents(ref1, stack); useAllEvents(ref2, stack); return ( <> ); }; const { getByText } = render(); const button1 = getByText("button1"); const button2 = getByText("button2"); focus(button1); expect(button1).toHaveFocus(); focus(button2); expect(button2).toHaveFocus(); expect(stack).toMatchInlineSnapshot(` Array [ "focus button1", "focusin button1", "blur button1", "focusout button1", "focus button2", "focusin button2", ] `); }); test("focus disabled", async () => { const stack = [] as any[]; const Test = () => { const ref = React.useRef(null); useAllEvents(ref, stack); return ( ); }; const { getByText } = render(); const button = getByText("button"); focus(button); expect(button).not.toHaveFocus(); expect(stack).toMatchInlineSnapshot(`Array []`); }); test("focus readOnly", async () => { const stack = [] as any[]; const Test = () => { const ref = React.useRef(null); useAllEvents(ref, stack); return ; }; const { getByLabelText } = render(); const input = getByLabelText("input"); focus(input); expect(input).toHaveFocus(); expect(stack).toMatchInlineSnapshot(` Array [ "focus input", "focusin input", ] `); });