Skip to content

Commit 793029c

Browse files
committed
improve useParticipantIds & DailyAudio tests
1 parent c3f9660 commit 793029c

File tree

3 files changed

+311
-336
lines changed

3 files changed

+311
-336
lines changed

test/.test-utils/event-emitter.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ export const emitParticipantJoined = (callObject: DailyCall, participant: Partia
5050
participant,
5151
});
5252
}
53+
54+
export const emitJoinedMeeting = (callObject: DailyCall, participants: Record<string, Partial<DailyParticipant>>) => {
55+
// @ts-ignore
56+
callObject.emit('joined-meeting', {
57+
action: 'joined-meeting',
58+
participants,
59+
});
60+
}
61+
62+
export const emitLeftMeeting = (callObject: DailyCall) => {
63+
// @ts-ignore
64+
callObject.emit('left-meeting', {
65+
action: 'left-meeting',
66+
});
67+
}

test/components/DailyAudio.test.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DailyAudio } from '../../src/components/DailyAudio';
99
import { DailyProvider } from '../../src/DailyProvider';
1010
import {
1111
emitActiveSpeakerChange,
12+
emitJoinedMeeting,
1213
emitParticipantLeft,
1314
emitParticipantUpdated,
1415
emitStartedCamera,
@@ -365,46 +366,44 @@ describe('DailyAudio', () => {
365366
faker.datatype.uuid(),
366367
faker.datatype.uuid(),
367368
];
368-
(callObject.participants as jest.Mock).mockImplementation(() => {
369-
const participants: Record<string, Partial<DailyParticipant>> = {
370-
local: mockParticipant({
371-
local: true,
372-
session_id: localSessionId,
373-
}),
374-
};
375-
remoteParticipants.forEach((id) => {
376-
const peer = mockParticipant({
377-
local: false,
378-
session_id: id,
379-
});
380-
peer.tracks.audio.state = 'playable';
381-
peer.tracks.audio.subscribed = true;
382-
participants[id] = peer;
369+
const participants: Record<string, Partial<DailyParticipant>> = {
370+
local: mockParticipant({
371+
local: true,
372+
session_id: localSessionId,
373+
}),
374+
};
375+
remoteParticipants.forEach((id) => {
376+
const peer = mockParticipant({
377+
local: false,
378+
session_id: id,
383379
});
384-
return participants;
380+
peer.tracks.audio.state = 'playable';
381+
peer.tracks.audio.subscribed = true;
382+
participants[id] = peer;
385383
});
384+
(callObject.participants as jest.Mock).mockImplementation(
385+
() => participants
386+
);
386387
const Wrapper = createWrapper(callObject);
387388
const { container } = render(
388389
<Wrapper>
389390
<DailyAudio maxSpeakers={3} />
390391
</Wrapper>
391392
);
392-
jest.useFakeTimers();
393+
act(() => emitJoinedMeeting(callObject, participants));
393394
act(() => emitStartedCamera(callObject));
394395
act(() => emitActiveSpeakerChange(callObject, remoteParticipants[0]));
395-
await waitFor(() =>
396-
expect(queryAudioById(remoteParticipants[0], container)).not.toBeNull()
397-
);
396+
await waitFor(() => {
397+
expect(queryAudioById(remoteParticipants[0], container)).not.toBeNull();
398+
});
398399
act(() => {
399-
jest.advanceTimersByTime(5000);
400400
emitActiveSpeakerChange(callObject, remoteParticipants[1]);
401401
});
402402
await waitFor(() => {
403403
expect(queryAudioById(remoteParticipants[0], container)).not.toBeNull();
404404
expect(queryAudioById(remoteParticipants[1], container)).not.toBeNull();
405405
});
406406
act(() => {
407-
jest.advanceTimersByTime(5000);
408407
emitActiveSpeakerChange(callObject, remoteParticipants[2]);
409408
});
410409
await waitFor(() => {
@@ -413,7 +412,6 @@ describe('DailyAudio', () => {
413412
expect(queryAudioById(remoteParticipants[2], container)).not.toBeNull();
414413
});
415414
act(() => {
416-
jest.advanceTimersByTime(5000);
417415
emitActiveSpeakerChange(callObject, remoteParticipants[3]);
418416
});
419417
await waitFor(() => {
@@ -422,7 +420,6 @@ describe('DailyAudio', () => {
422420
expect(queryAudioById(remoteParticipants[2], container)).not.toBeNull();
423421
expect(queryAudioById(remoteParticipants[3], container)).not.toBeNull();
424422
});
425-
jest.useRealTimers();
426423
});
427424
});
428425
});

0 commit comments

Comments
 (0)