Files
vue-tui/packages/runtime-tests/integration/focus/focus-manager.test.tsx
T
Yunfei He a7f7d9957d feat(runtime-tests): integration test suite
21 test files covering components, composables, focus, lifecycle,
and scheduler through the public render() API.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 18:13:53 +08:00

43 lines
1.1 KiB
TypeScript

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<typeof useFocusManager>["activeId"];
const Item = defineComponent({
props: { id: { type: String, required: true } },
setup(props) {
const { isFocused } = useFocus({ id: props.id, autoFocus: props.id === "a" });
return () => (
<Text>
{isFocused.value ? "▶ " : " "}
{props.id}
</Text>
);
},
});
const App = defineComponent(() => {
const manager = useFocusManager();
activeId = manager.activeId;
return () => (
<Box flexDirection="column">
<Item id="a" />
<Item id="b" />
</Box>
);
});
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");
});