import { defineComponent } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text, useFocus, useFocusManager } from "@vue-tui/runtime"; test("useFocusManager().activeId tracks the currently focused component", async () => { let activeId!: ReturnType["activeId"]; const Item = defineComponent({ props: { id: { type: String, required: true } }, setup(props) { const { isFocused } = useFocus({ id: props.id, autoFocus: props.id === "a" }); return () => ( {isFocused.value ? "▶ " : " "} {props.id} ); }, }); const App = defineComponent(() => { const manager = useFocusManager(); activeId = manager.activeId; return () => ( ); }); const { stdin } = await render(App); expect(activeId.value).toBe("a"); await stdin.write("\t"); expect(activeId.value).toBe("b"); await stdin.write("\t"); expect(activeId.value).toBe("a"); });