Skip to content

Commit

Permalink
Fix ParticipantTracks tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Mendoza committed Sep 11, 2020
1 parent f2a6eb4 commit 84a2f14
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
22 changes: 1 addition & 21 deletions src/components/ParticipantTracks/ParticipantTracks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
import React from 'react';
import ParticipantTracks from './ParticipantTracks';
import usePublications from '../../hooks/usePublications/usePublications';
import { shallow } from 'enzyme';
import useVideoContext from '../../hooks/useVideoContext/useVideoContext';
import usePublications from '../../hooks/usePublications/usePublications';

jest.mock('../../hooks/usePublications/usePublications', () =>
jest.fn(() => [
{ trackSid: 0, kind: 'video', trackName: '' },
{ trackSid: 1, kind: 'audio', trackName: '' },
])
);
jest.mock('../../hooks/useVideoContext/useVideoContext');

const mockUsePublications = usePublications as jest.Mock<any>;
const mockUseVideoContext = useVideoContext as jest.Mock<any>;

describe('the ParticipantTracks component', () => {
it('should render an array of publications', () => {
mockUseVideoContext.mockImplementation(() => ({ room: {} }));
const wrapper = shallow(<ParticipantTracks participant={'mockParticipant' as any} />);
expect(usePublications).toHaveBeenCalledWith('mockParticipant');
expect(wrapper).toMatchSnapshot();
});

it('should render publications with "isLocal" set to true when the localParticipant is provided', () => {
mockUseVideoContext.mockImplementation(() => ({
room: { localParticipant: 'mockParticipant' },
}));
const wrapper = shallow(<ParticipantTracks participant={'mockParticipant' as any} />);
expect(
wrapper
.find('Publication')
.first()
.prop('isLocal')
).toEqual(true);
});

it('should filter out any screen share publications', () => {
mockUseVideoContext.mockImplementation(() => ({ room: {} }));
mockUsePublications.mockImplementation(() => [
{ trackName: 'screen', trackSid: 0, kind: 'video' },
{ trackName: 'camera-123456', trackSid: 1, kind: 'video' },
Expand All @@ -54,7 +36,6 @@ describe('the ParticipantTracks component', () => {

describe('with enableScreenShare prop', () => {
it('should filter out camera publications when a screen share publication is present', () => {
mockUseVideoContext.mockImplementation(() => ({ room: {} }));
mockUsePublications.mockImplementation(() => [
{ trackName: 'screen', trackSid: 0, kind: 'video' },
{ trackName: 'camera-123456', trackSid: 1, kind: 'video' },
Expand All @@ -70,7 +51,6 @@ describe('the ParticipantTracks component', () => {
});

it('should render camera publications when a screen share publication is absent', () => {
mockUseVideoContext.mockImplementation(() => ({ room: {} }));
mockUsePublications.mockImplementation(() => [{ trackName: 'camera-123456', trackSid: 1, kind: 'video' }]);
const wrapper = shallow(<ParticipantTracks participant={'mockParticipant' as any} enableScreenShare />);
expect(wrapper.find('Publication').length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports[`the ParticipantTracks component should render an array of publications 1`] = `
<Fragment>
<Publication
isLocal={false}
key="video"
participant="mockParticipant"
publication={
Expand All @@ -15,7 +14,6 @@ exports[`the ParticipantTracks component should render an array of publications
}
/>
<Publication
isLocal={false}
key="audio"
participant="mockParticipant"
publication={
Expand Down

0 comments on commit 84a2f14

Please sign in to comment.