@@ -7,7 +7,9 @@ import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed";
77import { HarnessLoader } from "@angular/cdk/testing" ;
88import { MatSelectHarness } from "@angular/material/select/testing" ;
99import { MockedTestingModule } from "../../../utils/mocked-testing.module" ;
10- import { ActivatedRoute } from "@angular/router" ;
10+ import { ActivatedRoute , Router } from "@angular/router" ;
11+ import { BasicFilterConfig } from "../../entity-list/EntityListConfig" ;
12+ import { TestEntity } from "../../../utils/test-utils/TestEntity" ;
1113
1214class ActivatedRouteMock {
1315 public snapshot = {
@@ -21,6 +23,7 @@ describe("FilterComponent", () => {
2123 let loader : HarnessLoader ;
2224
2325 let activatedRouteMock = new ActivatedRouteMock ( ) ;
26+ let router : Router ;
2427
2528 beforeEach ( async ( ) => {
2629 activatedRouteMock . snapshot = {
@@ -36,7 +39,7 @@ describe("FilterComponent", () => {
3639 } ,
3740 ] ,
3841 } ) . compileComponents ( ) ;
39-
42+ router = TestBed . inject ( Router ) ;
4043 fixture = TestBed . createComponent ( FilterComponent ) ;
4144 loader = TestbedHarnessEnvironment . loader ( fixture ) ;
4245 component = fixture . componentInstance ;
@@ -98,6 +101,40 @@ describe("FilterComponent", () => {
98101 expect ( component . filterSelections [ 0 ] . selectedOptionValues [ 1 ] ) . toBe ( "bar" ) ;
99102 } ) ;
100103
104+ it ( "should remove the longest filter option if URL length exceeds 2000 characters" , async ( ) => {
105+ const initialQueryParams = { dateOfBirth : "a,b" } ;
106+ activatedRouteMock . snapshot . queryParams = initialQueryParams ;
107+ const routerNavigate = spyOn ( router , "navigate" ) ;
108+
109+ component . entityType = TestEntity ;
110+ component . entities = [ ] ;
111+ component . useUrlQueryParams = true ;
112+ component . filterConfig = [ { id : "category" } as BasicFilterConfig ] ;
113+ await component . ngOnChanges ( { filterConfig : true } as any ) ;
114+
115+ component . filterOptionSelected ( component . filterSelections [ 0 ] , [
116+ "categoryXX" ,
117+ "categoryYY" ,
118+ ] ) ;
119+ // filter options should be added to url
120+ expect ( router . navigate ) . toHaveBeenCalledWith ( [ ] , {
121+ relativeTo : activatedRouteMock as any ,
122+ queryParams : { ...initialQueryParams , category : "categoryXX,categoryYY" } ,
123+ queryParamsHandling : "merge" ,
124+ } ) ;
125+ routerNavigate . calls . reset ( ) ;
126+
127+ const longOptions = Array ( 250 ) . fill ( "categoryZZ" ) ;
128+ component . filterOptionSelected ( component . filterSelections [ 0 ] , longOptions ) ;
129+ // long options should be skipped, short options for other filter still present
130+ expect ( router . navigate ) . toHaveBeenCalledWith ( [ ] , {
131+ relativeTo : activatedRouteMock as any ,
132+ queryParams : { ...initialQueryParams , category : undefined } ,
133+ queryParamsHandling : "merge" ,
134+ } ) ;
135+ routerNavigate . calls . reset ( ) ;
136+ } ) ;
137+
101138 it ( "should load url params and set no filter value when empty" , async ( ) => {
102139 component . entityType = Note ;
103140 component . useUrlQueryParams = true ;
0 commit comments