From dece904bb8def9d3f9748a81c88a87b2dfa60958 Mon Sep 17 00:00:00 2001 From: Florian Glombik <63976129+florian-glombik@users.noreply.github.com> Date: Sat, 30 Nov 2024 22:41:26 +0100 Subject: [PATCH 1/2] Lectures: Improve lecture attachment validation (#9893) --- .../lecture-attachments.component.html | 50 ++++--- .../lecture-attachments.component.scss | 4 + .../lecture/lecture-attachments.component.ts | 124 +++++++++++++----- .../lecture-attachments.component.spec.ts | 82 +++++++----- 4 files changed, 169 insertions(+), 91 deletions(-) diff --git a/src/main/webapp/app/lecture/lecture-attachments.component.html b/src/main/webapp/app/lecture/lecture-attachments.component.html index 6192f270d64e..82050a7c3efe 100644 --- a/src/main/webapp/app/lecture/lecture-attachments.component.html +++ b/src/main/webapp/app/lecture/lecture-attachments.component.html @@ -44,7 +44,6 @@

- @@ -53,25 +52,25 @@

@for (attachment of attachments; track trackId($index, attachment)) { - + {{ attachment.id }} - {{ attachment.name }} - {{ attachment.attachmentType }} @if (!isDownloadingAttachmentLink) { {{ attachment.name }} - } - @if (isDownloadingAttachmentLink === attachment.link) { + } @else if (isDownloadingAttachmentLink === attachment.link) { {{ 'artemisApp.courseOverview.lectureDetails.isDownloading' | artemisTranslate }} + } @else { + {{ attachment.name }} } + {{ attachment.attachmentType }} {{ attachment.releaseDate | artemisDate }} {{ attachment.uploadDate | artemisDate }} @@ -91,7 +90,7 @@

} @@ -207,9 +204,8 @@

- - } - @if (!attachmentToBeCreated) { + + } @else {
diff --git a/src/test/javascript/spec/component/iris/ui/iris-base-chatbot.component.spec.ts b/src/test/javascript/spec/component/iris/ui/iris-base-chatbot.component.spec.ts index 1bad06bcbba7..a5a0334dbc33 100644 --- a/src/test/javascript/spec/component/iris/ui/iris-base-chatbot.component.spec.ts +++ b/src/test/javascript/spec/component/iris/ui/iris-base-chatbot.component.spec.ts @@ -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));