mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACS-10083] Filter not behaving correctly in file and site (#4817)
* [ACS-10083]: adds query decoding * [ACS-10083]: adds unit test for added feature * [ACS-10083]: unit test fix * [ACS-10083]: minor fixes * [ACS-10083]: circular dep fix * [ACS-10083]: removes redundant code * [ACS-10083]: test fix
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
import { TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
|
||||
import { NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core';
|
||||
import { Router, ActivatedRoute, convertToParamMap } from '@angular/router';
|
||||
import { Router, ActivatedRoute, convertToParamMap, ParamMap } from '@angular/router';
|
||||
import { DocumentListService, FilterSearch, UploadService } from '@alfresco/adf-content-services';
|
||||
import { NodeActionsService } from '../../services/node-actions.service';
|
||||
import { FilesComponent } from './files.component';
|
||||
@@ -72,6 +72,11 @@ describe('FilesComponent', () => {
|
||||
expect(template).not.toBeNull();
|
||||
}
|
||||
|
||||
function getEncodedParamMap(initialQuery = { checkList: 'TYPE:"cm:folder"' }): ParamMap {
|
||||
const encoded = btoa(JSON.stringify(initialQuery));
|
||||
return convertToParamMap({ q: encoded });
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule, FilesComponent, MatSnackBarModule],
|
||||
@@ -85,7 +90,7 @@ describe('FilesComponent', () => {
|
||||
useValue: {
|
||||
snapshot: { data: { preferencePrefix: 'prefix' }, paramMap: convertToParamMap({ folderId: undefined }) },
|
||||
params: of({ folderId: 'someId' }),
|
||||
queryParamMap: of({})
|
||||
queryParamMap: of(convertToParamMap({}))
|
||||
}
|
||||
},
|
||||
AppExtensionService,
|
||||
@@ -190,8 +195,26 @@ describe('FilesComponent', () => {
|
||||
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['/personal-files', 'parent-id']);
|
||||
});
|
||||
|
||||
it('should set decoded query as queryParams', () => {
|
||||
const initialQuery = { checkList: 'TYPE:"cm:folder"' };
|
||||
|
||||
const mockParamMap = getEncodedParamMap(initialQuery);
|
||||
|
||||
Object.defineProperty(route, 'queryParamMap', {
|
||||
value: of(mockParamMap)
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.queryParams).toEqual(initialQuery);
|
||||
});
|
||||
|
||||
it('should check isFilterHeaderActive to be true when filters are present in queryParamMap', () => {
|
||||
Object.defineProperty(route, 'queryParamMap', { value: of({ params: { $thumbnail: 'TYPE:"cm:folder"' } }) });
|
||||
const mockParamMap = getEncodedParamMap();
|
||||
|
||||
Object.defineProperty(route, 'queryParamMap', {
|
||||
value: of(mockParamMap)
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { SearchAiInputContainerComponent } from '../knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { extractFiltersFromEncodedQuery } from '../../utils/aca-search-utils';
|
||||
|
||||
@Component({
|
||||
imports: [
|
||||
@@ -120,8 +121,8 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.title = data.title;
|
||||
|
||||
this.route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((queryMap: Params) => {
|
||||
this.queryParams = queryMap.params;
|
||||
this.route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((queryMap) => {
|
||||
this.queryParams = extractFiltersFromEncodedQuery(queryMap?.get('q'));
|
||||
});
|
||||
this.route.params.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(({ folderId }: Params) => {
|
||||
const nodeId = folderId || data.defaultNodeId;
|
||||
@@ -384,7 +385,6 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
|
||||
void this.router.navigate(['.'], { relativeTo: this.route });
|
||||
this.isFilterHeaderActive = false;
|
||||
this.showHeader = ShowHeaderMode.Data;
|
||||
this.onAllFilterCleared();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-7
@@ -259,11 +259,4 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
|
||||
onSortingChanged(event: any) {
|
||||
this.filterSorting = event.detail.key + '-' + event.detail.direction;
|
||||
}
|
||||
|
||||
onAllFilterCleared() {
|
||||
if (!this.isOutletPreviewUrl()) {
|
||||
this.documentList.node = null;
|
||||
this.documentListService.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-37
@@ -26,11 +26,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { PageComponent } from './document-base-page.component';
|
||||
import { AppState, SetSelectedNodesAction, ViewNodeAction } from '@alfresco/aca-shared/store';
|
||||
import { LibTestingModule, discoveryApiServiceMockValue, DocumentBasePageServiceMock } from '@alfresco/aca-shared';
|
||||
import { NodeEntry, NodePaging } from '@alfresco/js-api';
|
||||
import { NodeEntry } from '@alfresco/js-api';
|
||||
import { DocumentBasePageService } from './document-base-page.service';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Component } from '@angular/core';
|
||||
import { DiscoveryApiService, DocumentListComponent, DocumentListService, SearchAiInputState, SearchAiService } from '@alfresco/adf-content-services';
|
||||
import { DiscoveryApiService, DocumentListService, SearchAiInputState, SearchAiService } from '@alfresco/adf-content-services';
|
||||
import { MockStore, provideMockStore } from '@ngrx/store/testing';
|
||||
import { provideCoreAuth, UserPreferencesService } from '@alfresco/adf-core';
|
||||
import { of, Subscription } from 'rxjs';
|
||||
@@ -157,41 +157,6 @@ describe('PageComponent', () => {
|
||||
expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(new SetSelectedNodesAction([node]));
|
||||
});
|
||||
|
||||
it('should clear results onAllFilterCleared event', () => {
|
||||
spyOn(documentListService, 'reload');
|
||||
|
||||
component.documentList = {
|
||||
node: {
|
||||
list: {
|
||||
pagination: {},
|
||||
entries: [{ entry: { id: 'new-node-id' } }]
|
||||
}
|
||||
} as NodePaging
|
||||
} as DocumentListComponent;
|
||||
spyOn(store, 'dispatch');
|
||||
|
||||
component.onAllFilterCleared();
|
||||
expect(component.documentList.node).toBe(null);
|
||||
expect(documentListService.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call onAllFilterCleared event if page is viewer outlet', () => {
|
||||
window.history.pushState({}, null, `${locationHref}#test(viewer:view)`);
|
||||
const nodePaging = {
|
||||
list: {
|
||||
pagination: {},
|
||||
entries: [{ entry: { id: 'new-node-id' } }]
|
||||
}
|
||||
} as NodePaging;
|
||||
|
||||
component.documentList = { node: nodePaging } as DocumentListComponent;
|
||||
spyOn(store, 'dispatch');
|
||||
|
||||
component.onAllFilterCleared();
|
||||
expect(component.documentList.node).toEqual(nodePaging);
|
||||
expect(store.dispatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call ViewNodeAction on showPreview for selected node', () => {
|
||||
spyOn(store, 'dispatch');
|
||||
const node = {
|
||||
|
||||
Reference in New Issue
Block a user