Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit d30b330

Browse files
committed
tests: add missing unit test
1 parent 4f826e2 commit d30b330

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/app/modules/angular-slickgrid/services/__tests__/filter.service.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ describe('FilterService', () => {
16791679
expect(preFilterSpy).toHaveReturnedWith([21, 4, 5]);
16801680
});
16811681

1682-
it('should return False when item is not found in the dataset', () => {
1682+
it('should return False also when called when item is not found in the dataset', () => {
16831683
const spyRxjs = jest.spyOn(service.onFilterChanged, 'next');
16841684
const preFilterSpy = jest.spyOn(service, 'preFilterTreeData');
16851685
jest.spyOn(dataViewStub, 'getItemById').mockReturnValueOnce({ ...dataset[4] as any })
@@ -1694,7 +1694,31 @@ describe('FilterService', () => {
16941694
gridStub.onHeaderRowCellRendered.notify(mockArgs2 as any, new Slick.EventData(), gridStub);
16951695

16961696
const columnFilters = { file: { columnDef: mockColumn1, columnId: 'file', searchTerms: ['unknown'], type: FieldType.string } } as ColumnFilters;
1697-
service.updateFilters([{ columnId: 'file', operator: '', searchTerms: ['unknown'] }], true, true, true);
1697+
service.updateFilters([{ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }], true, true, true);
1698+
const output = service.customLocalFilter(mockItem1, { dataView: dataViewStub, grid: gridStub, columnFilters });
1699+
1700+
expect(spyRxjs).toHaveBeenCalledWith([{ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }]);
1701+
expect(output).toBe(false);
1702+
expect(preFilterSpy).toHaveBeenCalledWith(dataset, { ...columnFilters, file: { ...columnFilters.file, operator: 'Contains', parsedSearchTerms: ['unknown'], type: 'string' } }); // it will use Contains by default
1703+
expect(preFilterSpy).toHaveReturnedWith([]);
1704+
});
1705+
1706+
it('should return False also when called by "updateSingleFilter" and when item is not found in the dataset', () => {
1707+
const spyRxjs = jest.spyOn(service.onFilterChanged, 'next');
1708+
const preFilterSpy = jest.spyOn(service, 'preFilterTreeData');
1709+
jest.spyOn(dataViewStub, 'getItemById').mockReturnValueOnce({ ...dataset[4] as any })
1710+
.mockReturnValueOnce(dataset[5])
1711+
.mockReturnValueOnce(dataset[6]);
1712+
1713+
const mockItem1 = { __parentId: 4, id: 5, file: 'unknown.pdf', dateModified: '2015-05-21T10:22:00.123Z', size: 3.1 };
1714+
1715+
service.init(gridStub);
1716+
service.bindLocalOnFilter(gridStub);
1717+
gridStub.onHeaderRowCellRendered.notify(mockArgs1 as any, new Slick.EventData(), gridStub);
1718+
gridStub.onHeaderRowCellRendered.notify(mockArgs2 as any, new Slick.EventData(), gridStub);
1719+
1720+
const columnFilters = { file: { columnDef: mockColumn1, columnId: 'file', searchTerms: ['unknown'], type: FieldType.string } } as ColumnFilters;
1721+
service.updateSingleFilter({ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }, true, true);
16981722
const output = service.customLocalFilter(mockItem1, { dataView: dataViewStub, grid: gridStub, columnFilters });
16991723

17001724
expect(spyRxjs).toHaveBeenCalledWith([{ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }]);

0 commit comments

Comments
 (0)