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
66 changes: 47 additions & 19 deletions src/app/components/chat/chat.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ describe('ChatComponent', () => {
mockFeatureFlagService.isTokenStreamingEnabledResponse.next(true);
mockFeatureFlagService.isEventFilteringEnabledResponse.next(true);
mockFeatureFlagService.isDeleteSessionEnabledResponse.next(true);
mockFeatureFlagService.isInfinityMessageScrollingEnabledResponse.next(false);
mockFeatureFlagService.isInfinityMessageScrollingEnabledResponse.next(
false);

mockDialog = jasmine.createSpyObj('MatDialog', ['open']);
mockSnackBar = jasmine.createSpyObj('MatSnackBar', ['open']);
Expand Down Expand Up @@ -934,24 +935,51 @@ describe('ChatComponent', () => {
.toContain(TEST_MESSAGE);
});

it(
'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;
component.userInput = 'hello';
component.sendMessage(new KeyboardEvent('keydown', {key: 'Enter'}));
tick();

expect(mockLocation.path).toHaveBeenCalled();
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?q=hello');
// The query param should be removed from the URL.
expect(mockLocation.replaceState).toHaveBeenCalledWith('/');
}));
describe('Query Param Handling', () => {
let urlTree: UrlTree;

beforeEach(() => {
urlTree = new UrlTree();
fixture = TestBed.createComponent(ChatComponent);
component = fixture.componentInstance;
component.userInput = 'hello';
});

it(
'should clear "q" param on send',
fakeAsync(() => {
urlTree.queryParams = {[INITIAL_USER_INPUT_QUERY_PARAM]: 'hello'};
mockRouter.parseUrl.and.returnValue(urlTree as any);
mockLocation.path.and.returnValue('/?q=hello');

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

expect(mockLocation.path).toHaveBeenCalled();
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?q=hello');
// The query param should be removed from the URL.
expect(mockLocation.replaceState).toHaveBeenCalledWith('/');
}));

it(
'should not update URL if "q" param is missing',
fakeAsync(() => {
urlTree.queryParams = {};
mockRouter.parseUrl.and.returnValue(urlTree as any);
mockLocation.path.and.returnValue('/?');

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

expect(mockLocation.path).toHaveBeenCalled();
expect(mockRouter.parseUrl).toHaveBeenCalledWith('/?');
// The query param should be removed from the URL.
expect(mockLocation.replaceState).not.toHaveBeenCalled();
}));
});


describe('when event contains multiple text parts', () => {
it(
Expand Down
6 changes: 4 additions & 2 deletions src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,10 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.userInput = '';
// 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];
this.location.replaceState(updatedUrl.toString());
if (updatedUrl.queryParams[INITIAL_USER_INPUT_QUERY_PARAM]) {
delete updatedUrl.queryParams[INITIAL_USER_INPUT_QUERY_PARAM];
this.location.replaceState(updatedUrl.toString());
}
this.changeDetectorRef.detectChanges();
}

Expand Down
Loading