-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fd63e3
commit 6d83b17
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |