diff --git a/projects/aca-content/src/lib/components/search/search-results/search-results.component.html b/projects/aca-content/src/lib/components/search/search-results/search-results.component.html index 57306df77..78d6505d5 100644 --- a/projects/aca-content/src/lib/components/search/search-results/search-results.component.html +++ b/projects/aca-content/src/lib/components/search/search-results/search-results.component.html @@ -75,7 +75,7 @@ - + diff --git a/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts b/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts index e8614b0a6..ce3c18fbb 100644 --- a/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts @@ -22,15 +22,15 @@ * from Hyland Software. If not, see . */ -import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; import { SearchResultsComponent } from './search-results.component'; import { AppConfigService, TranslationService } from '@alfresco/adf-core'; import { Store } from '@ngrx/store'; import { NavigateToFolder, SnackbarErrorAction } from '@alfresco/aca-shared/store'; -import { Pagination, SearchRequest } from '@alfresco/js-api'; -import { SearchQueryBuilderService } from '@alfresco/adf-content-services'; +import { Pagination, ResultSetPaging, SearchRequest } from '@alfresco/js-api'; +import { SearchQueryBuilderService, TagService } from '@alfresco/adf-content-services'; import { ActivatedRoute, Router } from '@angular/router'; -import { BehaviorSubject, Subject } from 'rxjs'; +import { BehaviorSubject, of, Subject } from 'rxjs'; import { AppTestingModule } from '../../../testing/app-testing.module'; import { AppService } from '@alfresco/aca-shared'; @@ -274,4 +274,80 @@ describe('SearchComponent', () => { expect(queryBuilder.userQuery).toBe(`((=cm:tag:"orange"))`); expect(queryBuilder.update).toHaveBeenCalled(); }); + + describe('Dynamic Columns', () => { + let tagsService: TagService; + + beforeEach(() => { + tagsService = TestBed.inject(TagService); + + spyOn(queryBuilder['searchApi'], 'search').and.returnValue( + Promise.resolve({ + list: { + pagination: { + count: 1, + hasMoreItems: false, + totalItems: 1, + skipCount: 0, + maxItems: 25 + }, + entries: [ + { + entry: { + isFile: true, + nodeType: 'cm:content', + isFolder: false, + name: 'test-file.txt', + id: '8dd4d319-ec9f-4ea0-8276-f3b195918477' + } + } + ] + } + } as ResultSetPaging) + ); + + spyOn(queryBuilder, 'buildQuery').and.returnValue(searchRequest); + }); + + it('should not show tags column if tags are disabled', fakeAsync(() => { + spyOn(tagsService, 'areTagsEnabled').and.returnValue(false); + fixture = TestBed.createComponent(SearchResultsComponent); + fixture.detectChanges(); + queryBuilder.execute(); + tick(); + fixture.detectChanges(); + const tagsColumnHeader = fixture.nativeElement.querySelector(`[data-automation-id='auto_id_$tags']`); + expect(tagsColumnHeader).toBeNull(); + })); + + it('should show tags column if tags are enabled', fakeAsync(() => { + spyOn(tagsService, 'areTagsEnabled').and.returnValue(true); + spyOn(tagsService, 'getTagsByNodeId').and.returnValue( + of({ + list: { + pagination: { + count: 0, + hasMoreItems: false, + totalItems: 0, + skipCount: 0, + maxItems: 100 + }, + entries: [] + } + }) + ); + fixture = TestBed.createComponent(SearchResultsComponent); + fixture.detectChanges(); + queryBuilder.execute(); + tick(); + fixture.detectChanges(); + const tagsColumnHeader = fixture.nativeElement.querySelector(`[data-automation-id='auto_id_$tags']`); + expect(tagsColumnHeader).not.toBeNull(); + flush(); + })); + + afterEach(() => { + fixture.destroy(); + }); + }); }); diff --git a/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts b/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts index 84bdd0472..e8f516904 100644 --- a/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts +++ b/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts @@ -25,7 +25,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { NodeEntry, Pagination, ResultSetPaging } from '@alfresco/js-api'; import { ActivatedRoute, Params } from '@angular/router'; -import { AlfrescoViewerModule, DocumentListModule, SearchModule, SearchQueryBuilderService } from '@alfresco/adf-content-services'; +import { AlfrescoViewerModule, DocumentListModule, SearchModule, SearchQueryBuilderService, TagService } from '@alfresco/adf-content-services'; import { infoDrawerPreview, NavigateToFolder, @@ -102,10 +102,18 @@ export class SearchResultsComponent extends PageComponent implements OnInit { sorting = ['name', 'asc']; isLoading = false; totalResults: number; + isTagsEnabled = false; - constructor(private queryBuilder: SearchQueryBuilderService, private route: ActivatedRoute, private translationService: TranslationService) { + constructor( + tagsService: TagService, + private queryBuilder: SearchQueryBuilderService, + private route: ActivatedRoute, + private translationService: TranslationService + ) { super(); + this.isTagsEnabled = tagsService.areTagsEnabled(); + queryBuilder.paging = { skipCount: 0, maxItems: 25