Skip to content

Commit

Permalink
[ACS-8907] Remove query / question from input on the results page (#4189
Browse files Browse the repository at this point in the history
)

* [ACS-8907] Remove query / question from input on the results page

* [ACS-8907] Remove query / question from input on the results page
  • Loading branch information
jacekpluta authored Oct 28, 2024
1 parent e743a38 commit 092a57f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[searchTerm]="(inputState$ | async).searchTerm"
[placeholder]="placeholder"
[agentId]="agentId"
[useStoredNodes]="useStoredNodes">
[usedInAiResultsPage]="usedInAiResultsPage">
</aca-search-ai-input>
<mat-divider
[vertical]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ describe('SearchAiInputContainerComponent', () => {
expect(inputComponent.agentId).toBe(component.agentId);
});

it('should have assigned correct useStoredNodes flag', () => {
component.useStoredNodes = true;
it('should have assigned correct usedInAiResultsPage flag', () => {
component.usedInAiResultsPage = true;
fixture.detectChanges();

expect(inputComponent.useStoredNodes).toBeTrue();
expect(inputComponent.usedInAiResultsPage).toBeTrue();
});

it('should set inputState$ to toggleSearchAiInput$ from the service on ngOnInit', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class SearchAiInputContainerComponent implements OnInit {
@Input()
agentId: string;
@Input()
useStoredNodes: boolean;
usedInAiResultsPage: boolean;

inputState$: Observable<SearchAiInputState>;
isKnowledgeRetrievalPage = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ describe('SearchAiInputComponent', () => {
let agents$: Subject<Agent[]>;
let dialog: MatDialog;
let activatedRoute: ActivatedRoute;
let userPreferencesService: UserPreferencesService;
let agentList: Agent[];

const newSelectionState: SelectionState = {
...selectionState,
file: {
entry: {
id: 'some-id'
}
} as NodeEntry
};

const prepareBeforeTest = (): void => {
selectionState = {
nodes: [],
Expand Down Expand Up @@ -94,6 +104,10 @@ describe('SearchAiInputComponent', () => {
loader = TestbedHarnessEnvironment.loader(fixture);
agents$ = new Subject<Agent[]>();
dialog = TestBed.inject(MatDialog);
userPreferencesService = TestBed.inject(UserPreferencesService);
spyOn(userPreferencesService, 'get').and.returnValue(JSON.stringify(newSelectionState));
spyOn(userPreferencesService, 'set');
spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(agents$);
agentList = [
{
id: '1',
Expand All @@ -108,7 +122,6 @@ describe('SearchAiInputComponent', () => {
avatarUrl: undefined
}
];
spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(agents$);
prepareBeforeTest();
});

Expand Down Expand Up @@ -143,12 +156,24 @@ describe('SearchAiInputComponent', () => {
expect(component.queryControl.value).toBe(query);
});

it('should set queryControl value to query param if searchTerm is not defined', () => {
component.searchTerm = undefined;
it('should set queryControl value to "some new query" if usedInAiResultsPage is equal to false', () => {
const query = 'some new query';
component.usedInAiResultsPage = false;
component.searchTerm = query;

component.ngOnInit();

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

it('should set queryControl value to empty string if usedInAiResultsPage is equal to true', () => {
const query = 'some new query';
component.usedInAiResultsPage = true;
component.searchTerm = query;

component.ngOnInit();

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

it('should get agents on init', () => {
Expand Down Expand Up @@ -285,7 +310,6 @@ describe('SearchAiInputComponent', () => {

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

component.ngOnInit();
fixture.detectChanges();

Expand Down Expand Up @@ -320,7 +344,6 @@ describe('SearchAiInputComponent', () => {
describe('Submitting', () => {
let checkSearchAvailabilitySpy: jasmine.Spy<(selectedNodesState: SelectionState, maxSelectedNodes?: number) => string>;
let notificationService: NotificationService;
let userPreferencesService: UserPreferencesService;
let submitButton: DebugElement;
let queryInput: MatInputHarness;
let submittingTrigger: () => void;
Expand All @@ -334,8 +357,6 @@ describe('SearchAiInputComponent', () => {
modalAiService = TestBed.inject(ModalAiService);
checkSearchAvailabilitySpy = spyOn(TestBed.inject(SearchAiService), 'checkSearchAvailability');
notificationService = TestBed.inject(NotificationService);
userPreferencesService = TestBed.inject(UserPreferencesService);
spyOn(userPreferencesService, 'set');
spyOn(notificationService, 'showError');
queryInput = await loader.getHarness(MatInputHarness);
submitButton = fixture.debugElement.query(By.directive(MatButton));
Expand Down Expand Up @@ -376,16 +397,7 @@ describe('SearchAiInputComponent', () => {
});

it('should call checkSearchAvailability on SearchAiService with parameter based on value returned by UserPreferencesService', () => {
component.useStoredNodes = true;
const newSelectionState: SelectionState = {
...selectionState,
file: {
entry: {
id: 'some-id'
}
} as NodeEntry
};
spyOn(userPreferencesService, 'get').and.returnValue(JSON.stringify(newSelectionState));
component.usedInAiResultsPage = true;
component.ngOnInit();
submittingTrigger();

Expand All @@ -400,16 +412,7 @@ describe('SearchAiInputComponent', () => {
});

it('should call set on UserPreferencesService with parameter based on value returned by UserPreferencesService', () => {
component.useStoredNodes = true;
const newSelectionState: SelectionState = {
...selectionState,
file: {
entry: {
id: 'some-id'
}
} as NodeEntry
};
spyOn(userPreferencesService, 'get').and.returnValue(JSON.stringify(newSelectionState));
component.usedInAiResultsPage = true;
component.ngOnInit();
submittingTrigger();

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 { ActivatedRoute } from '@angular/router';

const MatTooltipOptions: MatTooltipDefaultOptions = {
...MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(),
Expand Down Expand Up @@ -87,7 +86,7 @@ export class SearchAiInputComponent implements OnInit, OnDestroy {
agentId: string;

@Input()
useStoredNodes: boolean;
usedInAiResultsPage: boolean;

@Input()
searchTerm: string;
Expand Down Expand Up @@ -124,20 +123,14 @@ export class SearchAiInputComponent implements OnInit, OnDestroy {
private agentService: AgentService,
private userPreferencesService: UserPreferencesService,
private translateService: TranslateService,
private modalAiService: ModalAiService,
private route: ActivatedRoute
private modalAiService: ModalAiService
) {}

ngOnInit(): void {
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);
} else {
this.queryControl.setValue(null);
}
const queryValue = this.usedInAiResultsPage ? '' : this.searchTerm || '';
this.queryControl.setValue(queryValue);

if (!this.useStoredNodes) {
if (!this.usedInAiResultsPage) {
this.store
.select(getAppSelection)
.pipe(takeUntil(this.onDestroy$))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="aca-page-layout-header"
placeholder="KNOWLEDGE_RETRIEVAL.SEARCH.RESULTS_PAGE.QUERY_INPUT_PLACEHOLDER"
[agentId]="agentId"
[useStoredNodes]="true"
[usedInAiResultsPage]="true"
*ngIf="!hasError && agentId">
</aca-search-ai-input-container>
<div
Expand Down

0 comments on commit 092a57f

Please sign in to comment.