diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.spec.ts b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.spec.ts
new file mode 100644
index 000000000..2ae4ce426
--- /dev/null
+++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.spec.ts
@@ -0,0 +1,186 @@
+/*!
+ * 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 .
+ */
+
+import { SearchAiInputContainerComponent } from './search-ai-input-container.component';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { SearchAiInputComponent } from '../search-ai-input/search-ai-input.component';
+import { By } from '@angular/platform-browser';
+import { AgentService, ContentTestingModule, SearchAiService } from '@alfresco/adf-content-services';
+import { MockStore, provideMockStore } from '@ngrx/store/testing';
+import { getAppSelection } from '@alfresco/aca-shared/store';
+import { of, Subject } from 'rxjs';
+import { MatDivider } from '@angular/material/divider';
+import { DebugElement } from '@angular/core';
+import { MatIconButton } from '@angular/material/button';
+import { MatIcon } from '@angular/material/icon';
+import { SearchAiNavigationService } from '../../../../services/search-ai-navigation.service';
+import { NavigationEnd, NavigationStart, Router, RouterEvent } from '@angular/router';
+
+describe('SearchAiInputContainerComponent', () => {
+ let component: SearchAiInputContainerComponent;
+ let fixture: ComponentFixture;
+ let routingEvents$: Subject;
+ let searchAiService: SearchAiService;
+ let store: MockStore;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [SearchAiInputContainerComponent, ContentTestingModule],
+ providers: [
+ provideMockStore(),
+ {
+ provide: AgentService,
+ useValue: {
+ getAgents: () =>
+ of({
+ list: {
+ entries: [
+ {
+ entry: {
+ id: '1',
+ name: 'HR Agent'
+ }
+ }
+ ]
+ }
+ })
+ }
+ }
+ ]
+ });
+
+ fixture = TestBed.createComponent(SearchAiInputContainerComponent);
+ component = fixture.componentInstance;
+ store = TestBed.inject(MockStore);
+ searchAiService = TestBed.inject(SearchAiService);
+ store.overrideSelector(getAppSelection, {
+ nodes: [],
+ isEmpty: true,
+ count: 0,
+ libraries: []
+ });
+ component.agentId = '1';
+ routingEvents$ = new Subject();
+ spyOnProperty(TestBed.inject(Router), 'events').and.returnValue(routingEvents$);
+ fixture.detectChanges();
+ });
+
+ describe('Search ai input', () => {
+ let inputComponent: SearchAiInputComponent;
+
+ beforeEach(() => {
+ inputComponent = fixture.debugElement.query(By.directive(SearchAiInputComponent)).componentInstance;
+ });
+
+ it('should have assigned correct default placeholder', () => {
+ expect(inputComponent.placeholder).toBe('KNOWLEDGE_RETRIEVAL.SEARCH.SEARCH_INPUT.DEFAULT_PLACEHOLDER');
+ });
+
+ it('should have assigned correct placeholder if placeholder has been changed', () => {
+ component.placeholder = 'Some placeholder';
+ fixture.detectChanges();
+
+ expect(inputComponent.placeholder).toBe(component.placeholder);
+ });
+
+ it('should have assigned correct agentId', () => {
+ expect(inputComponent.agentId).toBe(component.agentId);
+ });
+
+ it('should have assigned correct useStoredNodes flag', () => {
+ component.useStoredNodes = true;
+ fixture.detectChanges();
+
+ expect(inputComponent.useStoredNodes).toBeTrue();
+ });
+
+ it('should call updateSearchAiInputState on SearchAiService when triggered searchSubmitted event', () => {
+ spyOn(searchAiService, 'updateSearchAiInputState');
+ inputComponent.searchSubmitted.emit();
+
+ expect(searchAiService.updateSearchAiInputState).toHaveBeenCalledWith({
+ active: false
+ });
+ });
+ });
+
+ describe('Divider', () => {
+ it('should have a vertical divider', () => {
+ fixture.detectChanges();
+
+ expect(fixture.debugElement.query(By.directive(MatDivider)).componentInstance.vertical).toBeTrue();
+ });
+ });
+
+ describe('Leaving button', () => {
+ let button: DebugElement;
+
+ beforeEach(() => {
+ button = fixture.debugElement.query(By.directive(MatIconButton));
+ });
+
+ it('should have correct title', () => {
+ expect(button.nativeElement.title).toBe('KNOWLEDGE_RETRIEVAL.SEARCH.SEARCH_INPUT.HIDE_INPUT');
+ });
+
+ it('should contain close icon', () => {
+ expect(button.query(By.directive(MatIcon)).nativeElement.textContent).toBe('close');
+ });
+
+ it('should call updateSearchAiInputState on SearchAiService when clicked', () => {
+ spyOn(searchAiService, 'updateSearchAiInputState');
+ button.nativeElement.click();
+
+ expect(searchAiService.updateSearchAiInputState).toHaveBeenCalledWith({
+ active: false
+ });
+ });
+
+ it('should call navigateToPreviousRoute on SearchAiNavigationService when clicked', () => {
+ const searchNavigationService = TestBed.inject(SearchAiNavigationService);
+ spyOn(searchNavigationService, 'navigateToPreviousRoute');
+ button.nativeElement.click();
+
+ expect(searchNavigationService.navigateToPreviousRoute).toHaveBeenCalled();
+ });
+ });
+
+ describe('Navigation', () => {
+ it('should call updateSearchAiInputState on SearchAiService when navigation starts', () => {
+ spyOn(searchAiService, 'updateSearchAiInputState');
+ routingEvents$.next(new NavigationStart(1, ''));
+
+ expect(searchAiService.updateSearchAiInputState).toHaveBeenCalledWith({
+ active: false
+ });
+ });
+
+ it('should not call updateSearchAiInputState on SearchAiService when there is different event than navigation starts', () => {
+ spyOn(searchAiService, 'updateSearchAiInputState');
+ routingEvents$.next(new NavigationEnd(1, '', ''));
+
+ expect(searchAiService.updateSearchAiInputState).not.toHaveBeenCalled();
+ });
+ });
+});
diff --git a/projects/aca-content/src/lib/services/search-ai-navigation.service.spec.ts b/projects/aca-content/src/lib/services/search-ai-navigation.service.spec.ts
new file mode 100644
index 000000000..7da4d1c80
--- /dev/null
+++ b/projects/aca-content/src/lib/services/search-ai-navigation.service.spec.ts
@@ -0,0 +1,134 @@
+/*!
+ * 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 .
+ */
+
+import { SearchAiNavigationService } from './search-ai-navigation.service';
+import { Params, Router } from '@angular/router';
+import { TestBed } from '@angular/core/testing';
+import { ContentTestingModule } from '@alfresco/adf-content-services';
+
+describe('SearchAiNavigationService', () => {
+ let service: SearchAiNavigationService;
+ let router: Router;
+
+ const knowledgeRetrievalUrl = '/knowledge-retrieval';
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [ContentTestingModule]
+ });
+ service = TestBed.inject(SearchAiNavigationService);
+ router = TestBed.inject(Router);
+ });
+
+ describe('navigateToPreviousRoute', () => {
+ let urlSpy: jasmine.Spy<() => string>;
+ let navigateByUrlSpy: jasmine.Spy<(url: string) => Promise>;
+
+ const sourceUrl = '/some-url';
+ const personalFilesUrl = '/personal-files';
+
+ beforeEach(() => {
+ navigateByUrlSpy = spyOn(router, 'navigateByUrl');
+ urlSpy = spyOnProperty(router, 'url');
+ });
+
+ it('should navigate to personal files if there is not previous route and actual route is knowledge retrieval', () => {
+ urlSpy.and.returnValue(knowledgeRetrievalUrl);
+ service.navigateToPreviousRoute();
+
+ expect(navigateByUrlSpy).toHaveBeenCalledWith(personalFilesUrl);
+ });
+
+ it('should not navigate if there is not previous route and actual route is not knowledge retrieval', () => {
+ urlSpy.and.returnValue('/some-url');
+ service.navigateToPreviousRoute();
+
+ expect(navigateByUrlSpy).not.toHaveBeenCalled();
+ });
+
+ it('should navigate to previous route if there is some previous route and actual route is knowledge retrieval', () => {
+ urlSpy.and.returnValue(sourceUrl);
+ service.navigateToSearchAi({
+ agentId: 'some agent id'
+ });
+ urlSpy.and.returnValue(knowledgeRetrievalUrl);
+ navigateByUrlSpy.calls.reset();
+ service.navigateToPreviousRoute();
+
+ expect(navigateByUrlSpy).toHaveBeenCalledWith(sourceUrl);
+ });
+
+ it('should not navigate to previous route if there is some previous route but actual route is not knowledge retrieval', () => {
+ urlSpy.and.returnValue(sourceUrl);
+ service.navigateToSearchAi({
+ agentId: 'some agent id'
+ });
+ urlSpy.and.returnValue('/some-different-url');
+ navigateByUrlSpy.calls.reset();
+ service.navigateToPreviousRoute();
+
+ expect(navigateByUrlSpy).not.toHaveBeenCalled();
+ });
+
+ it('should navigate to personal files if previous route is knowledge retrieval and actual route is knowledge retrieval', () => {
+ urlSpy.and.returnValue(knowledgeRetrievalUrl);
+ service.navigateToSearchAi({
+ agentId: 'some agent id'
+ });
+ navigateByUrlSpy.calls.reset();
+ service.navigateToPreviousRoute();
+
+ expect(navigateByUrlSpy).toHaveBeenCalledWith(personalFilesUrl);
+ });
+
+ it('should not navigate if previous route is knowledge retrieval and actual route is different than knowledge retrieval', () => {
+ urlSpy.and.returnValue(knowledgeRetrievalUrl);
+ service.navigateToSearchAi({
+ agentId: 'some agent id'
+ });
+ urlSpy.and.returnValue(sourceUrl);
+ navigateByUrlSpy.calls.reset();
+ service.navigateToPreviousRoute();
+
+ expect(navigateByUrlSpy).not.toHaveBeenCalled();
+ });
+ });
+
+ describe('navigateToSearchAi', () => {
+ beforeEach(() => {
+ spyOn(router, 'navigate');
+ });
+
+ it('should navigate to search ai results page', () => {
+ const queryParams: Params = {
+ agentId: 'some agent id'
+ };
+ service.navigateToSearchAi(queryParams);
+
+ expect(router.navigate).toHaveBeenCalledWith([knowledgeRetrievalUrl], {
+ queryParams
+ });
+ });
+ });
+});
diff --git a/projects/aca-content/src/lib/services/search-ai-navigation.service.ts b/projects/aca-content/src/lib/services/search-ai-navigation.service.ts
index 5fc3cb197..6bc745e3c 100644
--- a/projects/aca-content/src/lib/services/search-ai-navigation.service.ts
+++ b/projects/aca-content/src/lib/services/search-ai-navigation.service.ts
@@ -43,6 +43,6 @@ export class SearchAiNavigationService {
if (!this.router.url.includes(this.knowledgeRetrievalRoute)) {
this.previousRoute = this.router.url;
}
- void this.router.navigate([this.knowledgeRetrievalRoute], { queryParams: queryParams });
+ void this.router.navigate([this.knowledgeRetrievalRoute], { queryParams });
}
}
diff --git a/projects/aca-content/src/lib/store/effects/search-ai.effects.ts b/projects/aca-content/src/lib/store/effects/search-ai.effects.ts
index 6de4a8d54..4670b8a77 100644
--- a/projects/aca-content/src/lib/store/effects/search-ai.effects.ts
+++ b/projects/aca-content/src/lib/store/effects/search-ai.effects.ts
@@ -28,6 +28,7 @@ import { SearchAiActionTypes, SearchByTermAiAction, ToggleAISearchInput } from '
import { map } from 'rxjs/operators';
import { SearchAiNavigationService } from '../../services/search-ai-navigation.service';
import { SearchAiService } from '@alfresco/adf-content-services';
+import { Params } from '@angular/router';
@Injectable()
export class SearchAiEffects {
@@ -38,7 +39,7 @@ export class SearchAiEffects {
this.actions$.pipe(
ofType(SearchAiActionTypes.SearchByTermAi),
map((action) => {
- const queryParams = {
+ const queryParams: Params = {
query: encodeURIComponent(action.payload.searchTerm),
agentId: action.payload.agentId
};
diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts
index c1f1828f6..f6289f6a8 100644
--- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts
+++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts
@@ -84,7 +84,6 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
protected searchAiService: SearchAiService = inject(SearchAiService);
protected subscriptions: Subscription[] = [];
- private fileAutoDownloadService = inject(AcaFileAutoDownloadService, { optional: true });
private _searchAiInputState: SearchAiInputState = {
active: false
};