From 0c8eefef0cffe5109688d673d70d3b97d31d1d53 Mon Sep 17 00:00:00 2001 From: Paul Rangger <48455539+PaRangger@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:06:27 +0100 Subject: [PATCH] Communication: Fix scrolling error for long messages (#9997) --- .../conversation-messages.component.ts | 2 +- .../conversation-messages.component.spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts b/src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts index 17342052df52..ddac0b0efacb 100644 --- a/src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts +++ b/src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts @@ -441,7 +441,7 @@ export class ConversationMessagesComponent implements OnInit, AfterViewInit, OnD } } this.elementsAtScrollPosition = visibleMessages; - if (this.elementsAtScrollPosition && this.canStartSaving) { + if (this.elementsAtScrollPosition && this.elementsAtScrollPosition.length > 0 && this.canStartSaving) { this.saveScrollPosition(this.elementsAtScrollPosition[0].post.id!); } } diff --git a/src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts b/src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts index 9884da1a010a..815c5d9a4501 100644 --- a/src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts +++ b/src/test/javascript/spec/component/overview/course-conversations/layout/conversation-messages/conversation-messages.component.spec.ts @@ -284,5 +284,14 @@ examples.forEach((activeConversation) => { expect(inlineInput).toBeTruthy(); // Check if the inline input component is present })); } + + it('should scroll to bottom and set canStartSaving to true when lastScrollPosition is falsy', async () => { + const scrollToBottomSpy = jest.spyOn(component, 'scrollToBottomOfMessages'); + + await component.goToLastSelectedElement(0, false); + + expect(scrollToBottomSpy).toHaveBeenCalledOnce(); + expect(component.canStartSaving).toBeTrue(); + }); }); });