Skip to content

Commit a55e563

Browse files
google-genai-botcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 855622856
1 parent be1b2e3 commit a55e563

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

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

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ describe('ChatComponent', () => {
175175
mockFeatureFlagService.isTokenStreamingEnabledResponse.next(true);
176176
mockFeatureFlagService.isEventFilteringEnabledResponse.next(true);
177177
mockFeatureFlagService.isDeleteSessionEnabledResponse.next(true);
178-
mockFeatureFlagService.isInfinityMessageScrollingEnabledResponse.next(false);
178+
mockFeatureFlagService.isInfinityMessageScrollingEnabledResponse.next(
179+
false);
179180

180181
mockDialog = jasmine.createSpyObj('MatDialog', ['open']);
181182
mockSnackBar = jasmine.createSpyObj('MatSnackBar', ['open']);
@@ -934,24 +935,51 @@ describe('ChatComponent', () => {
934935
.toContain(TEST_MESSAGE);
935936
});
936937

937-
it(
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'};
941-
mockRouter.parseUrl.and.returnValue(urlTree as any);
942-
mockLocation.path.and.returnValue('/?q=hello');
943-
944-
fixture = TestBed.createComponent(ChatComponent);
945-
component = fixture.componentInstance;
946-
component.userInput = 'hello';
947-
component.sendMessage(new KeyboardEvent('keydown', {key: 'Enter'}));
948-
tick();
949-
950-
expect(mockLocation.path).toHaveBeenCalled();
951-
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?q=hello');
952-
// The query param should be removed from the URL.
953-
expect(mockLocation.replaceState).toHaveBeenCalledWith('/');
954-
}));
938+
describe('Query Param Handling', () => {
939+
let urlTree: UrlTree;
940+
941+
beforeEach(() => {
942+
urlTree = new UrlTree();
943+
fixture = TestBed.createComponent(ChatComponent);
944+
component = fixture.componentInstance;
945+
component.userInput = 'hello';
946+
});
947+
948+
it(
949+
'should clear "q" param on send',
950+
fakeAsync(() => {
951+
urlTree.queryParams = {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'};
952+
mockRouter.parseUrl.and.returnValue(urlTree as any);
953+
mockLocation.path.and.returnValue('/?q=hello');
954+
955+
component.sendMessage(
956+
new KeyboardEvent('keydown', {key: 'Enter'}));
957+
tick();
958+
959+
expect(mockLocation.path).toHaveBeenCalled();
960+
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?q=hello');
961+
// The query param should be removed from the URL.
962+
expect(mockLocation.replaceState).toHaveBeenCalledWith('/');
963+
}));
964+
965+
it(
966+
'should not update URL if "q" param is missing',
967+
fakeAsync(() => {
968+
urlTree.queryParams = {};
969+
mockRouter.parseUrl.and.returnValue(urlTree as any);
970+
mockLocation.path.and.returnValue('/?');
971+
972+
component.sendMessage(
973+
new KeyboardEvent('keydown', {key: 'Enter'}));
974+
tick();
975+
976+
expect(mockLocation.path).toHaveBeenCalled();
977+
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?');
978+
// The query param should be removed from the URL.
979+
expect(mockLocation.replaceState).not.toHaveBeenCalled();
980+
}));
981+
});
982+
955983

956984
describe('when event contains multiple text parts', () => {
957985
it(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,10 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
593593
this.userInput = '';
594594
// Clear the query param for the initial user input once it is sent.
595595
const updatedUrl = this.router.parseUrl(this.location.path());
596-
delete updatedUrl.queryParams[INITIAL_USER_INPUT_QUERY_PARAM];
597-
this.location.replaceState(updatedUrl.toString());
596+
if (updatedUrl.queryParams[INITIAL_USER_INPUT_QUERY_PARAM]) {
597+
delete updatedUrl.queryParams[INITIAL_USER_INPUT_QUERY_PARAM];
598+
this.location.replaceState(updatedUrl.toString());
599+
}
598600
this.changeDetectorRef.detectChanges();
599601
}
600602

0 commit comments

Comments
 (0)