Files
romm/frontend/test/withInputModality.test.ts
Georges-Antoine Assi 90693fab59 fix(storybook): address code-review findings on the input toolbar
code-review (xhigh) pass:
- lazy-load useGamepad so vitest.setup.ts no longer caches it ahead of
  useGamepad/index.test.ts's vue-router mock (5 failures in the full suite)
- drop flush: "sync" on the re-pin watcher, which ran between setModality's
  ref write and DOM write and let a listener's data-input win
- stop the re-pin watcher on HMR
- test that a pin survives the live listeners, and assert data-input in play()

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 21:15:13 -04:00

29 lines
1006 B
TypeScript

import type { StoryContext } from "@storybook/vue3-vite";
import { mount } from "@vue/test-utils";
import { expect, it, vi } from "vitest";
import { defineComponent, nextTick, reactive } from "vue";
it("keeps a pinned mode once the live listeners are installed", async () => {
// vitest.setup.ts already loaded the decorator, so load a fresh copy with
// its own modality singleton.
vi.resetModules();
const { useInputModality } =
await import("@/v2/composables/useInputModality");
const { withInputModality } = await import("../.storybook/withInputModality");
useInputModality().install();
const globals = reactive({ input: "key" });
const story = defineComponent({ render: () => null });
mount(
withInputModality(
story as unknown as Parameters<typeof withInputModality>[0],
{ globals } as unknown as StoryContext,
),
);
window.dispatchEvent(new Event("touchstart"));
await nextTick();
expect(document.documentElement.dataset.input).toBe("key");
});