import { describe, expect, it } from 'vitest'; import { heldSongMarkers } from '../../src/core/music/markers'; import { MARKER_FLAG, MARKER_REACH, MARKER_STRIP, markerAt, markerNameX, markerSpans, SONG_TOP, } from '../../src/editor/song/markerView'; import { RULER_HEIGHT } from '../../src/editor/music/timeView'; /** A tick a pixel, from x 100; every name 6 pixels a letter. */ const VIEW = { panX: 100, pxPerTick: 1 }; const measure = (name: string) => name.length * 6; describe('the marker strip of the song tab (#338)', () => { it('lies between the ruler and the tracks', () => { expect(SONG_TOP).toBe(RULER_HEIGHT + MARKER_STRIP); }); it('draws a marker at its tick, as wide as its flag and name, but not into the next one', () => { const markers = heldSongMarkers([ { id: 'a', name: 'Intro', tick: 0 }, { id: 'b', name: 'A long name', tick: 40 }, { id: 'c', name: '', tick: 300 }, ]); const spans = markerSpans(VIEW, markers, measure); expect(spans.map((s) => s.x)).toEqual([100, 140, 400]); // Room to the next one is 40 pixels, less 2: the name of "Intro" (30) and the flag fit just so. expect(spans[0]!.w).toBe(38); expect(spans[1]!.w).toBe(MARKER_FLAG + 3 + measure('A long name')); expect(spans[2]!.w).toBe(MARKER_FLAG + 3 + measure('Marker 3')); expect(markerNameX(spans[0]!)).toBe(100 + MARKER_FLAG + 3); }); it('keeps the flag of a marker with another one close behind it', () => { const markers = heldSongMarkers([ { id: 'a', name: 'Close', tick: 0 }, { id: 'b', name: 'By', tick: 2 }, ]); expect(markerSpans(VIEW, markers, measure)[0]!.w).toBe(MARKER_FLAG); }); it('takes the marker near its line or on its flag and name, the later one where they overlap', () => { const markers = heldSongMarkers([ { id: 'a', name: 'Intro', tick: 0 }, { id: 'b', name: 'B', tick: 6 }, ]); const spans = markerSpans(VIEW, markers, measure); expect(markerAt(spans, 100 - MARKER_REACH)).toBe('a'); expect(markerAt(spans, 100 - MARKER_REACH - 1)).toBeNull(); expect(markerAt(spans, 103)).toBe('b'); expect(markerAt(spans, 106 + MARKER_FLAG + 3 + 6)).toBe('b'); expect(markerAt(spans, 106 + MARKER_FLAG + 3 + 7)).toBeNull(); expect(markerAt([], 100)).toBeNull(); }); });