[ACS-8769] Removed mocked avatars and replaced with loading them from backend (#4207)

This commit is contained in:
AleksanderSklorz 2024-10-28 09:04:26 +01:00 committed by GitHub
parent 3cda94558d
commit e743a38117
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 54 additions and 67 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

View File

@ -81,7 +81,6 @@ describe('AgentsButtonComponent', () => {
notificationService = TestBed.inject(NotificationService);
spyOn(notificationService, 'showError');
message = 'Some message';
component.avatarsMocked = false;
});
const getMenuTrigger = (): MatMenuPanel => fixture.debugElement.query(By.directive(MatMenuTrigger)).injector.get(MatMenuTrigger).menu;
@ -226,7 +225,6 @@ describe('AgentsButtonComponent', () => {
describe('loaded config', () => {
beforeEach(() => {
component.avatarsMocked = false;
config$.next({
entry: {
knowledgeRetrievalUrl
@ -337,7 +335,6 @@ describe('AgentsButtonComponent', () => {
let loader: HarnessLoader;
const prepareData = (agents: Agent[]): void => {
component.avatarsMocked = false;
config$.next({
entry: {
knowledgeRetrievalUrl
@ -431,9 +428,18 @@ describe('AgentsButtonComponent', () => {
expect(getAvatar('1').initials).toBe('HA');
expect(getAvatar('2').initials).toBe('PA');
});
it('should assign correct src to each avatar', () => {
agentsMock[0].avatarUrl = 'some-url-1';
agentsMock[1].avatarUrl = 'some-url-2';
fixture.detectChanges();
expect(getAvatar('1').src).toBe('some-url-1');
expect(getAvatar('2').src).toBe('some-url-2');
});
});
describe('Agents multi words name', () => {
describe('Agents single word name', () => {
it('should assign correct initials to each avatar for each agent with single section name', () => {
agentsMock = [
{

View File

@ -36,7 +36,6 @@ import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { Agent } from '@alfresco/js-api';
import { AgentService, SearchAiService } from '@alfresco/adf-content-services';
import { MatTooltipModule } from '@angular/material/tooltip';
import { getAgentsWithMockedAvatars } from '../search-ai-utils';
@Component({
standalone: true,
@ -58,8 +57,6 @@ export class AgentsButtonComponent implements OnInit, OnDestroy {
private _initialsByAgentId: { [key: string]: string } = {};
private _hxInsightUrl: string;
avatarsMocked = true;
get agents(): Agent[] {
return this._agents;
}
@ -103,9 +100,6 @@ export class AgentsButtonComponent implements OnInit, OnDestroy {
this._hxInsightUrl = result.config.entry.knowledgeRetrievalUrl;
this._agents = result.agents;
// TODO remove mocked avatar images after backend is done (https://hyland.atlassian.net/browse/ACS-8769)
this._agents = getAgentsWithMockedAvatars(result.agents, this.avatarsMocked);
this.cd.detectChanges();
if (this.agents.length) {

View File

@ -47,21 +47,6 @@ import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dial
import { ActivatedRoute } from '@angular/router';
import { ModalAiService } from '../../../../services/modal-ai.service';
const agentList: Agent[] = [
{
id: '1',
name: 'HR Agent',
description: 'Test 1',
avatarUrl: undefined
},
{
id: '2',
name: 'Policy Agent',
description: 'Test 2',
avatarUrl: undefined
}
];
describe('SearchAiInputComponent', () => {
let component: SearchAiInputComponent;
let fixture: ComponentFixture<SearchAiInputComponent>;
@ -71,6 +56,7 @@ describe('SearchAiInputComponent', () => {
let agents$: Subject<Agent[]>;
let dialog: MatDialog;
let activatedRoute: ActivatedRoute;
let agentList: Agent[];
const prepareBeforeTest = (): void => {
selectionState = {
@ -81,7 +67,6 @@ describe('SearchAiInputComponent', () => {
};
store.overrideSelector(getAppSelection, selectionState);
component.agentId = '2';
component.avatarsMocked = false;
component.ngOnInit();
fixture.detectChanges();
};
@ -109,6 +94,20 @@ describe('SearchAiInputComponent', () => {
loader = TestbedHarnessEnvironment.loader(fixture);
agents$ = new Subject<Agent[]>();
dialog = TestBed.inject(MatDialog);
agentList = [
{
id: '1',
name: 'HR Agent',
description: 'Test 1',
avatarUrl: undefined
},
{
id: '2',
name: 'Policy Agent',
description: 'Test 2',
avatarUrl: undefined
}
];
spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(agents$);
prepareBeforeTest();
});
@ -170,11 +169,15 @@ describe('SearchAiInputComponent', () => {
});
it('should have selected correct agent', async () => {
agentList[0].avatarUrl = 'some-url-1';
agentList[1].avatarUrl = 'some-url-2';
agents$.next(agentList);
expect(await (await loader.getHarness(MatSelectHarness)).getValueText()).toBe('PAPolicy Agent');
expect(await (await loader.getHarness(MatSelectHarness)).getValueText()).toBe('Policy Agent');
const avatar = selectElement.query(By.directive(AvatarComponent))?.componentInstance;
expect(avatar.initials).toBe('PA');
expect(avatar.size).toBe('26px');
expect(avatar.src).toBe('some-url-2');
});
describe('Agents options', () => {
@ -210,6 +213,15 @@ describe('SearchAiInputComponent', () => {
expect(getAvatarForAgent('2').initials).toBe('PA');
});
it('should have correct initials for avatars for each of agent', () => {
agentList[0].avatarUrl = 'some-url-1';
agentList[1].avatarUrl = 'some-url-2';
fixture.detectChanges();
expect(getAvatarForAgent('1').src).toBe('some-url-1');
expect(getAvatarForAgent('2').src).toBe('some-url-2');
});
it('should assign correct initials to each avatar for each agent with single section name', () => {
const newAgentList = [
{ ...agentList[0], name: 'Adam' },
@ -224,6 +236,20 @@ describe('SearchAiInputComponent', () => {
});
});
describe('Agents popup', () => {
it('should have selected correct agent', () => {
agentList[0].avatarUrl = 'some-url-1';
agentList[1].avatarUrl = 'some-url-2';
agents$.next(agentList);
fixture.detectChanges();
fixture.debugElement.query(By.css('.aca-search-ai-input-agent-container')).nativeElement.dispatchEvent(new MouseEvent('mouseenter'));
expect(fixture.debugElement.query(By.css('.aca-search-ai-input-agent-popup-hover-card-container-title adf-avatar')).componentInstance.src).toBe(
'some-url-2'
);
});
});
describe('Query input', () => {
let queryInput: DebugElement;

View File

@ -48,7 +48,6 @@ import {
} from '@angular/material/tooltip';
import { ModalAiService } from '../../../../services/modal-ai.service';
import { Agent } from '@alfresco/js-api';
import { getAgentsWithMockedAvatars } from '../search-ai-utils';
import { ActivatedRoute } from '@angular/router';
const MatTooltipOptions: MatTooltipDefaultOptions = {
@ -102,8 +101,6 @@ export class SearchAiInputComponent implements OnInit, OnDestroy {
private _queryControl = new FormControl('');
private _initialsByAgentId: { [key: string]: string } = {};
avatarsMocked = true;
get agentControl(): FormControl<Agent> {
return this._agentControl;
}
@ -156,8 +153,7 @@ export class SearchAiInputComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.onDestroy$))
.subscribe(
(agents) => {
// TODO remove mocked avatar images after backend is done (https://hyland.atlassian.net/browse/ACS-8769)
this._agents = getAgentsWithMockedAvatars(agents, this.avatarsMocked);
this._agents = agents;
this.agentControl.setValue(this._agents.find((agent) => agent.id === this.agentId));
this._initialsByAgentId = this.agents.reduce((initials, agent) => {

View File

@ -1,35 +0,0 @@
/*!
* 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 { Agent } from '@alfresco/js-api/typings';
export const getAgentsWithMockedAvatars = (agents: Agent[], mocked: boolean) => {
if (mocked) {
const images = ['assets/images/agent-avatar-blue.png', 'assets/images/agent-avatar-gold.png', 'assets/images/agent-avatar-pink.png'];
return agents.map((agent, index) => {
return { ...agent, avatarUrl: images[index > 2 ? 2 : index] };
});
}
return agents;
};