import { describe, expect, it } from 'vitest'; import { GroupObjectsCommand } from '../../src/core/commands/groupCommands'; import { groupRowId, hierarchyRows } from '../../src/core/model/hierarchy'; import { hierarchyRange } from '../../src/editor/panels/hierarchyRange'; import { makeSpriteScene, place } from '../helpers'; /** Top-level a, b, c, d, e with k under a; b and d form the group "Crates": a [b d] c e. */ function grouped() { const f = makeSpriteScene(); const [a, b, c, d, e] = [0, 1, 2, 3, 4].map((i) => place(f, f.spriteId, { x: i * 10, y: 0 })); const k = place(f, f.spriteId, { x: 0, y: 10 }, a); const group = new GroupObjectsCommand(f.sceneId, [b!, d!], 'Crates'); f.stack.execute(group); const row = groupRowId(group.groupId); const names: Record = { [a!]: 'a', [b!]: 'b', [c!]: 'c', [d!]: 'd', [e!]: 'e', [k]: 'k' }; /** The row ids the panel shows with these rows unfolded. */ const rows = (open: string[]) => hierarchyRows(f.sceneOf(), new Set(open)).map((r) => r.kind === 'group' ? groupRowId(r.group.id) : r.object.id, ); const range = (open: string[], anchor: string, clicked: string) => hierarchyRange(f.sceneOf(), rows(open), anchor, clicked) .map((id) => names[id] ?? '?') .sort() .join(' '); return { a: a!, b: b!, c: c!, d: d!, e: e!, k, row, range }; } describe('Shift-click range in the hierarchy', () => { it('takes every shown row between anchor and click, in either direction', () => { const f = grouped(); expect(f.range([f.a, f.row], f.a, f.c)).toBe('a b c d k'); expect(f.range([f.a, f.row], f.c, f.a)).toBe('a b c d k'); expect(f.range([f.a, f.row], f.b, f.b)).toBe('b'); }); it('brings in all members of a folded group, but no children folded under a parent', () => { const f = grouped(); expect(f.range([], f.a, f.c)).toBe('a b c d'); }); it('starts inside an open group and runs out of it', () => { const f = grouped(); expect(f.range([f.row], f.d, f.e)).toBe('c d e'); }); it('can start or end on a group row', () => { const f = grouped(); expect(f.range([], f.row, f.e)).toBe('b c d e'); expect(f.range([f.row], f.a, f.row)).toBe('a b d'); }); it('gives nothing when a row is not shown', () => { const f = grouped(); expect(f.range([], f.k, f.c)).toBe(''); }); });