Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function buildTrackYPositions(tracks: readonly TrackState[]): number[] {
positions.push(y);
y += getTrackHeight(track.primaryAssetType);
}
positions.push(y); // sentinel: total height for "insert after last track"
return positions;
}

Expand Down
19 changes: 12 additions & 7 deletions tests/interaction-calculations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ describe("formatDragTime", () => {

describe("Track Y Position Calculations", () => {
describe("buildTrackYPositions", () => {
it("returns empty array for no tracks", () => {
expect(buildTrackYPositions([])).toEqual([]);
it("returns sentinel-only array for no tracks", () => {
expect(buildTrackYPositions([])).toEqual([0]);
});

it("calculates positions for image tracks (72px height)", () => {
const tracks: TrackState[] = [createMockTrack([createMockClip(0, 1)], "image"), createMockTrack([createMockClip(0, 1, "image", 1)], "image")];
expect(buildTrackYPositions(tracks)).toEqual([0, 72]);
expect(buildTrackYPositions(tracks)).toEqual([0, 72, 144]);
});

it("calculates positions for audio tracks (48px height)", () => {
const tracks: TrackState[] = [
createMockTrack([createMockClip(0, 1, "audio")], "audio"),
createMockTrack([createMockClip(0, 1, "audio", 1)], "audio")
];
expect(buildTrackYPositions(tracks)).toEqual([0, 48]);
expect(buildTrackYPositions(tracks)).toEqual([0, 48, 96]);
});

it("handles mixed track types", () => {
Expand All @@ -141,20 +141,25 @@ describe("Track Y Position Calculations", () => {
createMockTrack([createMockClip(0, 1, "audio", 1)], "audio") // 48px
];
const positions = buildTrackYPositions(tracks);
expect(positions).toEqual([0, 72]); // Second track starts at 72
expect(positions).toEqual([0, 72, 120]); // Sentinel at 72 + 48 = 120
});
});

describe("getTrackYPosition", () => {
it("returns correct position from cache", () => {
const cache = [0, 60, 120];
const cache = [0, 60, 120, 180]; // includes sentinel
expect(getTrackYPosition(0, cache)).toBe(0);
expect(getTrackYPosition(1, cache)).toBe(60);
expect(getTrackYPosition(2, cache)).toBe(120);
});

it("returns sentinel position for insert-after-last index", () => {
const cache = [0, 60, 120]; // 2 tracks + sentinel at 120
expect(getTrackYPosition(2, cache)).toBe(120);
});

it("returns 0 for out of bounds index", () => {
const cache = [0, 60];
const cache = [0, 60, 120]; // 2 tracks + sentinel
expect(getTrackYPosition(5, cache)).toBe(0);
});
});
Expand Down
Loading