@@ -3,6 +3,7 @@ import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/t
33import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
44import { Store } from '@ngrx/store' ;
55import { createBasicStoreModule } from '@stratosui/store/testing' ;
6+ import { PaginationEntityState } from 'frontend/packages/store/src/types/pagination.types' ;
67import { BehaviorSubject , of as observableOf } from 'rxjs' ;
78import { switchMap } from 'rxjs/operators' ;
89
@@ -16,6 +17,7 @@ import { CoreTestingModule } from '../../../../test-framework/core-test.modules'
1617import { CoreModule } from '../../../core/core.module' ;
1718import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service' ;
1819import { SharedModule } from '../../shared.module' ;
20+ import { getFilterFunction } from './data-sources-controllers/local-filtering-sorting' ;
1921import { EndpointCardComponent } from './list-types/endpoint/endpoint-card/endpoint-card.component' ;
2022import { EndpointListHelper } from './list-types/endpoint/endpoint-list.helpers' ;
2123import { EndpointsListConfigService } from './list-types/endpoint/endpoints-list-config.service' ;
@@ -320,6 +322,74 @@ describe('ListComponent', () => {
320322 expect ( noEntriesMessage . hidden ) . toBeFalsy ( ) ;
321323 } ) ;
322324
325+ describe ( 'getFilterFunction filters entities ' , ( ) => {
326+ const paginationState : PaginationEntityState = {
327+ currentPage : 1 ,
328+ totalResults : 2 ,
329+ pageCount : 1 ,
330+ ids : { } ,
331+ params : { } ,
332+ pageRequests : { } ,
333+ clientPagination : {
334+ pageSize : 10 ,
335+ currentPage : 1 ,
336+ filter : {
337+ string : 'hello' , // Filtering for 'hello'
338+ items : { }
339+ } ,
340+ totalResults : 2
341+ } ,
342+ maxedState : { } ,
343+ isListPagination : false
344+ } ;
345+
346+ it ( 'by label' , ( ) => {
347+ const filterbyLabel = getFilterFunction ( {
348+ type : 'filter' ,
349+ field : 'entity.label'
350+ } , )
351+
352+ const entities : APIResource [ ] = [
353+ {
354+ metadata : { created_at : '2025-02-02' , guid : '1' , updated_at : '2025-02-03' , url : '/url1' } ,
355+ entity : { label : 'hello' }
356+ } ,
357+ {
358+ metadata : { created_at : '2022-01-02' , guid : '2' , updated_at : '2022-01-03' , url : '/url2' } ,
359+ entity : { label : 'world' }
360+ } ,
361+ ]
362+
363+ const result = filterbyLabel ( entities , paginationState )
364+
365+ expect ( result . length ) . toBe ( 1 ) ;
366+ expect ( result [ 0 ] . entity . label ) . toEqual ( 'hello' ) ;
367+ } )
368+
369+ it ( 'by tags' , ( ) => {
370+ const filterbyTags = getFilterFunction ( {
371+ type : 'filter' ,
372+ field : 'entity.tags'
373+ } )
374+
375+ const entities : APIResource [ ] = [
376+ {
377+ metadata : { created_at : '2025-02-02' , guid : '1' , updated_at : '2025-02-03' , url : '/url1' } ,
378+ entity : { tags : [ 'hello' , 'world' ] }
379+ } ,
380+ {
381+ metadata : { created_at : '2022-01-02' , guid : '2' , updated_at : '2022-01-03' , url : '/url2' } ,
382+ entity : { tags : [ 'bye' , 'world' ] }
383+ } ,
384+ ]
385+
386+ const result = filterbyTags ( entities , paginationState )
387+
388+ expect ( result . length ) . toBe ( 1 ) ;
389+ expect ( result [ 0 ] . entity . tags ) . toEqual ( [ 'hello' , 'world' ] ) ;
390+ } )
391+ } )
392+
323393 } ) ;
324394
325395} ) ;
0 commit comments