import { describe, expect, it } from 'vitest' import { nextTick, ref } from 'vue' import { useExpansionSet } from '../../composables/useExpansionSet' describe('useExpansionSet', () => { it('tracks expanded ids without mutating defaults', () => { const defaults = ['study', 'plate', 'plate'] const expansion = useExpansionSet({ defaultIds: defaults }) expect(expansion.expandedList.value).toEqual(['study', 'plate']) expect(expansion.isExpanded('study')).toBe(true) expect(expansion.toggle('study')).toBe(false) expect(expansion.isExpanded('study')).toBe(false) expect(expansion.toggle('sample')).toBe(true) expect(expansion.expandedList.value).toEqual(['plate', 'sample']) expansion.reset() expect(expansion.expandedList.value).toEqual(['study', 'plate']) expect(defaults).toEqual(['study', 'plate', 'plate']) }) it('supports bulk expansion and collapse helpers', () => { const expansion = useExpansionSet() expansion.expand('study') expansion.expandMany(['plate', 'sample', 'plate']) expect(expansion.expandedList.value).toEqual(['study', 'plate', 'sample']) expansion.collapse('plate') expect(expansion.expandedList.value).toEqual(['study', 'sample']) expansion.setExpanded(['treatment']) expect(expansion.expandedList.value).toEqual(['treatment']) expansion.collapseAll() expect(expansion.expandedList.value).toEqual([]) }) it('reacts to expand-all and all-id sources', async () => { const expandAll = ref(false) const allIds = ref(['study', 'plate']) const expansion = useExpansionSet({ defaultIds: ['study'], allIds, expandAll, }) expect(expansion.expandedList.value).toEqual(['study']) expandAll.value = true await nextTick() expect(expansion.expandedList.value).toEqual(['study', 'plate']) allIds.value = ['study', 'plate', 'sample'] await nextTick() expect(expansion.expandedList.value).toEqual(['study', 'plate', 'sample']) expandAll.value = false await nextTick() expect(expansion.expandedList.value).toEqual(['study']) }) })