[ACS-8666] Fixed issue where header filters were not getting reset when navigating between folders (#10150)

This commit is contained in:
swapnil-verma-gl 2024-09-12 12:27:37 +05:30 committed by GitHub
parent 3458546c92
commit eb954c0ecd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 66 additions and 1 deletions

View File

@ -204,4 +204,40 @@ describe('SearchCheckListComponent', () => {
const checkedElements = await loader.getAllHarnesses(MatCheckboxHarness.with({ checked: true }));
expect(checkedElements.length).toBe(0);
});
it('should update query with startValue on init, if provided', () => {
component.id = 'checkList';
component.options = new SearchFilterList<SearchListOption>([
{ name: 'Folder', value: `TYPE:'cm:folder'`, checked: false },
{ name: 'Document', value: `TYPE:'cm:content'`, checked: false }
]);
component.startValue = `TYPE:'cm:folder'`;
component.context = {
queryFragments: {},
update: jasmine.createSpy()
} as any;
fixture.detectChanges();
expect(component.context.queryFragments[component.id]).toBe(`TYPE:'cm:folder'`);
expect(component.context.update).toHaveBeenCalled();
});
it('should set query context as blank and not call query update, if no start value was provided', () => {
component.id = 'checkList';
component.options = new SearchFilterList<SearchListOption>([
{ name: 'Folder', value: `TYPE:'cm:folder'`, checked: true },
{ name: 'Document', value: `TYPE:'cm:content'`, checked: false }
]);
component.startValue = undefined;
component.context = {
queryFragments: {
checkList: `TYPE:'cm:folder'`
},
update: jasmine.createSpy()
} as any;
fixture.detectChanges();
expect(component.context.queryFragments[component.id]).toBe('');
expect(component.context.update).not.toHaveBeenCalled();
});
});

View File

@ -49,7 +49,7 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
context?: SearchQueryBuilderService;
options: SearchFilterList<SearchListOption>;
operator: string = 'OR';
startValue: SearchListOption = null;
startValue: string;
pageSize = 5;
isActive = false;
enableChangeUpdate = true;
@ -72,6 +72,10 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
if (this.startValue) {
this.setValue(this.startValue);
} else {
if (this.id && this.context) {
this.context.queryFragments[this.id] = '';
}
}
}

View File

@ -119,4 +119,25 @@ describe('SearchTextComponent', () => {
expect(component.value).toBe('');
expect(component.context.queryFragments[component.id]).toBe('');
});
it('should update query with startValue on init, if provided', () => {
spyOn(component.context, 'update');
component.startValue = 'mock-start-value';
fixture.detectChanges();
expect(component.context.queryFragments[component.id]).toBe(`cm:name:'mock-start-value'`);
expect(component.value).toBe('mock-start-value');
expect(component.context.update).toHaveBeenCalled();
});
it('should parse value and set query context as blank, and not call query update, if no start value was provided', () => {
component.context.queryFragments[component.id] = `cm:name:'secret.pdf'`;
spyOn(component.context, 'update');
component.startValue = undefined;
fixture.detectChanges();
expect(component.context.queryFragments[component.id]).toBe('');
expect(component.value).toBe('secret.pdf');
expect(component.context.update).not.toHaveBeenCalled();
});
});

View File

@ -64,6 +64,10 @@ export class SearchTextComponent implements SearchWidget, OnInit {
if (this.startValue) {
this.setValue(this.startValue);
} else {
if (this.context?.queryFragments) {
this.context.queryFragments[this.id] = '';
}
}
}
}