|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { |
| 3 | + buildClipboardPastePayload, |
| 4 | + copySelectedNotesToClipboard, |
| 5 | +} from "./pianoRollClipboard"; |
| 6 | + |
| 7 | +function clamp(value, min, max) { |
| 8 | + return Math.max(min, Math.min(max, value)); |
| 9 | +} |
| 10 | + |
| 11 | +function makeId(prefix) { |
| 12 | + makeId.count = (makeId.count || 0) + 1; |
| 13 | + return prefix + "-" + makeId.count; |
| 14 | +} |
| 15 | + |
| 16 | +describe("pianoRollClipboard", () => { |
| 17 | + it("keeps overlapping copied notes in paste payload", () => { |
| 18 | + copySelectedNotesToClipboard({ |
| 19 | + activePatternId: "pat-1", |
| 20 | + activeChannelId: "ch-1", |
| 21 | + defaultVelocity: 95, |
| 22 | + clampFn: clamp, |
| 23 | + selectedNotes: [ |
| 24 | + { start: 0, pitch: 60, length: 4, velocity: 100 }, |
| 25 | + { start: 0, pitch: 60, length: 1, velocity: 80 }, |
| 26 | + ], |
| 27 | + }); |
| 28 | + |
| 29 | + const { notesToAdd, nextSelection } = buildClipboardPastePayload({ |
| 30 | + activePatternId: "pat-1", |
| 31 | + activeChannelId: "ch-1", |
| 32 | + patternLength: 16, |
| 33 | + minFreeLength: 0.0625, |
| 34 | + pitchMin: 0, |
| 35 | + pitchMax: 127, |
| 36 | + defaultVelocity: 95, |
| 37 | + clampFn: clamp, |
| 38 | + makeIdFn: makeId, |
| 39 | + }); |
| 40 | + |
| 41 | + expect(notesToAdd).toHaveLength(2); |
| 42 | + expect(notesToAdd[0]).toMatchObject({ start: 1, pitch: 60, length: 4 }); |
| 43 | + expect(notesToAdd[1]).toMatchObject({ start: 1, pitch: 60, length: 1 }); |
| 44 | + expect(nextSelection).toHaveLength(2); |
| 45 | + }); |
| 46 | +}); |
0 commit comments