2026-05-25 23:28:06 +08:00
|
|
|
import { defineComponent, shallowRef } from "vue";
|
2026-05-24 18:13:53 +08:00
|
|
|
import { expect, test } from "vite-plus/test";
|
|
|
|
|
import { render } from "@vue-tui/testing";
|
|
|
|
|
import { Box, Text, useInput } from "@vue-tui/runtime";
|
|
|
|
|
|
|
|
|
|
test("counter responds to + and - keys", async () => {
|
|
|
|
|
const Counter = defineComponent(() => {
|
2026-05-25 23:28:06 +08:00
|
|
|
const count = shallowRef(0);
|
2026-05-24 18:13:53 +08:00
|
|
|
useInput((input) => {
|
|
|
|
|
if (input === "+") count.value++;
|
|
|
|
|
if (input === "-") count.value--;
|
|
|
|
|
});
|
|
|
|
|
return () => (
|
|
|
|
|
<Box>
|
|
|
|
|
<Text>Count: {count.value}</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { lastFrame, stdin } = await render(Counter);
|
|
|
|
|
expect(lastFrame()).toContain("Count: 0");
|
|
|
|
|
|
|
|
|
|
await stdin.write("+");
|
|
|
|
|
expect(lastFrame()).toContain("Count: 1");
|
|
|
|
|
|
|
|
|
|
await stdin.write("+");
|
|
|
|
|
await stdin.write("+");
|
|
|
|
|
expect(lastFrame()).toContain("Count: 3");
|
|
|
|
|
|
|
|
|
|
await stdin.write("-");
|
|
|
|
|
expect(lastFrame()).toContain("Count: 2");
|
|
|
|
|
});
|