Skip to content

Commit 6f5411e

Browse files
Merge branch 'develop' into chore/moveHistoryPayloadGetter
2 parents 6b756fc + 06991bc commit 6f5411e

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

apps/meteor/client/views/navigation/sidepanel/hooks/useRoomMenuActions.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { mockAppRoot } from '@rocket.chat/mock-providers';
2-
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
32
import { renderHook } from '@testing-library/react';
43

54
import { useRoomMenuActions } from './useRoomMenuActions';
6-
import { createFakeRoom, createFakeSubscription } from '../../../../../tests/mocks/data';
5+
import { createFakeSubscription } from '../../../../../tests/mocks/data';
76

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

119
jest.mock('../../../../../client/lib/rooms/roomCoordinator', () => ({
1210
roomCoordinator: {
@@ -42,7 +40,7 @@ describe('useRoomMenuActions', () => {
4240
it('should return all menu options for normal rooms', () => {
4341
const { result } = renderHook(() => useRoomMenuActions(mockHookProps), {
4442
wrapper: mockAppRoot()
45-
.withSubscriptions([{ ...mockSubscription, rid: 'room1' }] as unknown as SubscriptionWithRoom[])
43+
.withSubscription({ ...mockSubscription, rid: 'room1' })
4644
.withPermission('leave-c')
4745
.withPermission('leave-p')
4846
.withSetting('Favorite_Rooms', true)
@@ -59,7 +57,7 @@ describe('useRoomMenuActions', () => {
5957
it('should return priorities section for omnichannel room', () => {
6058
const { result } = renderHook(() => useRoomMenuActions({ ...mockHookProps, type: 'l' }), {
6159
wrapper: mockAppRoot()
62-
.withSubscriptions([{ ...mockSubscription, ...mockRoom, t: 'l' }] as unknown as SubscriptionWithRoom[])
60+
.withSubscription({ ...mockSubscription, t: 'l' })
6361
.withPermission('leave-c')
6462
.withPermission('leave-p')
6563
.withSetting('Favorite_Rooms', true)
@@ -76,7 +74,7 @@ describe('useRoomMenuActions', () => {
7674
it('should not return any menu option if hideDefaultOptions', () => {
7775
const { result } = renderHook(() => useRoomMenuActions({ ...mockHookProps, hideDefaultOptions: true }), {
7876
wrapper: mockAppRoot()
79-
.withSubscriptions([{ ...mockSubscription, ...mockRoom }] as unknown as SubscriptionWithRoom[])
77+
.withSubscription(mockSubscription)
8078
.withPermission('leave-c')
8179
.withPermission('leave-p')
8280
.withSetting('Favorite_Rooms', true)
@@ -89,7 +87,7 @@ describe('useRoomMenuActions', () => {
8987
it('should not return favorite room option if setting is disabled', () => {
9088
const { result } = renderHook(() => useRoomMenuActions(mockHookProps), {
9189
wrapper: mockAppRoot()
92-
.withSubscriptions([{ ...mockSubscription, ...mockRoom }] as unknown as SubscriptionWithRoom[])
90+
.withSubscription(mockSubscription)
9391
.withPermission('leave-c')
9492
.withPermission('leave-p')
9593
.withSetting('Favorite_Rooms', false)

apps/meteor/client/views/room/contextualBar/Info/hooks/actions/useRoomLeave.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { mockAppRoot } from '@rocket.chat/mock-providers';
2-
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
32
import { renderHook } from '@testing-library/react';
43

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

3130
const { result } = renderHook(() => useRoomLeave(mockRoom), { wrapper });

packages/mock-providers/src/MockedAppRootBuilder.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
DirectCallData,
44
IRoom,
55
ISetting,
6-
ISubscription,
76
IUser,
87
ProviderCapabilities,
98
Serialized,
@@ -149,8 +148,11 @@ export class MockedAppRootBuilder {
149148
onLogout: () => () => undefined,
150149
queryPreference: () => [() => () => undefined, () => undefined],
151150
queryRoom: () => [() => () => undefined, () => this.room],
152-
querySubscription: () => [() => () => undefined, () => this.subscriptions as unknown as ISubscription],
153-
querySubscriptions: () => [() => () => undefined, () => this.subscriptions ?? []], // apply query and option
151+
querySubscription: () => [() => () => undefined, () => this.subscription],
152+
querySubscriptions: () => [
153+
() => () => undefined,
154+
() => (this.subscription ? [this.subscription, ...(this.subscriptions ?? [])] : (this.subscriptions ?? [])),
155+
], // apply query and option
154156
user: null,
155157
userId: undefined,
156158
};
@@ -205,6 +207,8 @@ export class MockedAppRootBuilder {
205207

206208
private subscriptions: SubscriptionWithRoom[] | undefined = undefined;
207209

210+
private subscription: SubscriptionWithRoom | undefined = undefined;
211+
208212
private modal: ModalContextValue = {
209213
currentModal: { component: null },
210214
modal: {
@@ -451,6 +455,12 @@ export class MockedAppRootBuilder {
451455
return this;
452456
}
453457

458+
withSubscription(subscription: SubscriptionWithRoom): this {
459+
this.subscription = subscription;
460+
461+
return this;
462+
}
463+
454464
withRoom(room: IRoom): this {
455465
this.room = room;
456466

0 commit comments

Comments
 (0)