Skip to content

Commit 89d7cd6

Browse files
committed
two tests down
1 parent 58ebb62 commit 89d7cd6

File tree

2 files changed

+63
-20
lines changed

2 files changed

+63
-20
lines changed

frontend/src/hooks/tests/useCollectBrowserInformation.spec.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ describe('useCollectBrowserInformation', () => {
1111
(useSessionContext as Mock).mockReturnValue({
1212
session: {
1313
sessionId: 'someSessionId',
14-
connection: {
15-
connectionId: 'yourConnectionId',
16-
},
14+
connectionId: 'yourConnectionId',
1715
},
1816
});
1917

frontend/src/hooks/tests/useEmoji.spec.tsx

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import useSessionContext from '../useSessionContext';
77
import { SessionContextType } from '../../Context/SessionProvider/session';
88
import useEmoji, { EmojiWrapper } from '../useEmoji';
99
import VonageVideoClient from '../../utils/VonageVideoClient';
10+
import { SignalEvent, SubscriberWrapper } from '../../types/session';
1011

1112
vi.mock('../useSessionContext');
1213

@@ -34,7 +35,7 @@ describe('useEmoji', () => {
3435
vonageVideoClient = {
3536
current: Object.assign(new EventEmitter(), {
3637
signal: vi.fn(),
37-
connectionId: 'connection-id',
38+
connectionId: '123',
3839
}) as unknown as VonageVideoClient,
3940
};
4041

@@ -84,13 +85,10 @@ describe('useEmoji', () => {
8485
});
8586

8687
expect(vonageVideoClient.current?.signal).toBeCalledTimes(1);
87-
expect(vonageVideoClient.current?.signal).toBeCalledWith(
88-
{
89-
type: 'emoji',
90-
data: '{"emoji":"❤️","time":12000000}',
91-
},
92-
expect.any(Function)
93-
);
88+
expect(vonageVideoClient.current?.signal).toBeCalledWith({
89+
type: 'emoji',
90+
data: '{"emoji":"❤️","time":12000000}',
91+
});
9492
});
9593

9694
it('when called multiple times, sendEmoji throttles calls to once every 500ms', async () => {
@@ -118,22 +116,29 @@ describe('useEmoji', () => {
118116
it('adds emojis to the queue when a signal event is received and gets the correct sender name', async () => {
119117
const { result } = renderHook(() => useEmoji({ vonageVideoClient }));
120118

119+
// Mock receiving a signal event from another user
121120
act(() => {
122-
// Simulate sending an emoji
123-
result.current.sendEmoji('❤️');
124-
});
125-
126-
// Mock emitting a signal event from another user's connection
127-
act(() => {
128-
vonageVideoClient.current?.emit('signal', {
121+
const signalEvent: SignalEvent = {
129122
type: 'signal:emoji',
130123
data: JSON.stringify({
131124
emoji: '❤️',
132125
time: Date.now(),
133126
connectionId: mockConnection.connectionId, // Different from the session connection
134-
}),
127+
}) as unknown as string,
135128
from: { connectionId: '456', creationTime: 1, data: 'some-data' },
136-
});
129+
};
130+
const subscriberWrapper: SubscriberWrapper = {
131+
subscriber: {
132+
stream: {
133+
connection: {
134+
connectionId: '456',
135+
},
136+
name: 'John Doe',
137+
},
138+
},
139+
} as unknown as SubscriberWrapper;
140+
const subscriberWrappers = [subscriberWrapper];
141+
result.current.onEmoji(signalEvent, subscriberWrappers);
137142
});
138143

139144
const expectedEmojiWrapper: EmojiWrapper = {
@@ -147,4 +152,44 @@ describe('useEmoji', () => {
147152
expect(result.current.emojiQueue).toContainEqual(expectedEmojiWrapper);
148153
});
149154
});
155+
156+
it('recognizes when a received signal event is from local user', async () => {
157+
const { result } = renderHook(() => useEmoji({ vonageVideoClient }));
158+
159+
// Mock receiving a signal event from local user
160+
act(() => {
161+
const signalEvent: SignalEvent = {
162+
type: 'signal:emoji',
163+
data: JSON.stringify({
164+
emoji: '😲',
165+
time: Date.now(),
166+
connectionId: mockConnection.connectionId, // Different from the session connection
167+
}) as unknown as string,
168+
from: { connectionId: '123', creationTime: 1, data: 'some-data' },
169+
};
170+
const subscriberWrapper: SubscriberWrapper = {
171+
subscriber: {
172+
stream: {
173+
connection: {
174+
connectionId: '123',
175+
},
176+
name: 'That be I',
177+
},
178+
},
179+
} as unknown as SubscriberWrapper;
180+
const subscriberWrappers = [subscriberWrapper];
181+
result.current.onEmoji(signalEvent, subscriberWrappers);
182+
});
183+
184+
const expectedEmojiWrapper: EmojiWrapper = {
185+
name: 'You',
186+
emoji: '😲',
187+
time: expect.any(Number),
188+
};
189+
190+
// Use waitFor to check if emojiQueue contains the expected emoji
191+
await waitFor(() => {
192+
expect(result.current.emojiQueue).toContainEqual(expectedEmojiWrapper);
193+
});
194+
});
150195
});

0 commit comments

Comments
 (0)