Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
ShowHeaderMode
} from '@alfresco/adf-core';
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { ActivatedRoute, ParamMap, Params } from '@angular/router';
import { Node, NodeEntry, PathElement } from '@alfresco/js-api';
import { NodeActionsService } from '../../services/node-actions.service';
import {
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: ParamMap) => {
this.queryParams = extractFiltersFromEncodedQuery(queryMap?.get('q'));
});
this.route.params.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(({ folderId }: Params) => {
const nodeId = folderId || data.defaultNodeId;
Expand Down Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
Expand Down
Loading