Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
147 lines
5.6 KiB
TypeScript
147 lines
5.6 KiB
TypeScript
import type { RoomType } from '@rocket.chat/core-typings';
|
|
import { mockAppRoot } from '@rocket.chat/mock-providers';
|
|
import { QueryClient } from '@tanstack/react-query';
|
|
import { render, screen } from '@testing-library/react';
|
|
import '@testing-library/jest-dom';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import RoomMenu from './RoomMenu';
|
|
import { createFakeLicenseInfo, createFakeSubscription } from '../../tests/mocks/data';
|
|
|
|
jest.mock('../../client/lib/rooms/roomCoordinator', () => ({
|
|
roomCoordinator: {
|
|
getRoomDirectives: () => ({
|
|
getUiText: () => 'leaveWarning',
|
|
}),
|
|
},
|
|
}));
|
|
|
|
jest.mock('../../client/lib/LegacyRoomManager', () => ({
|
|
LegacyRoomManager: {
|
|
close: jest.fn(),
|
|
},
|
|
}));
|
|
|
|
jest.mock('./categories/hooks/useCategoryModals', () => ({
|
|
useCategoryModals: () => ({ openCreate: jest.fn(), openManage: jest.fn(), openDelete: jest.fn() }),
|
|
}));
|
|
|
|
const defaultProps = {
|
|
rid: 'roomId',
|
|
type: 'c' as RoomType,
|
|
hideDefaultOptions: false,
|
|
placement: 'right-start',
|
|
};
|
|
|
|
const buildBase = () =>
|
|
mockAppRoot()
|
|
.withTranslations('en', 'core', {
|
|
Hide: 'Hide',
|
|
Mark_unread: 'Mark Unread',
|
|
Favorite: 'Favorite',
|
|
Favorites: 'Favorites',
|
|
Move_to: 'Move to',
|
|
New_category: 'New category',
|
|
Leave_room: 'Leave',
|
|
Remove_from__categoryName__: 'Remove from {{categoryName}}',
|
|
})
|
|
.withSetting('Favorite_Rooms', true)
|
|
.withPermission('leave-c')
|
|
.withPermission('leave-p');
|
|
|
|
const renderOptions = {
|
|
wrapper: buildBase().build(),
|
|
};
|
|
|
|
const buildEnterpriseQueryClient = () => {
|
|
const client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } });
|
|
client.setQueryData(['licenses', 'getLicenses', undefined], {
|
|
license: createFakeLicenseInfo({ hasValidLicense: true, activeModules: ['experimental-enterprise-features'] }),
|
|
});
|
|
return client;
|
|
};
|
|
|
|
const enterpriseRenderOptions = {
|
|
wrapper: buildBase().withJohnDoe().withQueryClient(buildEnterpriseQueryClient()).build(),
|
|
};
|
|
|
|
it('should display Hide, Mark Unread, Leave and Favorite toggle for regular rooms without enterprise', async () => {
|
|
render(<RoomMenu {...defaultProps} />, renderOptions);
|
|
|
|
await userEvent.click(screen.queryByRole('button') as HTMLElement);
|
|
|
|
expect(await screen.findByRole('menuitem', { name: 'Hide' })).toBeInTheDocument();
|
|
expect(await screen.findByRole('menuitem', { name: 'Mark Unread' })).toBeInTheDocument();
|
|
expect(await screen.findByRole('menuitem', { name: 'Leave' })).toBeInTheDocument();
|
|
expect(await screen.findByRole('menuitem', { name: 'Favorite' })).toBeInTheDocument();
|
|
expect(screen.queryByRole('menuitem', { name: 'Move to' })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should display Hide, Mark Unread, Leave and Move to for regular rooms with enterprise', async () => {
|
|
render(<RoomMenu {...defaultProps} />, enterpriseRenderOptions);
|
|
|
|
await userEvent.click(screen.queryByRole('button') as HTMLElement);
|
|
|
|
expect(await screen.findByRole('menuitem', { name: 'Hide' })).toBeInTheDocument();
|
|
expect(await screen.findByRole('menuitem', { name: 'Mark Unread' })).toBeInTheDocument();
|
|
expect(await screen.findByRole('menuitem', { name: 'Leave' })).toBeInTheDocument();
|
|
expect(await screen.findByRole('menuitem', { name: 'Move to' })).toBeInTheDocument();
|
|
expect(screen.queryByRole('menuitem', { name: 'Favorite' })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should reveal Favorites and New category inside the "Move to" submenu for enterprise rooms', async () => {
|
|
render(<RoomMenu {...defaultProps} />, enterpriseRenderOptions);
|
|
|
|
await userEvent.click(screen.queryByRole('button') as HTMLElement);
|
|
await userEvent.hover(await screen.findByRole('menuitem', { name: 'Move to' }));
|
|
|
|
expect(await screen.findByRole('menuitem', { name: 'Favorites' })).toBeInTheDocument();
|
|
expect(await screen.findByRole('menuitem', { name: 'New category' })).toBeInTheDocument();
|
|
});
|
|
|
|
const enterpriseFavoriteRenderOptions = {
|
|
wrapper: buildBase()
|
|
.withJohnDoe()
|
|
.withQueryClient(buildEnterpriseQueryClient())
|
|
.withSubscription(createFakeSubscription({ rid: 'roomId', f: true, t: 'c' }))
|
|
.build(),
|
|
};
|
|
|
|
const enterpriseCategoryRenderOptions = {
|
|
wrapper: buildBase()
|
|
.withJohnDoe()
|
|
.withQueryClient(buildEnterpriseQueryClient())
|
|
.withSubscription(createFakeSubscription({ rid: 'roomId', f: false, t: 'c', category: 'cat-design' }))
|
|
.withUserPreference('sidebarCategories', [{ _id: 'cat-design', name: 'Design', showUnreads: true }])
|
|
.build(),
|
|
};
|
|
|
|
it('shows "Remove from Favorites" in the Move to submenu when the room is in favorites', async () => {
|
|
render(<RoomMenu {...defaultProps} />, enterpriseFavoriteRenderOptions);
|
|
|
|
await userEvent.click(screen.queryByRole('button') as HTMLElement);
|
|
await userEvent.hover(await screen.findByRole('menuitem', { name: 'Move to' }));
|
|
|
|
expect(await screen.findByRole('menuitem', { name: 'Remove from Favorites' })).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows "Remove from Design" in the Move to submenu when the room is in a custom category', async () => {
|
|
render(<RoomMenu {...defaultProps} />, enterpriseCategoryRenderOptions);
|
|
|
|
await userEvent.click(screen.queryByRole('button') as HTMLElement);
|
|
await userEvent.hover(await screen.findByRole('menuitem', { name: 'Move to' }));
|
|
|
|
expect(await screen.findByRole('menuitem', { name: 'Remove from Design' })).toBeInTheDocument();
|
|
});
|
|
|
|
it('should display only mark unread and favorite for omnichannel rooms', async () => {
|
|
render(<RoomMenu {...defaultProps} type='l' />, renderOptions);
|
|
|
|
const menu = screen.queryByRole('button');
|
|
await userEvent.click(menu as HTMLElement);
|
|
|
|
expect(await screen.findAllByRole('menuitem')).toHaveLength(2);
|
|
expect(screen.queryByRole('menuitem', { name: 'Hide' })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole('menuitem', { name: 'Leave' })).not.toBeInTheDocument();
|
|
});
|