Skip to content

Commit

Permalink
chore: Hide suggestions during response generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kaancayli committed Nov 30, 2024
1 parent dece904 commit 06f09d1
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ <h4 class="modal-title">
<div class="chat-body" [class.not-accepted]="!userAccepted" #chatBody>
@if (messages?.length) {
<div class="messages" #messagesElement (scroll)="checkChatScroll()">
@if (suggestions?.length) {
@if (
suggestions?.length &&
userAccepted &&
!this.isLoading &&
this.active &&
(!this.rateLimitInfo?.rateLimit || this.rateLimitInfo?.currentMessageCount !== this.rateLimitInfo?.rateLimit) &&
!this.hasActiveStage
) {
<div @suggestionAnimation class="suggestions-container">
@for (suggestion of suggestions; track suggestion) {
<button class="suggestion-button" (click)="onSuggestionClick(suggestion)" [innerHTML]="suggestion"></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,96 @@ describe('IrisBaseChatbotComponent', () => {
expect(suggestionButtons).toHaveLength(0);
});

it('should not render suggestions if isLoading is true', () => {
// Arrange
const expectedSuggestions = ['suggestion1', 'suggestion2'];
const mockMessages = [mockClientMessage, mockServerMessage];

jest.spyOn(chatService, 'currentSuggestions').mockReturnValue(of(expectedSuggestions));
jest.spyOn(chatService, 'currentMessages').mockReturnValue(of(mockMessages));

// Act
component.ngOnInit();
component.isLoading = true;
fixture.detectChanges();

// Assert
const suggestionButtons = fixture.nativeElement.querySelectorAll('.suggestion-button');
expect(suggestionButtons).toHaveLength(0);
});

it('should not render suggestions if userAccepted is false', () => {
// Arrange
const expectedSuggestions = ['suggestion1', 'suggestion2'];
const mockMessages = [mockClientMessage, mockServerMessage];

jest.spyOn(chatService, 'currentSuggestions').mockReturnValue(of(expectedSuggestions));
jest.spyOn(chatService, 'currentMessages').mockReturnValue(of(mockMessages));

// Act
component.ngOnInit();
component.userAccepted = false;
fixture.detectChanges();

// Assert
const suggestionButtons = fixture.nativeElement.querySelectorAll('.suggestion-button');
expect(suggestionButtons).toHaveLength(0);
});

it('should not render suggestions if the rate limit is exceeded', () => {
// Arrange
const expectedSuggestions = ['suggestion1', 'suggestion2'];
const mockMessages = [mockClientMessage, mockServerMessage];

jest.spyOn(chatService, 'currentSuggestions').mockReturnValue(of(expectedSuggestions));
jest.spyOn(chatService, 'currentMessages').mockReturnValue(of(mockMessages));

// Act
component.ngOnInit();
component.rateLimitInfo = { currentMessageCount: 100, rateLimit: 100, rateLimitTimeframeHours: 1 };
fixture.detectChanges();

// Assert
const suggestionButtons = fixture.nativeElement.querySelectorAll('.suggestion-button');
expect(suggestionButtons).toHaveLength(0);
});

it('should not render suggestions if the user is not active', () => {
// Arrange
const expectedSuggestions = ['suggestion1', 'suggestion2'];
const mockMessages = [mockClientMessage, mockServerMessage];

jest.spyOn(chatService, 'currentSuggestions').mockReturnValue(of(expectedSuggestions));
jest.spyOn(chatService, 'currentMessages').mockReturnValue(of(mockMessages));

// Act
component.ngOnInit();
component.active = false;
fixture.detectChanges();

// Assert
const suggestionButtons = fixture.nativeElement.querySelectorAll('.suggestion-button');
expect(suggestionButtons).toHaveLength(0);
});

it('should not render suggestions if hasActiveStage is true', () => {
// Arrange
const expectedSuggestions = ['suggestion1', 'suggestion2'];
const mockMessages = [mockClientMessage, mockServerMessage];

jest.spyOn(chatService, 'currentSuggestions').mockReturnValue(of(expectedSuggestions));
jest.spyOn(chatService, 'currentMessages').mockReturnValue(of(mockMessages));

// Act
component.ngOnInit();
component.hasActiveStage = true;
fixture.detectChanges();

// Assert
const suggestionButtons = fixture.nativeElement.querySelectorAll('.suggestion-button');
expect(suggestionButtons).toHaveLength(0);
});

describe('clear chat session', () => {
it('should open confirm modal when click on the clear button', fakeAsync(() => {
jest.spyOn(httpService, 'getCurrentSessionOrCreateIfNotExists').mockReturnValueOnce(of(mockServerSessionHttpResponse));
Expand Down

0 comments on commit 06f09d1

Please sign in to comment.