Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
import { renderHook } from '@testing-library/react';

import { useRoomMenuActions } from './useRoomMenuActions';
import { createFakeRoom, createFakeSubscription } from '../../../../../tests/mocks/data';
import { createFakeSubscription } from '../../../../../tests/mocks/data';

const mockRoom = createFakeRoom({ _id: 'room1', t: 'c', name: 'room1', fname: 'Room 1' });
const mockSubscription = createFakeSubscription({ name: 'room1', t: 'c', disableNotifications: false, rid: 'room1' });
const mockSubscription = createFakeSubscription({ name: 'room1', fname: 'Room 1', t: 'c', disableNotifications: false, rid: 'room1' });

jest.mock('../../../../../client/lib/rooms/roomCoordinator', () => ({
roomCoordinator: {
Expand Down Expand Up @@ -42,7 +40,7 @@ describe('useRoomMenuActions', () => {
it('should return all menu options for normal rooms', () => {
const { result } = renderHook(() => useRoomMenuActions(mockHookProps), {
wrapper: mockAppRoot()
.withSubscriptions([{ ...mockSubscription, rid: 'room1' }] as unknown as SubscriptionWithRoom[])
.withSubscription({ ...mockSubscription, rid: 'room1' })
.withPermission('leave-c')
.withPermission('leave-p')
.withSetting('Favorite_Rooms', true)
Expand All @@ -59,7 +57,7 @@ describe('useRoomMenuActions', () => {
it('should return priorities section for omnichannel room', () => {
const { result } = renderHook(() => useRoomMenuActions({ ...mockHookProps, type: 'l' }), {
wrapper: mockAppRoot()
.withSubscriptions([{ ...mockSubscription, ...mockRoom, t: 'l' }] as unknown as SubscriptionWithRoom[])
.withSubscription({ ...mockSubscription, t: 'l' })
.withPermission('leave-c')
.withPermission('leave-p')
.withSetting('Favorite_Rooms', true)
Expand All @@ -76,7 +74,7 @@ describe('useRoomMenuActions', () => {
it('should not return any menu option if hideDefaultOptions', () => {
const { result } = renderHook(() => useRoomMenuActions({ ...mockHookProps, hideDefaultOptions: true }), {
wrapper: mockAppRoot()
.withSubscriptions([{ ...mockSubscription, ...mockRoom }] as unknown as SubscriptionWithRoom[])
.withSubscription(mockSubscription)
.withPermission('leave-c')
.withPermission('leave-p')
.withSetting('Favorite_Rooms', true)
Expand All @@ -89,7 +87,7 @@ describe('useRoomMenuActions', () => {
it('should not return favorite room option if setting is disabled', () => {
const { result } = renderHook(() => useRoomMenuActions(mockHookProps), {
wrapper: mockAppRoot()
.withSubscriptions([{ ...mockSubscription, ...mockRoom }] as unknown as SubscriptionWithRoom[])
.withSubscription(mockSubscription)
.withPermission('leave-c')
.withPermission('leave-p')
.withSetting('Favorite_Rooms', false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
import { renderHook } from '@testing-library/react';

import { useRoomLeave } from './useRoomLeave';
Expand All @@ -25,7 +24,7 @@ jest.mock('../../../../../../../client/lib/rooms/roomCoordinator', () => ({
it('should return leave function if user has subscription', () => {
const wrapper = mockAppRoot()
.withPermission('leave-c')
.withSubscriptions([{ ...mockSubscription, rid: 'room1' }] as unknown as SubscriptionWithRoom[])
.withSubscription({ ...mockSubscription, rid: 'room1' })
.build();

const { result } = renderHook(() => useRoomLeave(mockRoom), { wrapper });
Expand Down
16 changes: 13 additions & 3 deletions packages/mock-providers/src/MockedAppRootBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
DirectCallData,
IRoom,
ISetting,
ISubscription,
IUser,
ProviderCapabilities,
Serialized,
Expand Down Expand Up @@ -149,8 +148,11 @@ export class MockedAppRootBuilder {
onLogout: () => () => undefined,
queryPreference: () => [() => () => undefined, () => undefined],
queryRoom: () => [() => () => undefined, () => this.room],
querySubscription: () => [() => () => undefined, () => this.subscriptions as unknown as ISubscription],
querySubscriptions: () => [() => () => undefined, () => this.subscriptions ?? []], // apply query and option
querySubscription: () => [() => () => undefined, () => this.subscription],
querySubscriptions: () => [
() => () => undefined,
() => (this.subscription ? [this.subscription, ...(this.subscriptions ?? [])] : (this.subscriptions ?? [])),
], // apply query and option
user: null,
userId: undefined,
};
Expand Down Expand Up @@ -205,6 +207,8 @@ export class MockedAppRootBuilder {

private subscriptions: SubscriptionWithRoom[] | undefined = undefined;

private subscription: SubscriptionWithRoom | undefined = undefined;

private modal: ModalContextValue = {
currentModal: { component: null },
modal: {
Expand Down Expand Up @@ -451,6 +455,12 @@ export class MockedAppRootBuilder {
return this;
}

withSubscription(subscription: SubscriptionWithRoom): this {
this.subscription = subscription;

return this;
}

withRoom(room: IRoom): this {
this.room = room;

Expand Down
Loading