Skip to content

Commit 3bc0654

Browse files
committed
test(voip): fix CallStore mock assertions for ESLint
Use mockCallStoreState helper with unknown double assertion so partial mocks satisfy @typescript-eslint/consistent-type-assertions (CI failure on navigateToCallRoom.test.ts). Made-with: Cursor
1 parent b11885f commit 3bc0654

File tree

1 file changed

+81
-54
lines changed

1 file changed

+81
-54
lines changed

app/lib/services/voip/navigateToCallRoom.test.ts

Lines changed: 81 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ const mockGoRoom = jest.mocked(goRoom);
3434
const mockStoreGetState = jest.mocked(store.getState);
3535
const mockNavigation = jest.mocked(Navigation);
3636

37+
type CallStoreSnapshot = ReturnType<typeof useCallStore.getState>;
38+
39+
/** Partial mock: tests only need fields read by `navigateToCallRoom`. */
40+
function mockCallStoreState(
41+
snapshot: Pick<CallStoreSnapshot, 'roomId' | 'contact' | 'focused' | 'toggleFocus'>
42+
): CallStoreSnapshot {
43+
return snapshot as unknown as CallStoreSnapshot;
44+
}
45+
3746
describe('navigateToCallRoom', () => {
3847
const toggleFocus = jest.fn();
3948

@@ -44,12 +53,14 @@ describe('navigateToCallRoom', () => {
4453
});
4554

4655
it('does not navigate when roomId is null', async () => {
47-
mockGetState.mockReturnValue({
48-
roomId: null,
49-
contact: { username: 'u', sipExtension: '' },
50-
focused: false,
51-
toggleFocus
52-
} as ReturnType<typeof useCallStore.getState>);
56+
mockGetState.mockReturnValue(
57+
mockCallStoreState({
58+
roomId: null,
59+
contact: { username: 'u', sipExtension: '' },
60+
focused: false,
61+
toggleFocus
62+
})
63+
);
5364

5465
await navigateToCallRoom();
5566

@@ -58,38 +69,44 @@ describe('navigateToCallRoom', () => {
5869
});
5970

6071
it('does not navigate for SIP contact', async () => {
61-
mockGetState.mockReturnValue({
62-
roomId: 'rid-1',
63-
contact: { username: 'u', sipExtension: '100' },
64-
focused: false,
65-
toggleFocus
66-
} as ReturnType<typeof useCallStore.getState>);
72+
mockGetState.mockReturnValue(
73+
mockCallStoreState({
74+
roomId: 'rid-1',
75+
contact: { username: 'u', sipExtension: '100' },
76+
focused: false,
77+
toggleFocus
78+
})
79+
);
6780

6881
await navigateToCallRoom();
6982

7083
expect(mockGoRoom).not.toHaveBeenCalled();
7184
});
7285

7386
it('does not navigate when username is missing', async () => {
74-
mockGetState.mockReturnValue({
75-
roomId: 'rid-1',
76-
contact: { username: undefined, sipExtension: '' },
77-
focused: false,
78-
toggleFocus
79-
} as ReturnType<typeof useCallStore.getState>);
87+
mockGetState.mockReturnValue(
88+
mockCallStoreState({
89+
roomId: 'rid-1',
90+
contact: { username: undefined, sipExtension: '' },
91+
focused: false,
92+
toggleFocus
93+
})
94+
);
8095

8196
await navigateToCallRoom();
8297

8398
expect(mockGoRoom).not.toHaveBeenCalled();
8499
});
85100

86101
it('minimizes first when CallView is focused then navigates', async () => {
87-
mockGetState.mockReturnValue({
88-
roomId: 'rid-1',
89-
contact: { username: 'alice', sipExtension: '' },
90-
focused: true,
91-
toggleFocus
92-
} as ReturnType<typeof useCallStore.getState>);
102+
mockGetState.mockReturnValue(
103+
mockCallStoreState({
104+
roomId: 'rid-1',
105+
contact: { username: 'alice', sipExtension: '' },
106+
focused: true,
107+
toggleFocus
108+
})
109+
);
93110

94111
await navigateToCallRoom();
95112

@@ -101,12 +118,14 @@ describe('navigateToCallRoom', () => {
101118
});
102119

103120
it('navigates without toggleFocus when already minimized', async () => {
104-
mockGetState.mockReturnValue({
105-
roomId: 'rid-1',
106-
contact: { username: 'alice', sipExtension: '' },
107-
focused: false,
108-
toggleFocus
109-
} as ReturnType<typeof useCallStore.getState>);
121+
mockGetState.mockReturnValue(
122+
mockCallStoreState({
123+
roomId: 'rid-1',
124+
contact: { username: 'alice', sipExtension: '' },
125+
focused: false,
126+
toggleFocus
127+
})
128+
);
110129

111130
await navigateToCallRoom();
112131

@@ -119,12 +138,14 @@ describe('navigateToCallRoom', () => {
119138

120139
it('navigates to ChatsStackNavigator first when on ProfileView', async () => {
121140
mockNavigation.getCurrentRoute.mockReturnValue({ name: 'ProfileView' } as any);
122-
mockGetState.mockReturnValue({
123-
roomId: 'rid-1',
124-
contact: { username: 'alice', sipExtension: '' },
125-
focused: false,
126-
toggleFocus
127-
} as ReturnType<typeof useCallStore.getState>);
141+
mockGetState.mockReturnValue(
142+
mockCallStoreState({
143+
roomId: 'rid-1',
144+
contact: { username: 'alice', sipExtension: '' },
145+
focused: false,
146+
toggleFocus
147+
})
148+
);
128149

129150
await navigateToCallRoom();
130151

@@ -137,12 +158,14 @@ describe('navigateToCallRoom', () => {
137158

138159
it('navigates to ChatsStackNavigator first when on AccessibilityAndAppearanceView', async () => {
139160
mockNavigation.getCurrentRoute.mockReturnValue({ name: 'AccessibilityAndAppearanceView' } as any);
140-
mockGetState.mockReturnValue({
141-
roomId: 'rid-1',
142-
contact: { username: 'alice', sipExtension: '' },
143-
focused: false,
144-
toggleFocus
145-
} as ReturnType<typeof useCallStore.getState>);
161+
mockGetState.mockReturnValue(
162+
mockCallStoreState({
163+
roomId: 'rid-1',
164+
contact: { username: 'alice', sipExtension: '' },
165+
focused: false,
166+
toggleFocus
167+
})
168+
);
146169

147170
await navigateToCallRoom();
148171

@@ -152,12 +175,14 @@ describe('navigateToCallRoom', () => {
152175

153176
it('navigates to ChatsStackNavigator first when on SettingsView', async () => {
154177
mockNavigation.getCurrentRoute.mockReturnValue({ name: 'SettingsView' } as any);
155-
mockGetState.mockReturnValue({
156-
roomId: 'rid-1',
157-
contact: { username: 'alice', sipExtension: '' },
158-
focused: false,
159-
toggleFocus
160-
} as ReturnType<typeof useCallStore.getState>);
178+
mockGetState.mockReturnValue(
179+
mockCallStoreState({
180+
roomId: 'rid-1',
181+
contact: { username: 'alice', sipExtension: '' },
182+
focused: false,
183+
toggleFocus
184+
})
185+
);
161186

162187
await navigateToCallRoom();
163188

@@ -167,12 +192,14 @@ describe('navigateToCallRoom', () => {
167192

168193
it('does not navigate to ChatsStackNavigator when already on RoomView', async () => {
169194
mockNavigation.getCurrentRoute.mockReturnValue({ name: 'RoomView' } as any);
170-
mockGetState.mockReturnValue({
171-
roomId: 'rid-1',
172-
contact: { username: 'alice', sipExtension: '' },
173-
focused: false,
174-
toggleFocus
175-
} as ReturnType<typeof useCallStore.getState>);
195+
mockGetState.mockReturnValue(
196+
mockCallStoreState({
197+
roomId: 'rid-1',
198+
contact: { username: 'alice', sipExtension: '' },
199+
focused: false,
200+
toggleFocus
201+
})
202+
);
176203

177204
await navigateToCallRoom();
178205

0 commit comments

Comments
 (0)