import * as stubData from './stub-data' import type { Collection } from './types' import { selectAll } from './select-all' describe('selectAll', () => { let collection: Collection describe('basic', () => { beforeEach(() => { collection = stubData.basic }) it('should select all ids - no filter', () => { expect(selectAll(collection)).toEqual(new Set(['1', '2', '3', '4'])) }) it('should select all matched ids', () => { expect(selectAll(collection, new Set(['2', '4']))).toEqual( new Set(['2', '4']) ) }) }) describe('tree', () => { beforeEach(() => { collection = stubData.tree }) it('should select all ids - no filter', () => { expect(selectAll(collection)).toEqual(new Set(['1', '2', '3', '4'])) }) it('should select all matched ids (does not nest if parent is not matched)', () => { expect(selectAll(collection, new Set(['2', '3']))).toEqual( new Set(['3']) ) }) it('should select all matched ids (nests if parent is matched)', () => { expect(selectAll(collection, new Set(['1', '2', '3']))).toEqual( new Set(['1', '2', '3']) ) }) }) describe('group', () => { beforeEach(() => { collection = stubData.group }) it('should select all leaf ids - no filter', () => { expect(selectAll(collection)).toEqual(new Set(['1', '4', '2', '3'])) }) it('should select all matched ids (does not nest if parent is not matched)', () => { expect( selectAll(collection, new Set(['1', 'group-2', '3'])) ).toEqual(new Set(['3'])) }) it('should select all matched ids (nesting if parent is matched)', () => { expect( selectAll(collection, new Set(['group-1', '1', 'group-2', '3'])) ).toEqual(new Set(['1', '3'])) }) }) describe('grouped tree', () => { beforeEach(() => { collection = stubData.groupedTree }) it('should select all leaf ids - no filter', () => { expect(selectAll(collection)).toEqual(new Set(['1', '2', '3', '4'])) }) it('should select all matched ids (does not nest if parent is not matched)', () => { expect( selectAll(collection, new Set(['1', 'group-2', '3'])) ).toEqual(new Set(['3'])) }) it('should select all matched ids (nesting if parent is matched)', () => { expect( selectAll( collection, new Set(['group-1', '1', 'group-2', '3', '4']) ) ).toEqual(new Set(['1', '3', '4'])) }) }) })