From 89983e47e42847f34fbfe7aa83097d209ac8c0ba Mon Sep 17 00:00:00 2001 From: Xiaohan-Tian <157918347+Xiaohan-Tian@users.noreply.github.com> Date: Tue, 7 Jul 2026 17:24:24 -0700 Subject: [PATCH] fix: failed test cases --- src/core/commands/note/CreateNoteCommand.ts | 9 ++++++++- src/hooks/useNoteOperations.test.ts | 12 ++++++------ src/stores/projectStore.test.ts | 5 +++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/core/commands/note/CreateNoteCommand.ts b/src/core/commands/note/CreateNoteCommand.ts index bb3a1e8..f8b29ce 100644 --- a/src/core/commands/note/CreateNoteCommand.ts +++ b/src/core/commands/note/CreateNoteCommand.ts @@ -130,6 +130,13 @@ export class CreateNoteCommand extends KGCommand { return this.regionId; } + /** + * Get the velocity that will be used for the created note. + */ + public getVelocity(): number { + return this.velocity; + } + /** * Factory method to create a note command from UI coordinates */ @@ -170,4 +177,4 @@ export class CreateNoteCommand extends KGCommand { velocity ); } -} \ No newline at end of file +} diff --git a/src/hooks/useNoteOperations.test.ts b/src/hooks/useNoteOperations.test.ts index dcc9c15..2b17dd9 100644 --- a/src/hooks/useNoteOperations.test.ts +++ b/src/hooks/useNoteOperations.test.ts @@ -173,9 +173,9 @@ describe('useNoteOperations', () => { }); expect(coreState.executeCommand).toHaveBeenCalledTimes(1); - const createCommand = coreState.executeCommand.mock.calls[0][0] as CreateNoteCommand & { velocity: number }; + const createCommand = coreState.executeCommand.mock.calls[0][0] as CreateNoteCommand; expect(createCommand).toBeInstanceOf(CreateNoteCommand); - expect(createCommand.velocity).toBe(91); + expect(createCommand.getVelocity()).toBe(91); }); it('uses the most recently selected note velocity after deselecting a multi-selection', () => { @@ -201,9 +201,9 @@ describe('useNoteOperations', () => { }); expect(coreState.executeCommand).toHaveBeenCalledTimes(1); - const createCommand = coreState.executeCommand.mock.calls[0][0] as CreateNoteCommand & { velocity: number }; + const createCommand = coreState.executeCommand.mock.calls[0][0] as CreateNoteCommand; expect(createCommand).toBeInstanceOf(CreateNoteCommand); - expect(createCommand.velocity).toBe(105); + expect(createCommand.getVelocity()).toBe(105); }); it('falls back to velocity 127 when creating a manual note with no selection', () => { @@ -220,9 +220,9 @@ describe('useNoteOperations', () => { }); expect(coreState.executeCommand).toHaveBeenCalledTimes(1); - const createCommand = coreState.executeCommand.mock.calls[0][0] as CreateNoteCommand & { velocity: number }; + const createCommand = coreState.executeCommand.mock.calls[0][0] as CreateNoteCommand; expect(createCommand).toBeInstanceOf(CreateNoteCommand); - expect(createCommand.velocity).toBe(127); + expect(createCommand.getVelocity()).toBe(127); }); it('applies the cached velocity to every note in manual chord creation after deselecting', () => { diff --git a/src/stores/projectStore.test.ts b/src/stores/projectStore.test.ts index c389d82..2b7c547 100644 --- a/src/stores/projectStore.test.ts +++ b/src/stores/projectStore.test.ts @@ -59,6 +59,10 @@ const mockProject = { setShowGlobalTracks: vi.fn((value: boolean) => { mockShowGlobalTracks = value; }), + getPlayheadPosition: () => mockPlayheadPosition, + setPlayheadPosition: vi.fn((position: number) => { + mockPlayheadPosition = position; + }), getLoopingRange: () => [0, 0] as [number, number], getPianoRollZoom: () => 1, }; @@ -224,6 +228,7 @@ describe('projectStore piano roll state', () => { mockShowGlobalTracks = false; mockProject.setIsMetronomeEnabled.mockClear(); mockProject.setShowGlobalTracks.mockClear(); + mockProject.setPlayheadPosition.mockClear(); configValues.set('audio.input_device_id', 'default'); });