|
| 1 | +import type { LicenseModule } from '@rocket.chat/core-typings'; |
| 2 | +import { mockAppRoot } from '@rocket.chat/mock-providers'; |
| 3 | +import { render, screen } from '@testing-library/react'; |
| 4 | +import type { ReactNode } from 'react'; |
| 5 | + |
| 6 | +import ComposerFederation from './ComposerFederation'; |
| 7 | +import FakeRoomProvider from '../../../../../tests/mocks/client/FakeRoomProvider'; |
| 8 | +import { createFakeLicenseInfo } from '../../../../../tests/mocks/data'; |
| 9 | + |
| 10 | +jest.mock('../ComposerMessage', () => ({ |
| 11 | + __esModule: true, |
| 12 | + default: ({ children }: { children: ReactNode }) => <div data-testid='composer-message'>{children}</div>, |
| 13 | +})); |
| 14 | + |
| 15 | +const appRoot = ({ enabled = true, activeModules = ['federation'] }: { enabled?: boolean; activeModules?: LicenseModule[] } = {}) => |
| 16 | + mockAppRoot() |
| 17 | + .withJohnDoe() |
| 18 | + .withTranslations('en', 'core', { |
| 19 | + Federation_Matrix_Federated_Description_disabled: 'Federation is currently disabled on this workspace', |
| 20 | + Federation_Matrix_join_public_rooms_is_premium: 'Join federated rooms is a Premium feature', |
| 21 | + Federation_Matrix_Federated_Description_invalid_version: |
| 22 | + 'This room was created by an old Federation version and its blocked indeterminately. <1>Click here</1> for more information about Matrix Federation support', |
| 23 | + }) |
| 24 | + .withSetting('Federation_Matrix_enabled', enabled ?? true) |
| 25 | + .withEndpoint('GET', '/v1/licenses.info', () => ({ |
| 26 | + license: createFakeLicenseInfo({ activeModules }), |
| 27 | + })) |
| 28 | + .wrap((children) => <FakeRoomProvider>{children}</FakeRoomProvider>) |
| 29 | + .build(); |
| 30 | + |
| 31 | +describe('ComposerFederation', () => { |
| 32 | + it('should display blocked composer if federation version is invalid', () => { |
| 33 | + render(<ComposerFederation blocked />, { |
| 34 | + wrapper: appRoot(), |
| 35 | + }); |
| 36 | + |
| 37 | + expect(screen.getByText(/This room was created by an old Federation version and its blocked indeterminately/)).toBeInTheDocument(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should display disabled composer if federation is disabled', () => { |
| 41 | + render(<ComposerFederation />, { |
| 42 | + wrapper: appRoot({ enabled: false }), |
| 43 | + }); |
| 44 | + |
| 45 | + expect(screen.getByText('Federation is currently disabled on this workspace')).toBeInTheDocument(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should display disabled composer with premium message if federation addon is missing', () => { |
| 49 | + render(<ComposerFederation />, { |
| 50 | + wrapper: appRoot({ activeModules: [] }), |
| 51 | + }); |
| 52 | + |
| 53 | + expect(screen.getByText('Join federated rooms is a Premium feature')).toBeInTheDocument(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should display normal composer if federation is enabled and valid', async () => { |
| 57 | + render(<ComposerFederation />, { wrapper: appRoot() }); |
| 58 | + |
| 59 | + const composer = await screen.findByTestId('composer-message'); |
| 60 | + expect(composer).toBeInTheDocument(); |
| 61 | + }); |
| 62 | +}); |
0 commit comments