Skip to content

Commit

Permalink
[ACS-8907] Remove query / question from input on the results page
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekpluta committed Oct 23, 2024
1 parent b9213f3 commit 48d63ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { MatInputHarness } from '@angular/material/input/testing';
import { SelectionState } from '@alfresco/adf-extensions';
import { MatSnackBarRef } from '@angular/material/snack-bar';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { ModalAiService } from '../../../../services/modal-ai.service';

const agentList: Agent[] = [
Expand All @@ -71,6 +71,9 @@ describe('SearchAiInputComponent', () => {
let agents$: Subject<Agent[]>;
let dialog: MatDialog;
let activatedRoute: ActivatedRoute;
let mockRouter = {
url: '/some-url'
};

const prepareBeforeTest = (): void => {
selectionState = {
Expand All @@ -91,6 +94,7 @@ describe('SearchAiInputComponent', () => {
imports: [SearchAiInputComponent, ContentTestingModule, MatSelectModule],
providers: [
provideMockStore(),
{ provide: Router, useValue: mockRouter },
{
provide: ActivatedRoute,
useValue: {
Expand All @@ -115,6 +119,9 @@ describe('SearchAiInputComponent', () => {

afterEach(() => {
store.resetSelectors();
mockRouter = {
url: '/some-url'
};
});

describe('Agent select box', () => {
Expand Down Expand Up @@ -144,6 +151,26 @@ describe('SearchAiInputComponent', () => {
expect(component.queryControl.value).toBe(query);
});

it('should set queryControl value to empty string if we are on a knowledge-retrieval page', () => {
const query = 'some new query';
mockRouter.url = '/knowledge-retrieval';
component.searchTerm = query;

component.ngOnInit();

expect(component.queryControl.value).toBe('');
});

it('should set queryControl value to "some new query" if we are on a page different than /knowledge-retrieval', () => {
const query = 'some new query';
mockRouter.url = '/';
component.searchTerm = query;

component.ngOnInit();

expect(component.queryControl.value).toBe('some new query');
});

it('should set queryControl value to query param if searchTerm is not defined', () => {
component.searchTerm = undefined;

Expand Down Expand Up @@ -259,7 +286,7 @@ describe('SearchAiInputComponent', () => {

it('should be disabled by default', () => {
activatedRoute.snapshot.queryParams = { query: '' };

mockRouter.url = '/other-page';
component.ngOnInit();
fixture.detectChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
import { ModalAiService } from '../../../../services/modal-ai.service';
import { Agent } from '@alfresco/js-api';
import { getAgentsWithMockedAvatars } from '../search-ai-utils';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';

const MatTooltipOptions: MatTooltipDefaultOptions = {
...MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(),
Expand Down Expand Up @@ -128,11 +128,16 @@ export class SearchAiInputComponent implements OnInit, OnDestroy {
private userPreferencesService: UserPreferencesService,
private translateService: TranslateService,
private modalAiService: ModalAiService,
private route: ActivatedRoute
private route: ActivatedRoute,
private router: Router
) {}

ngOnInit(): void {
if (this.searchTerm) {
const isKnowledgeRetrievalPage = this.router.url.startsWith('/knowledge-retrieval');

if (isKnowledgeRetrievalPage) {
this.queryControl.setValue('');
} else if (this.searchTerm) {
this.queryControl.setValue(this.searchTerm);
} else if (this.route.snapshot?.queryParams?.query?.length > 0) {
this.queryControl.setValue(this.route.snapshot.queryParams.query);
Expand Down

0 comments on commit 48d63ac

Please sign in to comment.