diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts index 1b0b81e50..f23e51d77 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts @@ -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(); + }); }); } }); diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts index a3533dbcc..4fb6f7ab8 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts @@ -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(); } } } diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.scss b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.scss index 409be4699..ff9cd8cf1 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.scss +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.scss @@ -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; diff --git a/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts b/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts index ce2782bae..1510e939d 100644 --- a/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts +++ b/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts @@ -108,6 +108,6 @@ describe('SidenavComponent', () => { component.ngOnInit(); routerEvents$.next(mockNavigationEnd); - expect(navigationHistoryService.setHistory).toHaveBeenCalledWith(mockNavigationEnd, 3); + expect(navigationHistoryService.setHistory).toHaveBeenCalledWith(mockNavigationEnd); }); }); diff --git a/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts b/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts index 1b6d0700c..7dc1743a3 100755 --- a/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts +++ b/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts @@ -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); }); } diff --git a/projects/aca-shared/src/lib/services/navigation-history.service.spec.ts b/projects/aca-shared/src/lib/services/navigation-history.service.spec.ts index 6d4bec1f9..baa24f725 100644 --- a/projects/aca-shared/src/lib/services/navigation-history.service.spec.ts +++ b/projects/aca-shared/src/lib/services/navigation-history.service.spec.ts @@ -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')); diff --git a/projects/aca-shared/src/lib/services/navigation-history.service.ts b/projects/aca-shared/src/lib/services/navigation-history.service.ts index 6db2a1639..5bb175514 100644 --- a/projects/aca-shared/src/lib/services/navigation-history.service.ts +++ b/projects/aca-shared/src/lib/services/navigation-history.service.ts @@ -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(); - } } }