Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-8398] unit tests part 3 #4163

Merged
merged 14 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -31,6 +31,7 @@ import { AppTestingModule } from '../../testing/app-testing.module';
import { AppService, ContentApiService } from '@alfresco/aca-shared';
import { getTitleElementText } from '../../testing/test-utils';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { testHeader } from '../../testing/document-base-page-utils';

describe('FavoritesComponent', () => {
let fixture: ComponentFixture<FavoritesComponent>;
Expand Down Expand Up @@ -140,4 +141,6 @@ describe('FavoritesComponent', () => {
fixture.detectChanges();
expect(getTitleElementText(fixture)).toBe('APP.HEADER.SELECTED');
});

testHeader(FavoritesComponent);
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { By } from '@angular/platform-browser';
import { NodeEntry, NodePaging, Node, PathElement } from '@alfresco/js-api';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { testHeader } from '../../testing/document-base-page-utils';

describe('FilesComponent', () => {
let node;
Expand Down Expand Up @@ -473,4 +474,6 @@ describe('FilesComponent', () => {
expect(resetNewFolderPaginationSpy).not.toHaveBeenCalled();
});
});

testHeader(FilesComponent);
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { NodePaging, SearchApi } from '@alfresco/js-api';
import { of } from 'rxjs';
import { getTitleElementText } from '../../testing/test-utils';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { testHeader } from '../../testing/document-base-page-utils';

describe('RecentFilesComponent', () => {
let fixture: ComponentFixture<RecentFilesComponent>;
Expand Down Expand Up @@ -110,4 +111,6 @@ describe('RecentFilesComponent', () => {
fixture.detectChanges();
expect(getTitleElementText(fixture)).toBe('APP.HEADER.SELECTED');
});

testHeader(RecentFilesComponent);
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { BehaviorSubject, Subject } from 'rxjs';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { AppService } from '@alfresco/aca-shared';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { testHeader } from '../../../testing/document-base-page-utils';

describe('SearchComponent', () => {
let component: SearchResultsComponent;
Expand Down Expand Up @@ -279,4 +280,6 @@ describe('SearchComponent', () => {
expect(queryBuilder.userQuery).toBe(`((=cm:tag:"orange"))`);
expect(queryBuilder.update).toHaveBeenCalled();
});

testHeader(SearchResultsComponent, false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ import { By } from '@angular/platform-browser';
import { SharedLinkPaging } from '@alfresco/js-api';
import { AppService } from '@alfresco/aca-shared';
import { getTitleElementText } from '../../testing/test-utils';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRoute, NavigationStart, Router } from '@angular/router';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { testHeader } from '../../testing/document-base-page-utils';

describe('SharedFilesComponent', () => {
let fixture: ComponentFixture<SharedFilesComponent>;
let page: SharedLinkPaging;
let component: SharedFilesComponent;
const routerMock = {
routerState: { root: '' },
url: 'shared-files'
url: 'shared-files',
events: new Subject<NavigationStart>()
};
const route = {
snapshot: {
Expand Down Expand Up @@ -104,4 +106,6 @@ describe('SharedFilesComponent', () => {
const pagination = fixture.debugElement.query(By.css('.adf-pagination'));
expect(pagination).toBeNull();
});

testHeader(SharedFilesComponent);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*!
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { TestBed } from '@angular/core/testing';
import { EffectsModule } from '@ngrx/effects';
import { SearchAiEffects } from './search-ai.effects';
import { Store } from '@ngrx/store';
import { AppTestingModule } from '../../testing/app-testing.module';
import { SearchAiNavigationService } from '../../services/search-ai-navigation.service';
import { AppStore, SearchByTermAiAction, ToggleAISearchInput } from '@alfresco/aca-shared/store';
import { SearchAiService } from '@alfresco/adf-content-services';

describe('SearchAiEffects', () => {
let store: Store<AppStore>;

const agentId = '1';
const searchTerm = 'test';

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([SearchAiEffects])]
});
store = TestBed.inject(Store);
});

describe('searchByTerm$', () => {
it('should call navigateToSearchAi on SearchAiNavigationService', () => {
const searchAiNavigationService = TestBed.inject(SearchAiNavigationService);
spyOn(searchAiNavigationService, 'navigateToSearchAi');

store.dispatch(
new SearchByTermAiAction({
searchTerm,
agentId
})
);
expect(searchAiNavigationService.navigateToSearchAi).toHaveBeenCalledWith({
query: searchTerm,
agentId
});
});
});
describe('toggleAISearchInput$', () => {
it('should call updateSearchAiInputState on SearchAiService', () => {
const searchAiService = TestBed.inject(SearchAiService);
spyOn(searchAiService, 'updateSearchAiInputState');

store.dispatch(new ToggleAISearchInput(agentId, searchTerm));
expect(searchAiService.updateSearchAiInputState).toHaveBeenCalledWith({
active: true,
selectedAgentId: agentId,
searchTerm
});
});
});
});
103 changes: 103 additions & 0 deletions projects/aca-content/src/lib/testing/document-base-page-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*!
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { BehaviorSubject, Subject } from 'rxjs';
import { AgentService, SearchAiInputState, SearchAiService } from '@alfresco/adf-content-services';
import { DebugElement, Type } from '@angular/core';
import { By } from '@angular/platform-browser';
import { SearchAiInputContainerComponent } from '../components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PageComponent } from '@alfresco/aca-shared';
import { Agent } from '@alfresco/js-api/typings';

export const testHeader = <T extends PageComponent>(component: Type<T>, checkHeaderVisibility = true) => {
describe('Header', () => {
let fixture: ComponentFixture<T>;
let toggleSearchAiInput$: BehaviorSubject<SearchAiInputState>;

const getSearchAiInputElement = (): DebugElement => fixture.debugElement.query(By.directive(SearchAiInputContainerComponent));

const getHeaderElement = (): DebugElement => fixture.debugElement.query(By.css('.aca-header-container'));

beforeEach(() => {
fixture = TestBed.createComponent(component);
toggleSearchAiInput$ = new BehaviorSubject<SearchAiInputState>({
searchTerm: ''
} as SearchAiInputState);
TestBed.inject(SearchAiService).toggleSearchAiInput$ = toggleSearchAiInput$;
spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(new Subject<Agent[]>());
fixture.detectChanges();
});

it('should display ai input if input is active', () => {
toggleSearchAiInput$.next({
active: true,
searchTerm: ''
});

fixture.detectChanges();
expect(getSearchAiInputElement()).not.toBeNull();
});

it('should not display ai input if input is not active', () => {
toggleSearchAiInput$.next({
active: false,
searchTerm: ''
});

fixture.detectChanges();
expect(getSearchAiInputElement()).toBeNull();
});

it('should not display ai input by default', () => {
expect(getSearchAiInputElement()).toBeNull();
});

if (checkHeaderVisibility) {
it('should not display header if input is active', () => {
toggleSearchAiInput$.next({
active: true,
searchTerm: ''
});

fixture.detectChanges();
expect(getHeaderElement()).toBeNull();
});

it('should display header if input is not active', () => {
toggleSearchAiInput$.next({
active: false,
searchTerm: ''
});

fixture.detectChanges();
expect(getHeaderElement()).not.toBeNull();
});

it('should display header by default', () => {
expect(getHeaderElement()).not.toBeNull();
});
}
});
};
Loading
Loading