import { describe, expect, it } from 'vitest'; import { gapAt, maxScroll, moveTarget, STRIP_PAD, TILE, TILE_GAP, tileIndexAt, } from '../../src/editor/animation/strip'; const STEP = TILE + TILE_GAP; describe('the frame strip', () => { it('finds the tile under the pointer, and none in the gaps or past the last', () => { const at = (x: number) => tileIndexAt(x, 3, 0); expect([at(STRIP_PAD), at(STRIP_PAD + TILE), at(STRIP_PAD + STEP + 1)]).toEqual([0, 0, 1]); expect([at(STRIP_PAD - 1), at(STRIP_PAD + TILE + 2), at(STRIP_PAD + 3 * STEP + 1)]).toEqual([-1, -1, -1]); expect(tileIndexAt(STRIP_PAD + 1, 3, STEP)).toBe(1); }); it('drops into the gap nearest to the pointer', () => { const gap = (x: number) => gapAt(x, 3, 0); expect([gap(0), gap(STRIP_PAD + TILE / 2 - 1), gap(STRIP_PAD + TILE / 2 + 1), gap(9999)]).toEqual([ 0, 0, 1, 3, ]); }); it('turns a gap into the index the frame ends up at, and a drop beside itself into nothing', () => { expect([moveTarget(0, 0), moveTarget(0, 1)]).toEqual([null, null]); expect([moveTarget(0, 3), moveTarget(2, 0), moveTarget(1, 3)]).toEqual([2, 0, 2]); }); it('scrolls only as far as the last tile needs', () => { expect(maxScroll(2, 500)).toBe(0); expect(maxScroll(10, 300)).toBe(STRIP_PAD * 2 + 10 * TILE + 9 * TILE_GAP - 300); }); });