Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Aug 21, 2024
1 parent 9fd63e3 commit 6d83b17
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions apps/meteor/client/sidebar/RoomMenu.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { RoomType } from '@rocket.chat/core-typings';
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import React from 'react';

import RoomMenu from './RoomMenu';

jest.mock('../../client/lib/rooms/roomCoordinator', () => ({
roomCoordinator: {
getRoomDirectives: () => ({
getUiText: () => 'leaveWarning',
}),
},
}));

jest.mock('../../app/ui-utils/client', () => ({
LegacyRoomManager: {
close: jest.fn(),
},
}));

const defaultProps = {
rid: 'roomId',
type: 'c' as RoomType,
hideDefaultOptions: false,
placement: 'right-start',
};

const renderOptions = {
wrapper: mockAppRoot()
.withTranslations('en', 'core', {
Hide: 'Hide',
Mark_unread: 'Mark Unread',
Favorite: 'Favorite',
Leave_room: 'Leave',
})
.withSetting('Favorite_Rooms', true)
.withPermission('leave-c')
.withPermission('leave-p')
.build(),
legacyRoot: true,
};

describe('RoomMenu component', () => {
it('should display the menu options', async () => {
render(<RoomMenu {...defaultProps} />, renderOptions);

const menu = screen.queryByRole('button');
await userEvent.click(menu as HTMLElement);

expect(await screen.findByRole('option', { name: 'Hide' })).toBeInTheDocument();
expect(await screen.findByRole('option', { name: 'Favorite' })).toBeInTheDocument();
expect(await screen.findByRole('option', { name: 'Mark Unread' })).toBeInTheDocument();
expect(await screen.findByRole('option', { name: 'Leave' })).toBeInTheDocument();
});

it('should display the menu options mark unread and favorite', async () => {
render(<RoomMenu {...defaultProps} type='l' />, renderOptions);

const menu = screen.queryByRole('button');
await userEvent.click(menu as HTMLElement);

expect(await screen.findAllByRole('option')).toHaveLength(2);
expect(screen.queryByRole('option', { name: 'Hide' })).not.toBeInTheDocument();
expect(screen.queryByRole('option', { name: 'Leave' })).not.toBeInTheDocument();
});
});

0 comments on commit 6d83b17

Please sign in to comment.