Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk committed Nov 18, 2024
1 parent 4860e4c commit 0b609dc
Showing 1 changed file with 0 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ describe('PostReactionsBarComponent', () => {

describe('setMayEditOrDelete', () => {
beforeEach(() => {
// Reset spies and component state before each test
jest.clearAllMocks();
component.readOnlyMode = false;
component.previewMode = false;
Expand All @@ -228,78 +227,62 @@ describe('PostReactionsBarComponent', () => {
conversation: {},
} as Post;

// Mock EventEmitter
jest.spyOn(component.mayEditOrDeleteOutput, 'emit');
});

it('should allow edit/delete when user is the author and not in read-only or preview mode', () => {
// Arrange
component.isAuthorOfPosting = true;
jest.spyOn(metisService, 'metisUserIsAtLeastInstructorInCourse').mockReturnValue(false);
jest.spyOn(component, 'hasChannelModerationRights').mockReturnValue(false);

// Act
component.setMayEditOrDelete();

// Assert
expect(component.mayEditOrDelete).toBeTrue();
expect(component.mayEditOrDeleteOutput.emit).toHaveBeenCalledWith(true);
});

it('should allow edit/delete when user has channel moderation rights', () => {
// Arrange
component.isAuthorOfPosting = false;
jest.spyOn(metisService, 'metisUserIsAtLeastInstructorInCourse').mockReturnValue(false);
jest.spyOn(component, 'hasChannelModerationRights').mockReturnValue(true);

// Act
component.setMayEditOrDelete();

// Assert
expect(component.mayEditOrDelete).toBeTrue();
expect(component.mayEditOrDeleteOutput.emit).toHaveBeenCalledWith(true);
});

it('should not allow edit/delete when in read-only mode', () => {
// Arrange
component.readOnlyMode = true;
component.isAuthorOfPosting = true;
jest.spyOn(metisService, 'metisUserIsAtLeastInstructorInCourse').mockReturnValue(true);
jest.spyOn(component, 'hasChannelModerationRights').mockReturnValue(true);

// Act
component.setMayEditOrDelete();

// Assert
expect(component.mayEditOrDelete).toBeFalse();
expect(component.mayEditOrDeleteOutput.emit).toHaveBeenCalledWith(false);
});

it('should not allow edit/delete when in preview mode', () => {
// Arrange
component.previewMode = true;
component.isAuthorOfPosting = true;
jest.spyOn(metisService, 'metisUserIsAtLeastInstructorInCourse').mockReturnValue(true);
jest.spyOn(component, 'hasChannelModerationRights').mockReturnValue(true);

// Act
component.setMayEditOrDelete();

// Assert
expect(component.mayEditOrDelete).toBeFalse();
expect(component.mayEditOrDeleteOutput.emit).toHaveBeenCalledWith(false);
});

it('should not allow edit/delete when user is not author and lacks permissions', () => {
// Arrange
component.isAuthorOfPosting = false;
jest.spyOn(metisService, 'metisUserIsAtLeastInstructorInCourse').mockReturnValue(false);
jest.spyOn(component, 'hasChannelModerationRights').mockReturnValue(false);

// Act
component.setMayEditOrDelete();

// Assert
expect(component.mayEditOrDelete).toBeFalse();
expect(component.mayEditOrDeleteOutput.emit).toHaveBeenCalledWith(false);
});
Expand Down

0 comments on commit 0b609dc

Please sign in to comment.