[ACS-9546] knowledge retrieval question is repeated when new question is asked (#4555)

* [ACS-9546] Fixed repeating displayed question for knowledge retrieval

* [ACS-9546] Fixed not displayed border around answer

* [ACS-9546] Unit tests
This commit is contained in:
AleksanderSklorz 2025-05-08 15:23:57 +02:00 committed by GitHub
parent b4530e43b9
commit 2be3b94077
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 42 additions and 39 deletions

View File

@ -465,6 +465,13 @@ describe('SearchAiInputComponent', () => {
submittingTrigger();
expect(modalAiSpy).toHaveBeenCalledWith(jasmine.any(Function));
});
it('should call reset on queryControl', () => {
spyOn(component.queryControl, 'reset');
submittingTrigger();
expect(component.queryControl.reset).toHaveBeenCalled();
});
});
}
});

View File

@ -163,7 +163,7 @@ export class SearchAiInputComponent implements OnInit {
this.modalAiService.openUnsavedChangesModal(() => this.search());
}
search() {
private search(): void {
const error = this.searchAiService.checkSearchAvailability(this.selectedNodesState);
if (error) {
this.notificationService.showError(error);
@ -175,6 +175,7 @@ export class SearchAiInputComponent implements OnInit {
this.userPreferencesService.set(this.storedNodesKey, JSON.stringify(this.selectedNodesState));
this.store.dispatch(new SearchByTermAiAction(payload));
this.store.dispatch(new ToggleAISearchInput(this.agentControl.value.id, this.queryControl.value));
this.queryControl.reset();
}
}
}

View File

@ -32,7 +32,7 @@
padding: 18px 20px;
display: flex;
flex-direction: column;
border: 1px solid var(--adf-card-view-border-color);
border: 1px solid var(--adf-theme-foreground-divider-color);
border-radius: 12px;
margin: 16px 0 75px;

View File

@ -108,6 +108,6 @@ describe('SidenavComponent', () => {
component.ngOnInit();
routerEvents$.next(mockNavigationEnd);
expect(navigationHistoryService.setHistory).toHaveBeenCalledWith(mockNavigationEnd, 3);
expect(navigationHistoryService.setHistory).toHaveBeenCalledWith(mockNavigationEnd);
});
});

View File

@ -78,7 +78,7 @@ export class SidenavComponent implements OnInit {
.listenToRouteChanges()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((event: NavigationEnd) => {
this.navigationHistoryService.setHistory(event, 3);
this.navigationHistoryService.setHistory(event);
});
}

View File

@ -46,40 +46,13 @@ describe('NavigationHistoryService', () => {
});
it('should store route changes in history', () => {
service.listenToRouteChanges().subscribe((event) => service.setHistory(event, 3));
service.listenToRouteChanges().subscribe((event) => service.setHistory(event));
triggerNavigationEnd(1, '/page1');
triggerNavigationEnd(2, '/page2');
expect(service.history).toEqual(['/initial', '/page1', '/page2']);
});
it('should not exceed the max history length', () => {
service.listenToRouteChanges().subscribe((event) => service.setHistory(event, 6));
triggerNavigationEnd(1, '/page1');
triggerNavigationEnd(2, '/page2');
triggerNavigationEnd(3, '/page3');
triggerNavigationEnd(4, '/page4');
triggerNavigationEnd(5, '/page5');
triggerNavigationEnd(6, '/page6');
expect(service.history).toEqual(['/page1', '/page2', '/page3', '/page4', '/page5', '/page6']);
});
it('should store different route changes in history', () => {
service.listenToRouteChanges().subscribe((event) => service.setHistory(event, 4));
triggerNavigationEnd(1, '/page1');
triggerNavigationEnd(2, '/page2');
triggerNavigationEnd(3, '/page1');
triggerNavigationEnd(4, '/page2');
triggerNavigationEnd(5, '/page4');
triggerNavigationEnd(6, '/page2');
triggerNavigationEnd(7, '/page1');
triggerNavigationEnd(8, '/page2');
expect(service.history).toEqual(['/page4', '/page2', '/page1', '/page2']);
});
it('should return true for a valid last selection', () => {
service.history = ['/page1', '/page2', '/page1'];
@ -92,13 +65,31 @@ describe('NavigationHistoryService', () => {
expect(service.shouldReturnLastSelection('/page2')).toBeFalse();
});
it('should return true for a valid last selection when before first relevant url and before last url there are multiple urls', () => {
service.history = ['/page1', '/page2', '/page3', '/page4', '/page4', '/page3'];
expect(service.shouldReturnLastSelection('/page4')).toBeTrue();
});
it('should return false for an invalid last selection when before first relevant url and before last url there are multiple urls', () => {
service.history = ['/page1', '/page2', '/page3', '/page4', '/page4', '/page3'];
expect(service.shouldReturnLastSelection('/page5')).toBeFalse();
});
it('should return false for an invalid last url when before first relevant url and before last url there are multiple urls', () => {
service.history = ['/page1', '/page2', '/page3', '/page4', '/page4', '/page5'];
expect(service.shouldReturnLastSelection('/page4')).toBeFalse();
});
it('should initialize history with the current route', () => {
service.listenToRouteChanges().subscribe((event) => service.setHistory(event, 3));
service.listenToRouteChanges().subscribe((event) => service.setHistory(event));
expect(service.history).toEqual(['/initial']);
});
it('should only store NavigationEnd events in history', () => {
service.listenToRouteChanges().subscribe((event) => service.setHistory(event, 3));
service.listenToRouteChanges().subscribe((event) => service.setHistory(event));
routerEvents$.next(new NavigationStart(1, '/page-start'));
routerEvents$.next(new NavigationEnd(1, '/page1', '/page1'));

View File

@ -41,13 +41,17 @@ export class NavigationHistoryService {
}
shouldReturnLastSelection(url: string): boolean {
return this.history.length > 2 && this.history[1].startsWith(url) && this.history[0] === this.history[2];
return (
this.history.length > 2 &&
this.history[this.history.length - 2].startsWith(url) &&
[...this.history]
.reverse()
.slice(1)
.find((oldUrl) => !oldUrl.startsWith(url)) === this.history[this.history.length - 1]
);
}
setHistory(event: NavigationEnd, maxHistoryLength: number) {
setHistory(event: NavigationEnd): void {
this.history.push(event.urlAfterRedirects);
if (maxHistoryLength > 0 && this.history.length > maxHistoryLength) {
this.history.shift();
}
}
}