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
154 lines
4.8 KiB
TypeScript
154 lines
4.8 KiB
TypeScript
import { UserStatus } from '@rocket.chat/core-typings';
|
|
import { mockAppRoot } from '@rocket.chat/mock-providers';
|
|
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import RoomTopic from './RoomTopic';
|
|
import FakeRoomProvider from '../../../../tests/mocks/client/FakeRoomProvider';
|
|
import { createFakeRoom, createFakeSubscription, createFakeUser } from '../../../../tests/mocks/data';
|
|
|
|
const user = createFakeUser({
|
|
active: true,
|
|
roles: ['admin'],
|
|
type: 'user',
|
|
status: UserStatus.ONLINE,
|
|
});
|
|
|
|
const user2 = createFakeUser({
|
|
active: true,
|
|
roles: ['admin'],
|
|
type: 'user',
|
|
statusText: 'Sample Status',
|
|
status: UserStatus.ONLINE,
|
|
});
|
|
|
|
const user3 = createFakeUser({
|
|
active: true,
|
|
roles: ['admin'],
|
|
type: 'user',
|
|
status: UserStatus.ONLINE,
|
|
});
|
|
|
|
describe('RoomTopic', () => {
|
|
it('should render Add Topic when no topic is present and user can edit room', () => {
|
|
const room = createFakeRoom({ topic: '', t: 'c', u: { _id: user._id, username: user.username, name: user.name } });
|
|
const subscription = createFakeSubscription({ t: 'c', rid: room._id, u: room.u, roles: ['owner'] });
|
|
|
|
render(
|
|
<FakeRoomProvider roomOverrides={room} subscriptionOverrides={subscription}>
|
|
<RoomTopic room={room} />
|
|
</FakeRoomProvider>,
|
|
{
|
|
wrapper: mockAppRoot()
|
|
.withSubscriptions([{ ...subscription, ...room }] as unknown as SubscriptionWithRoom[])
|
|
.withPermission('edit-room')
|
|
.withUser(user)
|
|
.build(),
|
|
},
|
|
);
|
|
|
|
expect(screen.getByText('Add_topic')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should not render Add Topic when no topic is present and user cannot edit room', () => {
|
|
const room = createFakeRoom({ topic: '', t: 'c' });
|
|
const subscription = createFakeSubscription({ t: 'c', rid: room._id });
|
|
|
|
render(
|
|
<FakeRoomProvider roomOverrides={room} subscriptionOverrides={subscription}>
|
|
<RoomTopic room={room} />
|
|
</FakeRoomProvider>,
|
|
{
|
|
wrapper: mockAppRoot()
|
|
.withSubscriptions([{ ...subscription, ...room }] as unknown as SubscriptionWithRoom[])
|
|
.withUser(user)
|
|
.build(),
|
|
},
|
|
);
|
|
|
|
expect(screen.queryByText('Add_topic')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should not render Add Topic when no statusText is present, user can edit room and room is a direct message room', () => {
|
|
const room = createFakeRoom({ topic: '', t: 'd', uids: [user._id, user3._id] });
|
|
const subscription = createFakeSubscription({ t: 'd', rid: room._id });
|
|
|
|
render(
|
|
<FakeRoomProvider roomOverrides={room} subscriptionOverrides={subscription}>
|
|
<RoomTopic room={room} />
|
|
</FakeRoomProvider>,
|
|
{
|
|
wrapper: mockAppRoot()
|
|
.withSubscriptions([{ ...subscription, ...room }] as unknown as SubscriptionWithRoom[])
|
|
.withUser(user)
|
|
.withUsers([user3])
|
|
.withPermission('edit-room')
|
|
.build(),
|
|
},
|
|
);
|
|
|
|
expect(screen.queryByText('Add_topic')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should render topic when topic is present for rooms', () => {
|
|
const room = createFakeRoom({ topic: 'Sample Topic', t: 'c' });
|
|
const subscription = createFakeSubscription({ t: 'c', rid: room._id });
|
|
|
|
render(
|
|
<FakeRoomProvider roomOverrides={room} subscriptionOverrides={subscription}>
|
|
<RoomTopic room={room} />
|
|
</FakeRoomProvider>,
|
|
{
|
|
wrapper: mockAppRoot()
|
|
.withSubscriptions([{ ...subscription, ...room }] as unknown as SubscriptionWithRoom[])
|
|
.withUser(user)
|
|
.build(),
|
|
},
|
|
);
|
|
|
|
expect(screen.getByText('Sample Topic')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should not render the DM partner statusText (handled by RoomMemberStatus)', () => {
|
|
const room = createFakeRoom({ topic: '', t: 'd', uids: [user._id, user2._id] });
|
|
const subscription = createFakeSubscription({ t: 'd', rid: room._id });
|
|
|
|
render(
|
|
<FakeRoomProvider roomOverrides={room} subscriptionOverrides={subscription}>
|
|
<RoomTopic room={room} />
|
|
</FakeRoomProvider>,
|
|
{
|
|
wrapper: mockAppRoot()
|
|
.withSubscriptions([{ ...subscription, ...room }] as unknown as SubscriptionWithRoom[])
|
|
.withPermission('edit-room')
|
|
.withUser(user)
|
|
.withUsers([user2])
|
|
.build(),
|
|
},
|
|
);
|
|
|
|
expect(screen.queryByText('Add_topic')).not.toBeInTheDocument();
|
|
expect(screen.queryByText('Sample Status')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should not render Add Topic for livechat rooms', () => {
|
|
const room = createFakeRoom({ topic: '', t: 'l' });
|
|
const subscription = createFakeSubscription({ t: 'l', rid: room._id });
|
|
|
|
render(
|
|
<FakeRoomProvider roomOverrides={room} subscriptionOverrides={subscription}>
|
|
<RoomTopic room={room} />
|
|
</FakeRoomProvider>,
|
|
{
|
|
wrapper: mockAppRoot()
|
|
.withSubscriptions([{ ...subscription, ...room }] as unknown as SubscriptionWithRoom[])
|
|
.withUser(user)
|
|
.withPermission('edit-room')
|
|
.build(),
|
|
},
|
|
);
|
|
|
|
expect(screen.queryByText('Add_topic')).not.toBeInTheDocument();
|
|
});
|
|
});
|