|
1 | 1 | // @vitest-environment happy-dom |
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { dispatchModifierKey, dispatchPlainKey, type HotkeyCallbacks } from "./appHotkeysDispatch"; |
4 | | -import { usePlayerStore } from "../player/store/playerStore"; |
| 4 | +import { liveTime, usePlayerStore } from "../player/store/playerStore"; |
5 | 5 | import type { DomEditSelection } from "../components/editor/domEditing"; |
6 | 6 | import { clearAutomationClipboard, copyRange } from "../player/components/automationClipboard"; |
7 | 7 | import { VOLUME_RANGE } from "@hyperframes/core/audio-automation"; |
@@ -60,6 +60,63 @@ afterEach(() => { |
60 | 60 | }); |
61 | 61 | }); |
62 | 62 |
|
| 63 | +describe("dispatchPlainKey — select leftward / rightward", () => { |
| 64 | + const clips = [ |
| 65 | + { ...bgmElement, id: "early", key: "early", start: 0, track: 0 }, |
| 66 | + { ...bgmElement, id: "at", key: "at", start: 4, track: 1 }, |
| 67 | + { ...bgmElement, id: "late", key: "late", start: 7, track: 2 }, |
| 68 | + ]; |
| 69 | + beforeEach(() => usePlayerStore.setState({ elements: clips, currentTime: 4 })); |
| 70 | + |
| 71 | + it("[ selects every clip starting before the playhead, on every track", () => { |
| 72 | + const event = press("["); |
| 73 | + dispatchPlainKey(event, "[", callbacks()); |
| 74 | + expect([...usePlayerStore.getState().selectedElementIds]).toEqual(["early"]); |
| 75 | + expect(usePlayerStore.getState().selectedElementId).toBe("early"); |
| 76 | + expect(event.defaultPrevented).toBe(true); |
| 77 | + }); |
| 78 | + |
| 79 | + it("uses the live playhead while playing, not the time stored at play start", () => { |
| 80 | + usePlayerStore.setState({ isPlaying: true, currentTime: 0 }); |
| 81 | + liveTime.notify(8); |
| 82 | + try { |
| 83 | + dispatchPlainKey(press("["), "[", callbacks()); |
| 84 | + expect([...usePlayerStore.getState().selectedElementIds].sort()).toEqual([ |
| 85 | + "at", |
| 86 | + "early", |
| 87 | + "late", |
| 88 | + ]); |
| 89 | + } finally { |
| 90 | + usePlayerStore.setState({ isPlaying: false }); |
| 91 | + liveTime.notify(0); |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + it("clears a clicked keyframe like any other selection change", () => { |
| 96 | + usePlayerStore.setState({ activeKeyframePct: 50 }); |
| 97 | + dispatchPlainKey(press("]"), "]", callbacks()); |
| 98 | + expect(usePlayerStore.getState().activeKeyframePct).toBeNull(); |
| 99 | + }); |
| 100 | + |
| 101 | + it("] selects every clip starting at or after the playhead, on every track", () => { |
| 102 | + dispatchPlainKey(press("]"), "]", callbacks()); |
| 103 | + const { selectedElementIds, selectedElementId } = usePlayerStore.getState(); |
| 104 | + expect([...selectedElementIds].sort()).toEqual(["at", "late"]); |
| 105 | + expect(selectedElementId).toBe("at"); |
| 106 | + }); |
| 107 | + |
| 108 | + it("selects nothing when no clip is on that side", () => { |
| 109 | + usePlayerStore.setState({ |
| 110 | + currentTime: 0, |
| 111 | + selectedElementId: "late", |
| 112 | + selectedElementIds: new Set(["late"]), |
| 113 | + }); |
| 114 | + dispatchPlainKey(press("["), "[", callbacks()); |
| 115 | + expect(usePlayerStore.getState().selectedElementIds.size).toBe(0); |
| 116 | + expect(usePlayerStore.getState().selectedElementId).toBeNull(); |
| 117 | + }); |
| 118 | +}); |
| 119 | + |
63 | 120 | describe("dispatchPlainKey — Delete arbitration", () => { |
64 | 121 | const selectBgm = () => |
65 | 122 | usePlayerStore.setState({ elements: [bgmElement], selectedElementId: "bgm" }); |
|
0 commit comments