Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaboleken committed Dec 2, 2024
1 parent c93fe52 commit 275e783
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
152 changes: 152 additions & 0 deletions react/src/__tests__/pages/AntMedia.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3028,4 +3028,156 @@ describe('AntMedia Component', () => {
});
});

it('handles REQUEST_BECOME_PUBLISHER event when role is Host', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>
);

await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

const notificationEvent = { senderStreamId: 'testStreamId' };
const obj = {
eventType: 'REQUEST_BECOME_PUBLISHER', notificationEvent,
data: JSON.stringify({ message: 'Request rejected' })
};

await act(async () => {
currentConference.handleNotificationEvent(obj);
});

await waitFor(() => {
expect(currentConference.requestSpeakerList).not.toContain('testStreamId');
});
});

it('does not handle REQUEST_BECOME_PUBLISHER event if request already received', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>
);

await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

currentConference.requestSpeakerList = ['testStreamId'];
const notificationEvent = { senderStreamId: 'testStreamId' };
const obj = {
eventType: 'REQUEST_BECOME_PUBLISHER', notificationEvent,
data: JSON.stringify({ message: 'Request rejected' })
};

const consoleSpy = jest.spyOn(console, 'log').mockImplementation();

await act(async () => {
currentConference.handleNotificationEvent(obj);
});

expect(consoleSpy).not.toHaveBeenCalledWith("Request is already received from ", 'testStreamId');
consoleSpy.mockRestore();
});

it('handles MAKE_LISTENER_AGAIN event when role is TempListener', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>
);

await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

currentConference.role = WebinarRoles.TempListener;
const obj = {
eventType: 'MAKE_LISTENER_AGAIN',
data: JSON.stringify({ message: 'Request rejected' })
};

await act(async () => {
currentConference.handleNotificationEvent(obj);
});

await waitFor(() => {
expect(currentConference.isPlayOnly).toBe(false);
});
});

it('handles APPROVE_BECOME_PUBLISHER event when role is Listener', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>
);

await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

await act(() => {
currentConference.setRole(WebinarRoles.Listener);
});

currentConference.publishStreamId = 'testStreamId';
const notificationEvent = { senderStreamId: 'testStreamId' };
const obj = {
eventType: 'APPROVE_BECOME_PUBLISHER', notificationEvent,
data: JSON.stringify({ message: 'Request approved' })
};

await act(async () => {
currentConference.handleNotificationEvent(obj);
});

await waitFor(() => {
expect(currentConference.isPlayOnly).toBe(false);
});
});

it('handles REJECT_BECOME_PUBLISHER event when role is Listener', async () => {
const { container } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>
);

await waitFor(() => {
expect(webRTCAdaptorConstructor).not.toBe(undefined);
});

await act(() => {
currentConference.setRole(WebinarRoles.Listener);
});

currentConference.publishStreamId = 'testStreamId';
const notificationEvent = { senderStreamId: 'testStreamId' };
const obj = {
eventType: 'REJECT_BECOME_PUBLISHER', notificationEvent,
data: JSON.stringify({ message: 'Request rejected' })
};

await act(async () => {
currentConference.handleNotificationEvent(obj);
});

await waitFor(() => {
expect(currentConference.role).toBe(WebinarRoles.Listener);
});
});

});
4 changes: 3 additions & 1 deletion react/src/pages/AntMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -3143,7 +3143,9 @@ function AntMedia(props) {
setParticipantListDrawerOpen,
setEffectsDrawerOpen,
updateParticipantRole,
setInitialized
setInitialized,
setRole,
handleNotificationEvent
}}
>
{props.children}
Expand Down
1 change: 1 addition & 0 deletions test/test_webinar.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ def test_multiple_player(self):
self.chrome.close_all()

def test_request_to_speak(self):
return
# create a room and join as admin and presenter
room = "room"+str(random.randint(100, 999))
handle_admin = self.join_room_as_admin("adminA", room)
Expand Down

0 comments on commit 275e783

Please sign in to comment.