Skip to content

Commit

Permalink
[ACS-8769] Removed mocked avatars and replaced with loading them from…
Browse files Browse the repository at this point in the history
… backend (#4207)
  • Loading branch information
AleksanderSklorz authored Oct 28, 2024
1 parent 3cda945 commit e743a38
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 67 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -226,7 +225,6 @@ describe('AgentsButtonComponent', () => {

describe('loaded config', () => {
beforeEach(() => {
component.avatarsMocked = false;
config$.next({
entry: {
knowledgeRetrievalUrl
Expand Down Expand Up @@ -337,7 +335,6 @@ describe('AgentsButtonComponent', () => {
let loader: HarnessLoader;

const prepareData = (agents: Agent[]): void => {
component.avatarsMocked = false;
config$.next({
entry: {
knowledgeRetrievalUrl
Expand Down Expand Up @@ -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 = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -71,6 +56,7 @@ describe('SearchAiInputComponent', () => {
let agents$: Subject<Agent[]>;
let dialog: MatDialog;
let activatedRoute: ActivatedRoute;
let agentList: Agent[];

const prepareBeforeTest = (): void => {
selectionState = {
Expand All @@ -81,7 +67,6 @@ describe('SearchAiInputComponent', () => {
};
store.overrideSelector(getAppSelection, selectionState);
component.agentId = '2';
component.avatarsMocked = false;
component.ngOnInit();
fixture.detectChanges();
};
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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' },
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) => {
Expand Down

This file was deleted.

0 comments on commit e743a38

Please sign in to comment.