Skip to content

Commit

Permalink
[ACS-6642] Tags column and getTags API call is now dynamic on app.con…
Browse files Browse the repository at this point in the history
…fig.json for search page (#3607)
  • Loading branch information
swapnil-verma-gl authored Jan 24, 2024
1 parent 91cdb1a commit 47fb269
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<data-column id="app.search.size" key="content.sizeInBytes" type="fileSize" title="APP.DOCUMENT_LIST.COLUMNS.SIZE" class="adf-no-grow-cell adf-ellipsis-cell" [sortable]="false" *ngIf="!isSmallScreen" [draggable]="true"></data-column>
<data-column id="app.search.modifiedOn" key="modifiedAt" type="date" title="APP.DOCUMENT_LIST.COLUMNS.MODIFIED_ON" class="adf-no-grow-cell adf-ellipsis-cell" format="timeAgo" [sortable]="false" *ngIf="!isSmallScreen" [draggable]="true"></data-column>
<data-column id="app.search.modifiedBy" key="modifiedByUser.displayName" title="APP.DOCUMENT_LIST.COLUMNS.MODIFIED_BY" class="adf-no-grow-cell adf-ellipsis-cell" [sortable]="false" *ngIf="!isSmallScreen" [draggable]="true"></data-column>
<data-column id="app.search.tags" key="$tags" type="text" title="APP.DOCUMENT_LIST.COLUMNS.TAGS" class="adf-full-width adf-expand-cell-4" [sortable]="false" [draggable]="true">
<data-column id="app.search.tags" key="$tags" type="text" title="APP.DOCUMENT_LIST.COLUMNS.TAGS" class="adf-full-width adf-expand-cell-4" [sortable]="false" [draggable]="true" *ngIf="isTagsEnabled">
<ng-template let-context>
<aca-tags-column [context]="context"></aca-tags-column>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

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';

Expand Down Expand Up @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -102,10 +102,18 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
sorting = ['name', 'asc'];
isLoading = false;
totalResults: number;

constructor(private queryBuilder: SearchQueryBuilderService, private route: ActivatedRoute, private translationService: TranslationService) {
isTagsEnabled = false;

constructor(
tagsService: TagService,
private queryBuilder: SearchQueryBuilderService,
private route: ActivatedRoute,
private translationService: TranslationService
) {
super();

this.isTagsEnabled = tagsService.areTagsEnabled();

queryBuilder.paging = {
skipCount: 0,
maxItems: 25
Expand Down

0 comments on commit 47fb269

Please sign in to comment.