[ACS-10083]: addstop level filter management; unit tests (#4935)

This commit is contained in:
Anton Ramanovich
2026-01-12 08:28:18 +01:00
committed by GitHub
parent fef4075e93
commit fd81a29d51
3 changed files with 42 additions and 3 deletions
@@ -40,6 +40,7 @@
[imageResolver]="imageResolver"
[headerFilters]="true"
[filterValue]="queryParams"
[isDataProvidedExternally]="!!queryParams"
[isResizingEnabled]="true"
[blurOnResize]="false"
[displayDragAndDropHint]="canUpload"
@@ -25,7 +25,7 @@
import { TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core';
import { Router, ActivatedRoute, convertToParamMap, ParamMap } from '@angular/router';
import { DocumentListService, FilterSearch, UploadService } from '@alfresco/adf-content-services';
import { DocumentListService, FilterSearch, SearchHeaderQueryBuilderService, UploadService } from '@alfresco/adf-content-services';
import { NodeActionsService } from '../../services/node-actions.service';
import { FilesComponent } from './files.component';
import { AppTestingModule } from '../../testing/app-testing.module';
@@ -57,6 +57,8 @@ describe('FilesComponent', () => {
events: new Subject()
};
let searchHeaderQueryBuilderService: SearchHeaderQueryBuilderService;
let spyContent = null;
let loadFolderByNodeIdSpy: jasmine.Spy;
let unitTestingUtils: UnitTestingUtils;
@@ -117,6 +119,10 @@ describe('FilesComponent', () => {
store = TestBed.inject(MockStore);
spyContent = spyOn(contentApi, 'getNode');
unitTestingUtils = new UnitTestingUtils(fixture.debugElement);
searchHeaderQueryBuilderService = TestBed.inject(SearchHeaderQueryBuilderService);
spyOn(searchHeaderQueryBuilderService, 'resetActiveFilters').and.stub();
spyOn(searchHeaderQueryBuilderService.populateFilters, 'next').and.stub();
});
beforeEach(() => {
@@ -195,7 +201,7 @@ describe('FilesComponent', () => {
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['/personal-files', 'parent-id']);
});
it('should set decoded query as queryParams', () => {
it('should set decoded query to components queryParams property and populate filters', () => {
const initialQuery = { checkList: 'TYPE:"cm:folder"' };
const mockParamMap = getEncodedParamMap(initialQuery);
@@ -207,6 +213,18 @@ describe('FilesComponent', () => {
fixture.detectChanges();
expect(component.queryParams).toEqual(initialQuery);
expect(searchHeaderQueryBuilderService.populateFilters.next).toHaveBeenCalledWith(initialQuery);
});
it('should call reset filters when queryParams is nullish', () => {
Object.defineProperty(route, 'queryParamMap', {
value: of(convertToParamMap({}))
});
fixture.detectChanges();
expect(searchHeaderQueryBuilderService.resetActiveFilters).toHaveBeenCalled();
expect(component.queryParams).toBeNull();
});
it('should check isFilterHeaderActive to be true when filters are present in queryParamMap', () => {
@@ -550,6 +568,20 @@ describe('FilesComponent', () => {
expect(component.documentList.displayDragAndDropHint).toBeFalsy();
});
it('should bind isDataProvidedExternally based on queryParams property truthiness', () => {
fixture.detectChanges();
component.queryParams = { checkList: 'TYPE:"cm:folder"' };
fixture.detectChanges();
expect(component.documentList.isDataProvidedExternally).toBe(true);
component.queryParams = null;
fixture.detectChanges();
expect(component.documentList.isDataProvidedExternally).toBe(false);
});
});
describe('Generic error', () => {
@@ -50,6 +50,7 @@ import {
DocumentListComponent,
FileUploadEvent,
FilterSearch,
SearchHeaderQueryBuilderService,
ShareDataRow,
UploadDragAreaComponent
} from '@alfresco/adf-content-services';
@@ -109,7 +110,8 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
constructor(
private readonly contentApi: ContentApiService,
private readonly nodeActionsService: NodeActionsService,
private readonly route: ActivatedRoute
private readonly route: ActivatedRoute,
private readonly queryBuilderService: SearchHeaderQueryBuilderService
) {
super();
}
@@ -123,6 +125,10 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
this.route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((queryMap) => {
this.queryParams = extractFiltersFromEncodedQuery(queryMap?.get('q'));
this.queryBuilderService.populateFilters.next(this.queryParams);
if (!this.queryParams) {
this.queryBuilderService.resetActiveFilters();
}
});
this.route.params.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(({ folderId }: Params) => {
const nodeId = folderId || data.defaultNodeId;