Skip to content

Commit 83bc55e

Browse files
authored
[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
1 parent cd330c2 commit 83bc55e

File tree

4 files changed

+31
-50
lines changed

4 files changed

+31
-50
lines changed

projects/aca-content/src/lib/components/files/files.component.spec.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import { TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
2626
import { NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core';
27-
import { Router, ActivatedRoute, convertToParamMap } from '@angular/router';
27+
import { Router, ActivatedRoute, convertToParamMap, ParamMap } from '@angular/router';
2828
import { DocumentListService, FilterSearch, UploadService } from '@alfresco/adf-content-services';
2929
import { NodeActionsService } from '../../services/node-actions.service';
3030
import { FilesComponent } from './files.component';
@@ -72,6 +72,11 @@ describe('FilesComponent', () => {
7272
expect(template).not.toBeNull();
7373
}
7474

75+
function getEncodedParamMap(initialQuery = { checkList: 'TYPE:"cm:folder"' }): ParamMap {
76+
const encoded = btoa(JSON.stringify(initialQuery));
77+
return convertToParamMap({ q: encoded });
78+
}
79+
7580
beforeEach(() => {
7681
TestBed.configureTestingModule({
7782
imports: [AppTestingModule, FilesComponent, MatSnackBarModule],
@@ -85,7 +90,7 @@ describe('FilesComponent', () => {
8590
useValue: {
8691
snapshot: { data: { preferencePrefix: 'prefix' }, paramMap: convertToParamMap({ folderId: undefined }) },
8792
params: of({ folderId: 'someId' }),
88-
queryParamMap: of({})
93+
queryParamMap: of(convertToParamMap({}))
8994
}
9095
},
9196
AppExtensionService,
@@ -190,8 +195,26 @@ describe('FilesComponent', () => {
190195
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['/personal-files', 'parent-id']);
191196
});
192197

198+
it('should set decoded query as queryParams', () => {
199+
const initialQuery = { checkList: 'TYPE:"cm:folder"' };
200+
201+
const mockParamMap = getEncodedParamMap(initialQuery);
202+
203+
Object.defineProperty(route, 'queryParamMap', {
204+
value: of(mockParamMap)
205+
});
206+
207+
fixture.detectChanges();
208+
209+
expect(component.queryParams).toEqual(initialQuery);
210+
});
211+
193212
it('should check isFilterHeaderActive to be true when filters are present in queryParamMap', () => {
194-
Object.defineProperty(route, 'queryParamMap', { value: of({ params: { $thumbnail: 'TYPE:"cm:folder"' } }) });
213+
const mockParamMap = getEncodedParamMap();
214+
215+
Object.defineProperty(route, 'queryParamMap', {
216+
value: of(mockParamMap)
217+
});
195218

196219
fixture.detectChanges();
197220

projects/aca-content/src/lib/components/files/files.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
6161
import { SearchAiInputContainerComponent } from '../knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component';
6262
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
6363
import { HttpErrorResponse } from '@angular/common/http';
64+
import { extractFiltersFromEncodedQuery } from '../../utils/aca-search-utils';
6465

6566
@Component({
6667
imports: [
@@ -120,8 +121,8 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
120121

121122
this.title = data.title;
122123

123-
this.route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((queryMap: Params) => {
124-
this.queryParams = queryMap.params;
124+
this.route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((queryMap) => {
125+
this.queryParams = extractFiltersFromEncodedQuery(queryMap?.get('q'));
125126
});
126127
this.route.params.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(({ folderId }: Params) => {
127128
const nodeId = folderId || data.defaultNodeId;
@@ -384,7 +385,6 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
384385
void this.router.navigate(['.'], { relativeTo: this.route });
385386
this.isFilterHeaderActive = false;
386387
this.showHeader = ShowHeaderMode.Data;
387-
this.onAllFilterCleared();
388388
}
389389
}
390390

projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,4 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
259259
onSortingChanged(event: any) {
260260
this.filterSorting = event.detail.key + '-' + event.detail.direction;
261261
}
262-
263-
onAllFilterCleared() {
264-
if (!this.isOutletPreviewUrl()) {
265-
this.documentList.node = null;
266-
this.documentListService.reload();
267-
}
268-
}
269262
}

projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
2626
import { PageComponent } from './document-base-page.component';
2727
import { AppState, SetSelectedNodesAction, ViewNodeAction } from '@alfresco/aca-shared/store';
2828
import { LibTestingModule, discoveryApiServiceMockValue, DocumentBasePageServiceMock } from '@alfresco/aca-shared';
29-
import { NodeEntry, NodePaging } from '@alfresco/js-api';
29+
import { NodeEntry } from '@alfresco/js-api';
3030
import { DocumentBasePageService } from './document-base-page.service';
3131
import { Store } from '@ngrx/store';
3232
import { Component } from '@angular/core';
33-
import { DiscoveryApiService, DocumentListComponent, DocumentListService, SearchAiInputState, SearchAiService } from '@alfresco/adf-content-services';
33+
import { DiscoveryApiService, DocumentListService, SearchAiInputState, SearchAiService } from '@alfresco/adf-content-services';
3434
import { MockStore, provideMockStore } from '@ngrx/store/testing';
3535
import { provideCoreAuth, UserPreferencesService } from '@alfresco/adf-core';
3636
import { of, Subscription } from 'rxjs';
@@ -157,41 +157,6 @@ describe('PageComponent', () => {
157157
expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(new SetSelectedNodesAction([node]));
158158
});
159159

160-
it('should clear results onAllFilterCleared event', () => {
161-
spyOn(documentListService, 'reload');
162-
163-
component.documentList = {
164-
node: {
165-
list: {
166-
pagination: {},
167-
entries: [{ entry: { id: 'new-node-id' } }]
168-
}
169-
} as NodePaging
170-
} as DocumentListComponent;
171-
spyOn(store, 'dispatch');
172-
173-
component.onAllFilterCleared();
174-
expect(component.documentList.node).toBe(null);
175-
expect(documentListService.reload).toHaveBeenCalled();
176-
});
177-
178-
it('should call onAllFilterCleared event if page is viewer outlet', () => {
179-
window.history.pushState({}, null, `${locationHref}#test(viewer:view)`);
180-
const nodePaging = {
181-
list: {
182-
pagination: {},
183-
entries: [{ entry: { id: 'new-node-id' } }]
184-
}
185-
} as NodePaging;
186-
187-
component.documentList = { node: nodePaging } as DocumentListComponent;
188-
spyOn(store, 'dispatch');
189-
190-
component.onAllFilterCleared();
191-
expect(component.documentList.node).toEqual(nodePaging);
192-
expect(store.dispatch).not.toHaveBeenCalled();
193-
});
194-
195160
it('should call ViewNodeAction on showPreview for selected node', () => {
196161
spyOn(store, 'dispatch');
197162
const node = {

0 commit comments

Comments
 (0)