Skip to content

Commit

Permalink
Added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cremertim committed Oct 29, 2024
1 parent 9726517 commit 9979342
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { CustomBreakpointNames } from 'app/shared/breakpoints/breakpoints.servic
})
export class ConversationMessagesComponent implements OnInit, AfterViewInit, OnDestroy {
private ngUnsubscribe = new Subject<void>();
private sessionStorageKey = 'conversationId.scrollPosition.';
sessionStorageKey = 'conversationId.scrollPosition.';

readonly PageType = PageType;
readonly ButtonType = ButtonType;
Expand Down Expand Up @@ -282,7 +282,7 @@ export class ConversationMessagesComponent implements OnInit, AfterViewInit, OnD
});
}

private saveScrollPosition = () => {
saveScrollPosition = () => {
this.scrollSubject.next(this.content.nativeElement.scrollTop);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ examples.forEach((activeConversation) => {
expect(getFilteredPostSpy).toHaveBeenCalledOnce();
}));

it('should save the scroll position in sessionStorage', fakeAsync(() => {
// Überwache sessionStorage.setItem
const setItemSpy = jest.spyOn(sessionStorage, 'setItem');
component.ngOnInit();
component.content.nativeElement.scrollTop = 200;
component.saveScrollPosition();
tick(100);
const expectedKey = `${component.sessionStorageKey}${component._activeConversation?.id}`;
const expectedValue = '200';
expect(setItemSpy).toHaveBeenCalledWith(expectedKey, expectedValue);
}));

it('should scroll to the bottom when a new message is created', fakeAsync(() => {
component.content.nativeElement.scrollTop = 100;
fixture.detectChanges();
component.handleNewMessageCreated();
tick();
expect(component.content.nativeElement.scrollTop).toBe(component.content.nativeElement.scrollHeight);
}));

it('should create empty post with the correct conversation type', fakeAsync(() => {
const createEmptyPostForContextSpy = jest.spyOn(metisService, 'createEmptyPostForContext').mockReturnValue(new Post());
component.createEmptyPost();
Expand Down

0 comments on commit 9979342

Please sign in to comment.