Files
hyperframes/packages/studio/src/player/components/timelineTrackDisplay.test.ts
T
Miguel Angel Simon Sierra ba0d6406d2 fix(studio): scope lane ids per timeline and stop inventing a track row
Two latent defects in the announcement path this branch adds.

- lanesId was keyed by render row alone, so a second TimelineLanes on the
  page (a mini-timeline beside the main one) would mint the same
  timeline-lanes-track-0 and every caret's aria-controls would resolve to
  whichever instance mounted first. The prefix now comes from useId, with the
  colons stripped so the id stays a legal CSS selector.
- trackDisplayNumber returned trackOrder.length + 1 for a key it could not
  find, which is indistinguishable from a real row: the label announced a row
  the user can see is wrong and nothing upstream could tell it had guessed. It
  returns null now, and trackDisplaySuffix drops the number from the label
  rather than inventing one.
2026-07-28 21:21:27 +02:00

36 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { timelineTrackOrder, trackDisplayNumber, trackDisplaySuffix } from "./timelineTrackDisplay";
describe("timelineTrackOrder", () => {
it("is the ascending distinct key order, fractional sub-comp keys included", () => {
const elements = [{ track: 1 }, { track: 0 }, { track: 1 / 6 }, { track: 1 }];
expect(timelineTrackOrder(elements)).toEqual([0, 1 / 6, 1]);
});
});
describe("trackDisplayNumber", () => {
it("is the key's 1-based row, not the fractional key itself", () => {
const order = timelineTrackOrder([{ track: 0 }, { track: 1 / 6 }, { track: 1 }]);
expect(trackDisplayNumber(order, 1 / 6)).toBe(2);
expect(trackDisplayNumber(order, 1)).toBe(3);
});
it("is null for a key with no row rather than a plausible-looking one", () => {
// The old end-row fallback announced "track 4" for a track the user cannot
// see at row 4, and nothing upstream could tell that apart from a real row.
expect(trackDisplayNumber([0, 1, 2], 7)).toBeNull();
});
});
describe("trackDisplaySuffix", () => {
it("names the row when there is one", () => {
expect(`Hide track${trackDisplaySuffix(3)}`).toBe("Hide track 3");
});
it("drops the number entirely when there is no row", () => {
expect(`Hide track${trackDisplaySuffix(null)}`).toBe("Hide track");
});
});