import { ref } from 'vue' import { describe, expect, it } from 'vitest' import { useSampleSelectorSelection } from '../../components/SampleSelector.selection' function createSelection(selected: string[] = []) { const selectedRef = ref(selected) const emitted: string[][] = [] const selection = useSampleSelectorSelection({ selected: () => selectedRef.value, samples: () => ['S1', 'S2', 'S3'], emitSelected: samples => { emitted.push(samples) selectedRef.value = samples }, }) return { emitted, selectedRef, selection } } describe('SampleSelector selection helpers', () => { it('adapts select-all and single-sample toggles to update events', () => { const { emitted, selection } = createSelection() selection.toggleSelectAll() selection.toggleSample('S1') expect(emitted).toEqual([ ['S1', 'S2', 'S3'], ['S2', 'S3'], ]) expect(selection.isAllSelected.value).toBe(false) }) it('toggles an arbitrary sample set and exposes its selection state', () => { const { emitted, selection } = createSelection(['S1']) expect(selection.isPartiallySelected(['S1', 'S2'])).toBe(true) expect(selection.isFullySelected(['S1', 'S2'])).toBe(false) selection.toggleSamplesSelection(['S1', 'S2']) expect(emitted[0]).toEqual(['S1', 'S2']) expect(selection.isFullySelected(['S1', 'S2'])).toBe(true) }) it('clears a fully selected set, so a hierarchy node can deselect its subtree', () => { const { emitted, selection } = createSelection(['S1', 'S2']) expect(selection.isFullySelected(['S1', 'S2'])).toBe(true) selection.toggleSamplesSelection(['S1', 'S2']) expect(emitted[0]).toEqual([]) expect(selection.isPartiallySelected(['S1', 'S2'])).toBe(false) }) })