From 9ef76c1cb834da0a22f58937151082460ddb4bcd Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Wed, 2 Oct 2024 10:52:18 +0200 Subject: [PATCH 01/14] ACS-8398 Unit tests for search ai effects --- .../store/effects/search-ai.effects.spec.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts diff --git a/projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts b/projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts new file mode 100644 index 0000000000..a82f8b594e --- /dev/null +++ b/projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts @@ -0,0 +1,76 @@ +/*! + * 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 { 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; + + const agentId = '1'; + + 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'); + const searchTerm = 'test'; + + 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)); + expect(searchAiService.updateSearchAiInputState).toHaveBeenCalledWith({ + active: true, + selectedAgentId: agentId + }); + }); + }); +}); From 8b887bdcfa3aac6e61cf555503d48a39e767aa80 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Wed, 2 Oct 2024 13:14:13 +0200 Subject: [PATCH 02/14] ACS-8398 Unit tests for canDisplayKnowledgeRetrievalButton rule --- .../aca-shared/rules/src/app.rules.spec.ts | 195 +++++++++++++++--- 1 file changed, 164 insertions(+), 31 deletions(-) diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index d5fe674a96..b5d68d966d 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -26,6 +26,7 @@ import * as app from './app.rules'; import { TestRuleContext } from './test-rule-context'; import { NodeEntry, RepositoryInfo, StatusInfo } from '@alfresco/js-api'; import { getFileExtension } from './app.rules'; +import { AppConfigService } from '@alfresco/adf-core'; describe('app.evaluators', () => { let context: TestRuleContext; @@ -540,44 +541,176 @@ describe('app.evaluators', () => { }); }); - describe('isKnowledgeRetrievalEnabled', () => { - it('should call context.appConfig.get with correct parameters', () => { - context.appConfig = { get: jasmine.createSpy() } as any; + describe('canDisplayKnowledgeRetrievalButton', () => { + it('should return false if get from appConfig returns false and navigation is personal files', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/personal-files'; - app.canDisplayKnowledgeRetrievalButton(context); - expect(context.appConfig.get).toHaveBeenCalledWith('plugins.knowledgeRetrievalEnabled', true); + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); }); - it('should return false if get from appConfig returns false', () => { - expect( - app.canDisplayKnowledgeRetrievalButton({ - appConfig: { - get: () => false - } - } as any) - ).toBeFalse(); + it('should return true if get from appConfig returns true and navigation is personal files', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/personal-files'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); }); - it('should return true if get from appConfig returns true and navigation is correct', () => { - expect( - app.canDisplayKnowledgeRetrievalButton({ - navigation: { url: '/personal-files' }, - appConfig: { - get: () => true - } - } as any) - ).toBeTrue(); + it('should return false if get from appConfig returns false and navigation is shared files', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/shared'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); }); - it('should return false if get from appConfig returns true, but navigation is not correct', () => { - expect( - app.canDisplayKnowledgeRetrievalButton({ - navigation: { url: '/my-special-files' }, - appConfig: { - get: () => true - } - } as any) - ).toBeFalse(); + it('should return true if get from appConfig returns true and navigation is shared files', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/shared'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + }); + + it('should return false if get from appConfig returns false and navigation is recent files', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/recent-files'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return true if get from appConfig returns true and navigation is recent files', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/recent-files'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + }); + + it('should return false if get from appConfig returns false and navigation is favorites', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/favorites'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return true if get from appConfig returns true and navigation is favorites', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/favorites'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + }); + + it('should return false if get from appConfig returns false and navigation is search results but not for libraries', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/search'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return true if get from appConfig returns true and navigation is search results but not for libraries', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/search'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + }); + + it('should return false if get from appConfig returns false and navigation is search results for libraries', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/search/libraries'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return false if get from appConfig returns true and navigation is search results for libraries', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/search/libraries'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return false if get from appConfig returns false and navigation is library content', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/libraries/some-id'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return true if get from appConfig returns true and navigation is library content', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/libraries/some-id'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + }); + + it('should return false if get from appConfig returns false and navigation is libraries', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/libraries'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return false if get from appConfig returns true and navigation is libraries', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/libraries'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return false if get from appConfig returns false and navigation is incorrect', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + context.navigation.url = '/my-special-files'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should return false if get from appConfig returns true but navigation is incorrect', () => { + context.appConfig = jasmine.createSpyObj({ + get: true + }); + context.navigation.url = '/my-special-files'; + + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + }); + + it('should call get on context.appConfig with correct parameters', () => { + context.appConfig = jasmine.createSpyObj({ + get: false + }); + + app.canDisplayKnowledgeRetrievalButton(context); + expect(context.appConfig.get).toHaveBeenCalledWith('plugins.knowledgeRetrievalEnabled', false); }); }); From 21fa6678c0e9d2f43deaca5f71659d72108cce49 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Thu, 3 Oct 2024 09:20:17 +0200 Subject: [PATCH 03/14] ACS-8398 Unit tests for changes in document base page --- .../document-base-page.spec.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts index 8d6264154b..227e408738 100644 --- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts +++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts @@ -30,7 +30,7 @@ import { NodeEntry, NodePaging } 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, SearchAiService } from '@alfresco/adf-content-services'; +import { DiscoveryApiService, DocumentListComponent, DocumentListService, SearchAiInputState, SearchAiService } from '@alfresco/adf-content-services'; import { MockStore, provideMockStore } from '@ngrx/store/testing'; import { AuthModule, UserPreferencesService } from '@alfresco/adf-core'; import { of, Subscription } from 'rxjs'; @@ -278,6 +278,21 @@ describe('PageComponent', () => { expect(searchAiService.updateSearchAiInputState).not.toHaveBeenCalled(); }); }); + + describe('SearchAiService toggleSearchAiInput$ event handler', () => { + it('should set searchAiInputState', () => { + const initialSearchAiInputState = component.searchAiInputState; + const searchAiInputState: SearchAiInputState = { + active: true + }; + TestBed.inject(SearchAiService).toggleSearchAiInput$ = of(searchAiInputState); + + component.ngOnInit(); + expect(component.searchAiInputState).toBe(searchAiInputState); + expect(initialSearchAiInputState).toEqual({ + active: false + }); + }); }); describe('Info Drawer state', () => { From 82e5f89edfd6d95739364ad8fcef211bf20e7469 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Thu, 3 Oct 2024 14:52:52 +0200 Subject: [PATCH 04/14] ACS-8398 Added unit tests for changes in recent files component --- .../recent-files.component.spec.ts | 3 + .../lib/testing/document-base-page-utils.ts | 94 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 projects/aca-content/src/lib/testing/document-base-page-utils.ts diff --git a/projects/aca-content/src/lib/components/recent-files/recent-files.component.spec.ts b/projects/aca-content/src/lib/components/recent-files/recent-files.component.spec.ts index c5ae08ba7a..bc3bd6b889 100644 --- a/projects/aca-content/src/lib/components/recent-files/recent-files.component.spec.ts +++ b/projects/aca-content/src/lib/components/recent-files/recent-files.component.spec.ts @@ -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; @@ -110,4 +111,6 @@ describe('RecentFilesComponent', () => { fixture.detectChanges(); expect(getTitleElementText(fixture)).toBe('APP.HEADER.SELECTED'); }); + + testHeader(RecentFilesComponent); }); diff --git a/projects/aca-content/src/lib/testing/document-base-page-utils.ts b/projects/aca-content/src/lib/testing/document-base-page-utils.ts new file mode 100644 index 0000000000..0bb42c151d --- /dev/null +++ b/projects/aca-content/src/lib/testing/document-base-page-utils.ts @@ -0,0 +1,94 @@ +/*! + * 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 { Subject } from 'rxjs'; +import { 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'; + +export const testHeader = (component: Type) => { + let fixture: ComponentFixture; + + describe('Header', () => { + let toggleSearchAiInput$: Subject; + + 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 Subject(); + TestBed.inject(SearchAiService).toggleSearchAiInput$ = toggleSearchAiInput$; + fixture.detectChanges(); + }); + + it('should display ai input if input is active', () => { + toggleSearchAiInput$.next({ + active: true + }); + + fixture.detectChanges(); + expect(getSearchAiInputElement()).not.toBeNull(); + }); + + it('should not display ai input if input is not active', () => { + toggleSearchAiInput$.next({ + active: false + }); + + fixture.detectChanges(); + expect(getSearchAiInputElement()).toBeNull(); + }); + + it('should not display ai input by default', () => { + expect(getSearchAiInputElement()).toBeNull(); + }); + + it('should not display header if input is active', () => { + toggleSearchAiInput$.next({ + active: true + }); + + fixture.detectChanges(); + expect(getHeaderElement()).toBeNull(); + }); + + it('should display header if input is not active', () => { + toggleSearchAiInput$.next({ + active: false + }); + + fixture.detectChanges(); + expect(getHeaderElement()).not.toBeNull(); + }); + + it('should display header by default', () => { + expect(getHeaderElement()).not.toBeNull(); + }); + }); +}; From dc5fda4fc6fe30d871d7c36a4c97e5f1dd1da194 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Fri, 4 Oct 2024 14:12:15 +0200 Subject: [PATCH 05/14] ACS-8398 Unit tests for changes in lists pages --- .../favorites/favorites.component.spec.ts | 3 ++ .../components/files/files.component.spec.ts | 3 ++ .../search-results.component.spec.ts | 3 ++ .../shared-files.component.spec.ts | 8 +++- .../lib/testing/document-base-page-utils.ts | 42 ++++++++++--------- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts b/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts index b1b51b1262..a025b9c823 100644 --- a/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts +++ b/projects/aca-content/src/lib/components/favorites/favorites.component.spec.ts @@ -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; @@ -140,4 +141,6 @@ describe('FavoritesComponent', () => { fixture.detectChanges(); expect(getTitleElementText(fixture)).toBe('APP.HEADER.SELECTED'); }); + + testHeader(FavoritesComponent); }); diff --git a/projects/aca-content/src/lib/components/files/files.component.spec.ts b/projects/aca-content/src/lib/components/files/files.component.spec.ts index aecf55b6ca..fd8daea467 100644 --- a/projects/aca-content/src/lib/components/files/files.component.spec.ts +++ b/projects/aca-content/src/lib/components/files/files.component.spec.ts @@ -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; @@ -473,4 +474,6 @@ describe('FilesComponent', () => { expect(resetNewFolderPaginationSpy).not.toHaveBeenCalled(); }); }); + + testHeader(FilesComponent); }); 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 274a971bd1..841025d0b3 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 @@ -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; @@ -279,4 +280,6 @@ describe('SearchComponent', () => { expect(queryBuilder.userQuery).toBe(`((=cm:tag:"orange"))`); expect(queryBuilder.update).toHaveBeenCalled(); }); + + testHeader(SearchResultsComponent, false); }); diff --git a/projects/aca-content/src/lib/components/shared-files/shared-files.component.spec.ts b/projects/aca-content/src/lib/components/shared-files/shared-files.component.spec.ts index 2b873f3c75..7109e85735 100644 --- a/projects/aca-content/src/lib/components/shared-files/shared-files.component.spec.ts +++ b/projects/aca-content/src/lib/components/shared-files/shared-files.component.spec.ts @@ -31,8 +31,9 @@ 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; @@ -40,7 +41,8 @@ describe('SharedFilesComponent', () => { let component: SharedFilesComponent; const routerMock = { routerState: { root: '' }, - url: 'shared-files' + url: 'shared-files', + events: new Subject() }; const route = { snapshot: { @@ -104,4 +106,6 @@ describe('SharedFilesComponent', () => { const pagination = fixture.debugElement.query(By.css('.adf-pagination')); expect(pagination).toBeNull(); }); + + testHeader(SharedFilesComponent); }); diff --git a/projects/aca-content/src/lib/testing/document-base-page-utils.ts b/projects/aca-content/src/lib/testing/document-base-page-utils.ts index 0bb42c151d..aff9327dd7 100644 --- a/projects/aca-content/src/lib/testing/document-base-page-utils.ts +++ b/projects/aca-content/src/lib/testing/document-base-page-utils.ts @@ -23,15 +23,16 @@ */ import { Subject } from 'rxjs'; -import { SearchAiInputState, SearchAiService } from '@alfresco/adf-content-services'; +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 = (component: Type) => { - let fixture: ComponentFixture; +export const testHeader = (component: Type, checkHeaderVisibility = true) => { + let fixture: ComponentFixture; describe('Header', () => { let toggleSearchAiInput$: Subject; @@ -44,6 +45,7 @@ export const testHeader = (component: Type) => { fixture = TestBed.createComponent(component); toggleSearchAiInput$ = new Subject(); TestBed.inject(SearchAiService).toggleSearchAiInput$ = toggleSearchAiInput$; + spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(new Subject()); fixture.detectChanges(); }); @@ -69,26 +71,28 @@ export const testHeader = (component: Type) => { expect(getSearchAiInputElement()).toBeNull(); }); - it('should not display header if input is active', () => { - toggleSearchAiInput$.next({ - active: true + if (checkHeaderVisibility) { + it('should not display header if input is active', () => { + toggleSearchAiInput$.next({ + active: true + }); + + fixture.detectChanges(); + expect(getHeaderElement()).toBeNull(); }); - fixture.detectChanges(); - expect(getHeaderElement()).toBeNull(); - }); + it('should display header if input is not active', () => { + toggleSearchAiInput$.next({ + active: false + }); - it('should display header if input is not active', () => { - toggleSearchAiInput$.next({ - active: false + fixture.detectChanges(); + expect(getHeaderElement()).not.toBeNull(); }); - fixture.detectChanges(); - expect(getHeaderElement()).not.toBeNull(); - }); - - it('should display header by default', () => { - expect(getHeaderElement()).not.toBeNull(); - }); + it('should display header by default', () => { + expect(getHeaderElement()).not.toBeNull(); + }); + } }); }; From 2067d026e97e8e61796358fb64169e9380de8869 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Fri, 4 Oct 2024 14:33:00 +0200 Subject: [PATCH 06/14] ACS-8398 Moved variable to inside of describe --- .../aca-content/src/lib/testing/document-base-page-utils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/aca-content/src/lib/testing/document-base-page-utils.ts b/projects/aca-content/src/lib/testing/document-base-page-utils.ts index aff9327dd7..dfb8579845 100644 --- a/projects/aca-content/src/lib/testing/document-base-page-utils.ts +++ b/projects/aca-content/src/lib/testing/document-base-page-utils.ts @@ -32,9 +32,8 @@ import { PageComponent } from '@alfresco/aca-shared'; import { Agent } from '@alfresco/js-api/typings'; export const testHeader = (component: Type, checkHeaderVisibility = true) => { - let fixture: ComponentFixture; - describe('Header', () => { + let fixture: ComponentFixture; let toggleSearchAiInput$: Subject; const getSearchAiInputElement = (): DebugElement => fixture.debugElement.query(By.directive(SearchAiInputContainerComponent)); From e96d954d4f1ee0d4120a68e3b66e5cb24663fb38 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Fri, 4 Oct 2024 14:51:51 +0200 Subject: [PATCH 07/14] ACS-8398 Moved repeated code to function --- .../aca-shared/rules/src/app.rules.spec.ts | 137 ++++-------------- 1 file changed, 25 insertions(+), 112 deletions(-) diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index b5d68d966d..1befbef009 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -542,175 +542,88 @@ describe('app.evaluators', () => { }); describe('canDisplayKnowledgeRetrievalButton', () => { - it('should return false if get from appConfig returns false and navigation is personal files', () => { + const testCanDisplayKnowledgeRetrievalButton = (url: string, knowledgeRetrievalEnabled: boolean, expected: boolean) => { context.appConfig = jasmine.createSpyObj({ - get: false + get: knowledgeRetrievalEnabled }); - context.navigation.url = '/personal-files'; + context.navigation.url = url; + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBe(expected); + }; - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + it('should return false if get from appConfig returns false and navigation is personal files', () => { + testCanDisplayKnowledgeRetrievalButton('/personal-files', false, false); }); it('should return true if get from appConfig returns true and navigation is personal files', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/personal-files'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + testCanDisplayKnowledgeRetrievalButton('/personal-files', true, true); }); it('should return false if get from appConfig returns false and navigation is shared files', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/shared'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/shared', false, false); }); it('should return true if get from appConfig returns true and navigation is shared files', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/shared'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + testCanDisplayKnowledgeRetrievalButton('/shared', true, true); }); it('should return false if get from appConfig returns false and navigation is recent files', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/recent-files'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/recent-files', false, false); }); it('should return true if get from appConfig returns true and navigation is recent files', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/recent-files'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + testCanDisplayKnowledgeRetrievalButton('/recent-files', true, true); }); it('should return false if get from appConfig returns false and navigation is favorites', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/favorites'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/favorites', false, false); }); it('should return true if get from appConfig returns true and navigation is favorites', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/favorites'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + testCanDisplayKnowledgeRetrievalButton('/favorites', true, true); }); it('should return false if get from appConfig returns false and navigation is search results but not for libraries', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/search'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/search', false, false); }); it('should return true if get from appConfig returns true and navigation is search results but not for libraries', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/search'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + testCanDisplayKnowledgeRetrievalButton('/search', true, true); }); it('should return false if get from appConfig returns false and navigation is search results for libraries', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/search/libraries'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/search/libraries', false, false); }); it('should return false if get from appConfig returns true and navigation is search results for libraries', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/search/libraries'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/search/libraries', true, false); }); it('should return false if get from appConfig returns false and navigation is library content', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/libraries/some-id'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/libraries/some-id', false, false); }); it('should return true if get from appConfig returns true and navigation is library content', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/libraries/some-id'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeTrue(); + testCanDisplayKnowledgeRetrievalButton('/libraries/some-id', true, true); }); it('should return false if get from appConfig returns false and navigation is libraries', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/libraries'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/libraries', false, false); }); it('should return false if get from appConfig returns true and navigation is libraries', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/libraries'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/libraries', true, false); }); it('should return false if get from appConfig returns false and navigation is incorrect', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - context.navigation.url = '/my-special-files'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/my-special-files', false, false); }); it('should return false if get from appConfig returns true but navigation is incorrect', () => { - context.appConfig = jasmine.createSpyObj({ - get: true - }); - context.navigation.url = '/my-special-files'; - - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBeFalse(); + testCanDisplayKnowledgeRetrievalButton('/my-special-files', true, false); }); it('should call get on context.appConfig with correct parameters', () => { - context.appConfig = jasmine.createSpyObj({ - get: false - }); - - app.canDisplayKnowledgeRetrievalButton(context); - expect(context.appConfig.get).toHaveBeenCalledWith('plugins.knowledgeRetrievalEnabled', false); + testCanDisplayKnowledgeRetrievalButton('/personal-files', false, false); }); }); From b67172dd29696b73a3fc464b4ec52067fbc992b5 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Fri, 4 Oct 2024 14:53:53 +0200 Subject: [PATCH 08/14] ACS-8398 Reverted one change --- projects/aca-shared/rules/src/app.rules.spec.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index 1befbef009..1423f2d867 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -623,7 +623,12 @@ describe('app.evaluators', () => { }); it('should call get on context.appConfig with correct parameters', () => { - testCanDisplayKnowledgeRetrievalButton('/personal-files', false, false); + context.appConfig = jasmine.createSpyObj({ + get: false + }); + + app.canDisplayKnowledgeRetrievalButton(context); + expect(context.appConfig.get).toHaveBeenCalledWith('plugins.knowledgeRetrievalEnabled', false); }); }); From 2e3cf782544f115fbce50cd7dd28cd01fea84edd Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Fri, 4 Oct 2024 15:02:02 +0200 Subject: [PATCH 09/14] ACS-8398 Fix after rebase --- .../lib/components/document-base-page/document-base-page.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts index 227e408738..fe8ca49444 100644 --- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts +++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts @@ -293,6 +293,7 @@ describe('PageComponent', () => { active: false }); }); + }); }); describe('Info Drawer state', () => { From 0dda1807745fa53a87bd983701d89d98f852fa78 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Fri, 4 Oct 2024 15:12:02 +0200 Subject: [PATCH 10/14] ACS-8398 Fix issue with repeated code --- .../aca-shared/rules/src/app.rules.spec.ts | 208 +++++++++++------- 1 file changed, 132 insertions(+), 76 deletions(-) diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index 1423f2d867..2ac73719eb 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -542,85 +542,141 @@ describe('app.evaluators', () => { }); describe('canDisplayKnowledgeRetrievalButton', () => { - const testCanDisplayKnowledgeRetrievalButton = (url: string, knowledgeRetrievalEnabled: boolean, expected: boolean) => { - context.appConfig = jasmine.createSpyObj({ - get: knowledgeRetrievalEnabled + const testCanDisplayKnowledgeRetrievalButton = (testTitle: string, url: string, knowledgeRetrievalEnabled: boolean, expected: boolean) => { + it(testTitle, () => { + context.appConfig = jasmine.createSpyObj({ + get: knowledgeRetrievalEnabled + }); + context.navigation.url = url; + expect(app.canDisplayKnowledgeRetrievalButton(context)).toBe(expected); }); - context.navigation.url = url; - expect(app.canDisplayKnowledgeRetrievalButton(context)).toBe(expected); }; - it('should return false if get from appConfig returns false and navigation is personal files', () => { - testCanDisplayKnowledgeRetrievalButton('/personal-files', false, false); - }); - - it('should return true if get from appConfig returns true and navigation is personal files', () => { - testCanDisplayKnowledgeRetrievalButton('/personal-files', true, true); - }); - - it('should return false if get from appConfig returns false and navigation is shared files', () => { - testCanDisplayKnowledgeRetrievalButton('/shared', false, false); - }); - - it('should return true if get from appConfig returns true and navigation is shared files', () => { - testCanDisplayKnowledgeRetrievalButton('/shared', true, true); - }); - - it('should return false if get from appConfig returns false and navigation is recent files', () => { - testCanDisplayKnowledgeRetrievalButton('/recent-files', false, false); - }); - - it('should return true if get from appConfig returns true and navigation is recent files', () => { - testCanDisplayKnowledgeRetrievalButton('/recent-files', true, true); - }); - - it('should return false if get from appConfig returns false and navigation is favorites', () => { - testCanDisplayKnowledgeRetrievalButton('/favorites', false, false); - }); - - it('should return true if get from appConfig returns true and navigation is favorites', () => { - testCanDisplayKnowledgeRetrievalButton('/favorites', true, true); - }); - - it('should return false if get from appConfig returns false and navigation is search results but not for libraries', () => { - testCanDisplayKnowledgeRetrievalButton('/search', false, false); - }); - - it('should return true if get from appConfig returns true and navigation is search results but not for libraries', () => { - testCanDisplayKnowledgeRetrievalButton('/search', true, true); - }); - - it('should return false if get from appConfig returns false and navigation is search results for libraries', () => { - testCanDisplayKnowledgeRetrievalButton('/search/libraries', false, false); - }); - - it('should return false if get from appConfig returns true and navigation is search results for libraries', () => { - testCanDisplayKnowledgeRetrievalButton('/search/libraries', true, false); - }); - - it('should return false if get from appConfig returns false and navigation is library content', () => { - testCanDisplayKnowledgeRetrievalButton('/libraries/some-id', false, false); - }); - - it('should return true if get from appConfig returns true and navigation is library content', () => { - testCanDisplayKnowledgeRetrievalButton('/libraries/some-id', true, true); - }); - - it('should return false if get from appConfig returns false and navigation is libraries', () => { - testCanDisplayKnowledgeRetrievalButton('/libraries', false, false); - }); - - it('should return false if get from appConfig returns true and navigation is libraries', () => { - testCanDisplayKnowledgeRetrievalButton('/libraries', true, false); - }); - - it('should return false if get from appConfig returns false and navigation is incorrect', () => { - testCanDisplayKnowledgeRetrievalButton('/my-special-files', false, false); - }); - - it('should return false if get from appConfig returns true but navigation is incorrect', () => { - testCanDisplayKnowledgeRetrievalButton('/my-special-files', true, false); - }); + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is personal files', + '/personal-files', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return true if get from appConfig returns true and navigation is personal files', + '/personal-files', + true, + true + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is shared files', + '/shared', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return true if get from appConfig returns true and navigation is shared files', + '/shared', + true, + true + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is recent files', + '/recent-files', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return true if get from appConfig returns true and navigation is recent files', + '/recent-files', + true, + true + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is favorites', + '/favorites', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return true if get from appConfig returns true and navigation is favorites', + '/favorites', + true, + true + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is search results but not for libraries', + '/search', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return true if get from appConfig returns true and navigation is search results but not for libraries', + '/search', + true, + true + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is search results for libraries', + '/search/libraries', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns true and navigation is search results for libraries', + '/search/libraries', + true, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is library content', + '/libraries/some-id', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return true if get from appConfig returns true and navigation is library content', + '/libraries/some-id', + true, + true + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is libraries', + '/libraries', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns true and navigation is libraries', + '/libraries', + true, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns false and navigation is incorrect', + '/my-special-files', + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + 'should return false if get from appConfig returns true but navigation is incorrect', + '/my-special-files', + true, + false + ); it('should call get on context.appConfig with correct parameters', () => { context.appConfig = jasmine.createSpyObj({ From 1542936c56134b26f7fc2aec29d616c856c3762f Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Fri, 4 Oct 2024 15:25:45 +0200 Subject: [PATCH 11/14] ACS-8398 Fix issue with repeated code --- .../aca-shared/rules/src/app.rules.spec.ts | 105 ++++++------------ 1 file changed, 36 insertions(+), 69 deletions(-) diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index 2ac73719eb..e59ef4e478 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -552,61 +552,42 @@ describe('app.evaluators', () => { }); }; - testCanDisplayKnowledgeRetrievalButton( - 'should return false if get from appConfig returns false and navigation is personal files', - '/personal-files', - false, - false - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return true if get from appConfig returns true and navigation is personal files', - '/personal-files', - true, - true - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return false if get from appConfig returns false and navigation is shared files', - '/shared', - false, - false - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return true if get from appConfig returns true and navigation is shared files', - '/shared', - true, - true - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return false if get from appConfig returns false and navigation is recent files', - '/recent-files', - false, - false - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return true if get from appConfig returns true and navigation is recent files', - '/recent-files', - true, - true - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return false if get from appConfig returns false and navigation is favorites', - '/favorites', - false, - false - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return true if get from appConfig returns true and navigation is favorites', - '/favorites', - true, - true - ); + [ + { + pageName: 'personal files', + pageUrl: '/personal-files' + }, + { + pageName: 'shared files', + pageUrl: '/shared' + }, + { + pageName: 'recent files', + pageUrl: '/recent-files' + }, + { + pageName: 'favorites', + pageUrl: '/favorites' + }, + { + pageName: 'library content', + pageUrl: '/libraries/some-id' + } + ].forEach((testCase) => { + testCanDisplayKnowledgeRetrievalButton( + `should return false if get from appConfig returns false and navigation is ${testCase.pageName}`, + testCase.pageUrl, + false, + false + ); + + testCanDisplayKnowledgeRetrievalButton( + `should return true if get from appConfig returns true and navigation is ${testCase.pageName}`, + testCase.pageUrl, + true, + true + ); + }); testCanDisplayKnowledgeRetrievalButton( 'should return false if get from appConfig returns false and navigation is search results but not for libraries', @@ -636,20 +617,6 @@ describe('app.evaluators', () => { false ); - testCanDisplayKnowledgeRetrievalButton( - 'should return false if get from appConfig returns false and navigation is library content', - '/libraries/some-id', - false, - false - ); - - testCanDisplayKnowledgeRetrievalButton( - 'should return true if get from appConfig returns true and navigation is library content', - '/libraries/some-id', - true, - true - ); - testCanDisplayKnowledgeRetrievalButton( 'should return false if get from appConfig returns false and navigation is libraries', '/libraries', From 5767b2d24bde143daf48442d1e0273e0ae02180b Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Mon, 7 Oct 2024 12:20:10 +0200 Subject: [PATCH 12/14] ACS-8398 Fixed unit tests --- .../lib/testing/document-base-page-utils.ts | 20 ++++++++++++------- .../document-base-page.spec.ts | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/projects/aca-content/src/lib/testing/document-base-page-utils.ts b/projects/aca-content/src/lib/testing/document-base-page-utils.ts index dfb8579845..761db8e558 100644 --- a/projects/aca-content/src/lib/testing/document-base-page-utils.ts +++ b/projects/aca-content/src/lib/testing/document-base-page-utils.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { Subject } from 'rxjs'; +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'; @@ -34,7 +34,7 @@ import { Agent } from '@alfresco/js-api/typings'; export const testHeader = (component: Type, checkHeaderVisibility = true) => { describe('Header', () => { let fixture: ComponentFixture; - let toggleSearchAiInput$: Subject; + let toggleSearchAiInput$: BehaviorSubject; const getSearchAiInputElement = (): DebugElement => fixture.debugElement.query(By.directive(SearchAiInputContainerComponent)); @@ -42,7 +42,9 @@ export const testHeader = (component: Type, checkHea beforeEach(() => { fixture = TestBed.createComponent(component); - toggleSearchAiInput$ = new Subject(); + toggleSearchAiInput$ = new BehaviorSubject({ + searchTerm: '' + } as SearchAiInputState); TestBed.inject(SearchAiService).toggleSearchAiInput$ = toggleSearchAiInput$; spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(new Subject()); fixture.detectChanges(); @@ -50,7 +52,8 @@ export const testHeader = (component: Type, checkHea it('should display ai input if input is active', () => { toggleSearchAiInput$.next({ - active: true + active: true, + searchTerm: '' }); fixture.detectChanges(); @@ -59,7 +62,8 @@ export const testHeader = (component: Type, checkHea it('should not display ai input if input is not active', () => { toggleSearchAiInput$.next({ - active: false + active: false, + searchTerm: '' }); fixture.detectChanges(); @@ -73,7 +77,8 @@ export const testHeader = (component: Type, checkHea if (checkHeaderVisibility) { it('should not display header if input is active', () => { toggleSearchAiInput$.next({ - active: true + active: true, + searchTerm: '' }); fixture.detectChanges(); @@ -82,7 +87,8 @@ export const testHeader = (component: Type, checkHea it('should display header if input is not active', () => { toggleSearchAiInput$.next({ - active: false + active: false, + searchTerm: '' }); fixture.detectChanges(); diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts index fe8ca49444..8dde3db5f0 100644 --- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts +++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts @@ -285,7 +285,7 @@ describe('PageComponent', () => { const searchAiInputState: SearchAiInputState = { active: true }; - TestBed.inject(SearchAiService).toggleSearchAiInput$ = of(searchAiInputState); + searchAiService.toggleSearchAiInput$ = of(searchAiInputState); component.ngOnInit(); expect(component.searchAiInputState).toBe(searchAiInputState); From e1829c962f087a611ecc3533e091ddfaa83c8de8 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Mon, 7 Oct 2024 12:33:10 +0200 Subject: [PATCH 13/14] ACS-8398 Fixed unit tests --- .../src/lib/store/effects/search-ai.effects.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts b/projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts index a82f8b594e..cb187dc128 100644 --- a/projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts +++ b/projects/aca-content/src/lib/store/effects/search-ai.effects.spec.ts @@ -35,6 +35,7 @@ describe('SearchAiEffects', () => { let store: Store; const agentId = '1'; + const searchTerm = 'test'; beforeEach(() => { TestBed.configureTestingModule({ @@ -47,7 +48,6 @@ describe('SearchAiEffects', () => { it('should call navigateToSearchAi on SearchAiNavigationService', () => { const searchAiNavigationService = TestBed.inject(SearchAiNavigationService); spyOn(searchAiNavigationService, 'navigateToSearchAi'); - const searchTerm = 'test'; store.dispatch( new SearchByTermAiAction({ @@ -66,10 +66,11 @@ describe('SearchAiEffects', () => { const searchAiService = TestBed.inject(SearchAiService); spyOn(searchAiService, 'updateSearchAiInputState'); - store.dispatch(new ToggleAISearchInput(agentId)); + store.dispatch(new ToggleAISearchInput(agentId, searchTerm)); expect(searchAiService.updateSearchAiInputState).toHaveBeenCalledWith({ active: true, - selectedAgentId: agentId + selectedAgentId: agentId, + searchTerm }); }); }); From f287164cd500688729d6566e28cfd85a4e1d1922 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Mon, 7 Oct 2024 13:07:34 +0200 Subject: [PATCH 14/14] ACS-8398 Trigger job