import type { GridState } from '..' import { INITIAL_STATE } from '..' import { jest } from '@jest/globals' import type { StoreSimpleSelectors } from '../selectors' import type { SelectFilterMatches, SelectFilterMatchesShowOnly } from './filter' import generateSelectors from './filter' describe('compositeSelectors - filter', () => { let selectFilterMatches: SelectFilterMatches let selectFilterMatchesShowOnly: SelectFilterMatchesShowOnly let selectFilterMode: jest.Mock beforeEach(() => { const fn = (row: any) => Number(row.id) % 2 === 0 const rows = { 1: { id: '1', title: 'One' }, 2: { id: '2', title: 'Two' }, 3: { id: '3', title: 'Three' }, } const rowCollection = { ...INITIAL_STATE.rows.collection, entities: new Map(Object.entries(rows)), ids: ['1', '2', '3'], } selectFilterMode = jest .fn() .mockReturnValue('default') ;({ selectFilterMatches, selectFilterMatchesShowOnly } = generateSelectors({ selectFilterFn: () => fn, selectRowCollection: () => rowCollection, selectFilterMode, })) }) describe('selectFilterMatches', () => { it('should select correct row ids', () => { const res = selectFilterMatches({} as GridState) expect(res.matchedIds).toEqual(new Set(['2'])) expect(res.necessaryMatchedIds).toEqual(new Set(['2'])) }) }) describe('selectFilterMatchesShowOnly', () => { it('should select filtered row ids when mode is default', () => { const res = selectFilterMatchesShowOnly({} as GridState) expect(res).toEqual(new Set(['2'])) }) it('should return null when mode is highlight', () => { selectFilterMode.mockReturnValue('highlight') const res = selectFilterMatchesShowOnly({} as GridState) expect(res).toBeNull() }) }) })