diff --git a/src/components/GalleryView/__snapshots__/GalleryView.test.tsx.snap b/src/components/GalleryView/__snapshots__/GalleryView.test.tsx.snap index f606114cd..23446fc81 100644 --- a/src/components/GalleryView/__snapshots__/GalleryView.test.tsx.snap +++ b/src/components/GalleryView/__snapshots__/GalleryView.test.tsx.snap @@ -52,7 +52,7 @@ exports[`the GalleryView component should render correctly 1`] = ` } } > - - - - - - - - - - - - - - - - ); } + +export default React.memo(Participant); diff --git a/src/components/ParticipantList/ParticipantList.test.tsx b/src/components/ParticipantList/ParticipantList.test.tsx index dbceb2aa4..89ff8780a 100644 --- a/src/components/ParticipantList/ParticipantList.test.tsx +++ b/src/components/ParticipantList/ParticipantList.test.tsx @@ -52,7 +52,7 @@ describe('the ParticipantList component', () => { const wrapper = shallow(); expect( wrapper - .find('Participant') + .find('Memo(Participant)') .at(1) .prop('isSelected') ).toBe(true); @@ -79,14 +79,14 @@ describe('the ParticipantList component', () => { const wrapper = shallow(); expect( wrapper - .find('Participant') + .find('Memo(Participant)') .at(1) .prop('hideParticipant') ).toBe(true); expect( wrapper - .find('Participant') + .find('Memo(Participant)') .at(2) .prop('hideParticipant') ).toBe(false); @@ -104,7 +104,7 @@ describe('the ParticipantList component', () => { const wrapper = shallow(); expect( wrapper - .find('Participant') + .find('Memo(Participant)') .at(1) .prop('hideParticipant') ).toBe(false); @@ -122,7 +122,7 @@ describe('the ParticipantList component', () => { const wrapper = shallow(); expect( wrapper - .find('Participant') + .find('Memo(Participant)') .at(1) .prop('hideParticipant') ).toBe(false); diff --git a/src/components/ParticipantList/__snapshots__/ParticipantList.test.tsx.snap b/src/components/ParticipantList/__snapshots__/ParticipantList.test.tsx.snap index 6e3f84da2..e63cfc4df 100644 --- a/src/components/ParticipantList/__snapshots__/ParticipantList.test.tsx.snap +++ b/src/components/ParticipantList/__snapshots__/ParticipantList.test.tsx.snap @@ -10,11 +10,11 @@ exports[`the ParticipantList component should correctly render Participant compo
- - - - jest.fn(() => ({ room: mockRoom, isConnecting: false, connect: () => {} }))); jest.mock('./useLocalTracks/useLocalTracks', () => jest.fn(() => ({ @@ -22,6 +24,7 @@ jest.mock('./useLocalTracks/useLocalTracks', () => removeLocalVideoTrack: () => {}, })) ); +jest.mock('../../state'); jest.mock('./useHandleRoomDisconnection/useHandleRoomDisconnection'); jest.mock('./useHandleTrackPublicationFailed/useHandleTrackPublicationFailed'); jest.mock('./useRestartAudioTrackOnDeviceChange/useRestartAudioTrackOnDeviceChange'); @@ -35,6 +38,10 @@ jest.mock('@twilio/video-processors', () => { }; }); +const mockUseAppState = useAppState as jest.Mock; + +mockUseAppState.mockImplementation(() => ({ isGalleryViewActive: false })); + describe('the VideoProvider component', () => { it('should correctly return the Video Context object', () => { const wrapper: React.FC = ({ children }) => ( diff --git a/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.test.tsx b/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.test.tsx index da3d7dfd8..e8699087a 100644 --- a/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.test.tsx +++ b/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.test.tsx @@ -1,8 +1,14 @@ import { act, HookResult, renderHook } from '@testing-library/react-hooks'; import { EventEmitter } from 'events'; -import React from 'react'; import { Participant, Room } from 'twilio-video'; import useSelectedParticipant, { SelectedParticipantProvider } from './useSelectedParticipant'; +import { useAppState } from '../../../state'; + +jest.mock('../../../state'); + +const mockUseAppState = useAppState as jest.Mock; + +mockUseAppState.mockImplementation(() => ({ isGalleryViewActive: false })); describe('the useSelectedParticipant hook', () => { let mockRoom: Room; @@ -56,4 +62,14 @@ describe('the useSelectedParticipant hook', () => { }); expect(result.current[0]).toBe('mockParticipant'); }); + + it('should set "null" as the selected participant when gallery view is active', () => { + act(() => result.current[1]('mockParticipant' as any)); + expect(result.current[0]).toBe('mockParticipant'); + + mockUseAppState.mockImplementationOnce(() => ({ isGalleryViewActive: true })); + act(() => result.current[1]('mockParticipant' as any)); + + expect(result.current[0]).toBe(null); + }); }); diff --git a/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.tsx b/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.tsx index 23f876d87..5a928f533 100644 --- a/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.tsx +++ b/src/components/VideoProvider/useSelectedParticipant/useSelectedParticipant.tsx @@ -1,5 +1,6 @@ import React, { createContext, useContext, useState, useEffect } from 'react'; import { Participant, Room } from 'twilio-video'; +import { useAppState } from '../../../state'; type selectedParticipantContextType = [Participant | null, (participant: Participant) => void]; @@ -16,10 +17,17 @@ type SelectedParticipantProviderProps = { }; export function SelectedParticipantProvider({ room, children }: SelectedParticipantProviderProps) { + const { isGalleryViewActive } = useAppState(); const [selectedParticipant, _setSelectedParticipant] = useState(null); const setSelectedParticipant = (participant: Participant) => _setSelectedParticipant(prevParticipant => (prevParticipant === participant ? null : participant)); + useEffect(() => { + if (isGalleryViewActive) { + _setSelectedParticipant(null); + } + }, [isGalleryViewActive]); + useEffect(() => { if (room) { const onDisconnect = () => _setSelectedParticipant(null);