Skip to content

Commit be1b2e3

Browse files
reniowoodcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 855510046
1 parent 5deef73 commit be1b2e3

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/app/components/chat/chat.component.spec.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {MatDialog, MatDialogModule} from '@angular/material/dialog';
2323
import {MatSnackBar} from '@angular/material/snack-bar';
2424
import {By} from '@angular/platform-browser';
2525
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
26-
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
26+
import {ActivatedRoute, NavigationEnd, Router, UrlTree} from '@angular/router';
2727
// 1p-ONLY-IMPORTS: import {beforeEach, describe, expect, it}
2828
import {BehaviorSubject, NEVER, of, ReplaySubject, Subject, throwError} from 'rxjs';
2929

@@ -935,32 +935,22 @@ describe('ChatComponent', () => {
935935
});
936936

937937
it(
938-
'should clear "q" query param when message is sent',
939-
fakeAsync(() => {
940-
mockAgentService.setApp(''); // Initially no app
941-
mockActivatedRoute.snapshot!
942-
.queryParams = {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'};
943-
mockActivatedRoute.queryParams =
944-
of({[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'});
945-
const urlTree = {
946-
queryParams: {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'},
947-
};
938+
'should clear "q" query param when message is sent', fakeAsync(() => {
939+
const urlTree = new UrlTree();
940+
urlTree.queryParams = {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'};
948941
mockRouter.parseUrl.and.returnValue(urlTree as any);
949942
mockLocation.path.and.returnValue('/?q=hello');
943+
950944
fixture = TestBed.createComponent(ChatComponent);
951945
component = fixture.componentInstance;
952-
fixture.detectChanges();
953-
mockAgentService.setApp(TEST_APP_1_NAME);
954-
tick();
955-
946+
component.userInput = 'hello';
956947
component.sendMessage(new KeyboardEvent('keydown', {key: 'Enter'}));
957948
tick();
958949

959950
expect(mockLocation.path).toHaveBeenCalled();
960951
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?q=hello');
961-
expect(urlTree.queryParams).toEqual({} as any); // q param should be
962-
// deleted.
963-
expect(mockRouter.navigateByUrl).toHaveBeenCalledWith(urlTree as any);
952+
// The query param should be removed from the URL.
953+
expect(mockLocation.replaceState).toHaveBeenCalledWith('/');
964954
}));
965955

966956
describe('when event contains multiple text parts', () => {

src/app/components/chat/chat.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
594594
// Clear the query param for the initial user input once it is sent.
595595
const updatedUrl = this.router.parseUrl(this.location.path());
596596
delete updatedUrl.queryParams[INITIAL_USER_INPUT_QUERY_PARAM];
597-
await this.router.navigateByUrl(updatedUrl);
597+
this.location.replaceState(updatedUrl.toString());
598598
this.changeDetectorRef.detectChanges();
599599
}
600600

0 commit comments

Comments
 (0)