From 00ed3918ebafc60ca70dd8a3273d5d9e8c37732c Mon Sep 17 00:00:00 2001 From: Mustafa BOLEKEN Date: Mon, 6 Jan 2025 09:47:33 +0300 Subject: [PATCH] Add createWebRTCAdaptor function --- react/src/Components/PublisherRequestTab.js | 2 +- ...stTab.test.js => PublisherRequestTab.test} | 65 +++++++++---------- react/src/pages/AntMedia.js | 49 +++++++------- 3 files changed, 58 insertions(+), 58 deletions(-) rename react/src/__tests__/Components/{PublisherRequestTab.test.js => PublisherRequestTab.test} (53%) diff --git a/react/src/Components/PublisherRequestTab.js b/react/src/Components/PublisherRequestTab.js index eb4c45f9..e47bb926 100644 --- a/react/src/Components/PublisherRequestTab.js +++ b/react/src/Components/PublisherRequestTab.js @@ -3,7 +3,7 @@ import Stack from "@mui/material/Stack"; import Grid from "@mui/material/Grid"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; -import {styled, useTheme} from "@mui/material/styles"; +import {styled} from "@mui/material/styles"; import { SvgIcon } from "./SvgIcon"; const PublisherRequestName = styled(Typography)(({ theme }) => ({ diff --git a/react/src/__tests__/Components/PublisherRequestTab.test.js b/react/src/__tests__/Components/PublisherRequestTab.test similarity index 53% rename from react/src/__tests__/Components/PublisherRequestTab.test.js rename to react/src/__tests__/Components/PublisherRequestTab.test index 473780ba..ad2f704e 100644 --- a/react/src/__tests__/Components/PublisherRequestTab.test.js +++ b/react/src/__tests__/Components/PublisherRequestTab.test @@ -1,56 +1,36 @@ -// src/PublisherRequestTab.test.js +// src/PublisherRequestTab.tet.js import React from 'react'; import { render } from '@testing-library/react'; -import { ConferenceContext } from 'pages/AntMedia'; import PublisherRequestTab from "../../Components/PublisherRequestTab"; import theme from "../../styles/theme"; import {ThemeList} from "../../styles/themeList"; import {ThemeProvider} from "@mui/material"; -const contextValue = { - initialized: true, - setLocalVideo: jest.fn(), - localVideoCreate: jest.fn(), - setIsJoining: jest.fn(), - joinRoom: jest.fn(), - localVideo: {}, - setSpeedTestObject: jest.fn(), - makeId: jest.fn(), - requestSpeakerList: [ - "test1", - "test2", - ], - setRequestSpeakerList: jest.fn(), - approveBecomeSpeakerRequest: jest.fn(), - rejectBecomeSpeakerRequest: jest.fn(), -}; - // Mock the useContext hook jest.mock('react', () => ({ ...jest.requireActual('react'), useContext: jest.fn(), })); + describe('Publisher Request Tab Component', () => { beforeEach(() => { // Reset the mock implementation before each test jest.clearAllMocks(); - - React.useContext.mockImplementation(input => { - if (input === ConferenceContext) { - return contextValue; - } - return jest.requireActual('react').useContext(input); - }); }); it('renders without crashing', () => { render( - + ); }); @@ -58,7 +38,12 @@ describe('Publisher Request Tab Component', () => { it('renders the publisher request items', () => { const { getByText } = render( - + ); @@ -67,25 +52,39 @@ describe('Publisher Request Tab Component', () => { }); it('calls the approveBecomeSpeakerRequest function when the allow button is clicked', () => { + let mockApproveBecomeSpeakerRequest = jest.fn(); + const { getByTestId } = render( - + ); getByTestId('approve-become-speaker-test1').click(); - expect(contextValue.approveBecomeSpeakerRequest).toHaveBeenCalledWith('test1'); + expect(mockApproveBecomeSpeakerRequest).toHaveBeenCalledWith('test1'); }); it('calls the rejectBecomeSpeakerRequest function when the deny button is clicked', () => { + let mockRejectBecomeSpeakerRequest = jest.fn(); + const { getByTestId } = render( - + ); getByTestId('reject-become-speaker-test1').click(); - expect(contextValue.rejectBecomeSpeakerRequest).toHaveBeenCalledWith('test1'); + expect(mockRejectBecomeSpeakerRequest).toHaveBeenCalledWith('test1'); }); }); diff --git a/react/src/pages/AntMedia.js b/react/src/pages/AntMedia.js index 57742902..6491cdf5 100644 --- a/react/src/pages/AntMedia.js +++ b/react/src/pages/AntMedia.js @@ -1343,31 +1343,32 @@ function AntMedia(props) { } useEffect(() => { - - - reconnecting = false; - publishReconnected = true; - playReconnected = true; - console.log("++ createWebRTCAdaptor"); - //here we check if audio or video device available and wait result - //according to the result we modify mediaConstraints - - checkDevices().then(() => { - var adaptor = new WebRTCAdaptor({ - websocket_url: websocketURL, - mediaConstraints: mediaConstraints, - peerconnection_config: peerconnection_config, - isPlayMode: isPlayOnly, // onlyDataChannel: isPlayOnly, - debug: true, - callback: infoCallback, - callbackError: errorCallback, - purposeForTest: "main-adaptor" - }); - setWebRTCAdaptor(adaptor) + createWebRTCAdaptor(); + //just run once when component is mounted + }, []); //eslint-disable-line + + function createWebRTCAdaptor() { + reconnecting = false; + publishReconnected = true; + playReconnected = true; + console.log("++ createWebRTCAdaptor"); + //here we check if audio or video device available and wait result + //according to the result we modify mediaConstraints + + checkDevices().then(() => { + var adaptor = new WebRTCAdaptor({ + websocket_url: websocketURL, + mediaConstraints: mediaConstraints, + peerconnection_config: peerconnection_config, + isPlayMode: isPlayOnly, // onlyDataChannel: isPlayOnly, + debug: true, + callback: infoCallback, + callbackError: errorCallback, + purposeForTest: "main-adaptor" }); - - //just run once when component is mounted - }, []); //eslint-disable-line + setWebRTCAdaptor(adaptor) + }); + } useEffect(() => { if (devices.length > 0) {