Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iris: Hide suggestions during response generation #9919

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
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
Loading