Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/app/components/chat/chat.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {MatDialog, MatDialogModule} from '@angular/material/dialog';
import {MatSnackBar} from '@angular/material/snack-bar';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
import {ActivatedRoute, NavigationEnd, Router, UrlTree} from '@angular/router';
// 1p-ONLY-IMPORTS: import {beforeEach, describe, expect, it}
import {BehaviorSubject, NEVER, of, ReplaySubject, Subject, throwError} from 'rxjs';

Expand Down Expand Up @@ -935,32 +935,22 @@ describe('ChatComponent', () => {
});

it(
'should clear "q" query param when message is sent',
fakeAsync(() => {
mockAgentService.setApp(''); // Initially no app
mockActivatedRoute.snapshot!
.queryParams = {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'};
mockActivatedRoute.queryParams =
of({[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'});
const urlTree = {
queryParams: {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'},
};
'should clear "q" query param when message is sent', fakeAsync(() => {
const urlTree = new UrlTree();
urlTree.queryParams = {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'};
mockRouter.parseUrl.and.returnValue(urlTree as any);
mockLocation.path.and.returnValue('/?q=hello');

fixture = TestBed.createComponent(ChatComponent);
component = fixture.componentInstance;
fixture.detectChanges();
mockAgentService.setApp(TEST_APP_1_NAME);
tick();

component.userInput = 'hello';
component.sendMessage(new KeyboardEvent('keydown', {key: 'Enter'}));
tick();

expect(mockLocation.path).toHaveBeenCalled();
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?q=hello');
expect(urlTree.queryParams).toEqual({} as any); // q param should be
// deleted.
expect(mockRouter.navigateByUrl).toHaveBeenCalledWith(urlTree as any);
// The query param should be removed from the URL.
expect(mockLocation.replaceState).toHaveBeenCalledWith('/');
}));

describe('when event contains multiple text parts', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
// Clear the query param for the initial user input once it is sent.
const updatedUrl = this.router.parseUrl(this.location.path());
delete updatedUrl.queryParams[INITIAL_USER_INPUT_QUERY_PARAM];
await this.router.navigateByUrl(updatedUrl);
this.location.replaceState(updatedUrl.toString());
this.changeDetectorRef.detectChanges();
}

Expand Down
Loading