Skip to content

Commit

Permalink
Video 4673 remove preflight test (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
olipyskoty authored Apr 13, 2021
1 parent 7f2c6f8 commit 0f76df6
Show file tree
Hide file tree
Showing 18 changed files with 5 additions and 704 deletions.
9 changes: 1 addition & 8 deletions src/__mocks__/twilio-video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@ class MockTrack extends EventEmitter {
}
}

class MockPreflightTest extends EventEmitter {
stop = jest.fn();
}

const mockPreflightTest = new MockPreflightTest();

const twilioVideo = {
connect: jest.fn(() => Promise.resolve(mockRoom)),
createLocalTracks: jest.fn(() => Promise.resolve([new MockTrack('video'), new MockTrack('audio')])),
createLocalVideoTrack: jest.fn(() => Promise.resolve(new MockTrack('video'))),
testPreflight: jest.fn(() => mockPreflightTest),
};

export { mockRoom, mockPreflightTest };
export { mockRoom };
export default twilioVideo;
10 changes: 0 additions & 10 deletions src/components/IntroContainer/IntroContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,4 @@ describe('the IntroContainer component', () => {

expect(wrapper.find('span').text()).toBe('Test Content');
});

it('should render subcontent when provided', () => {
const wrapper = shallow(
<IntroContainer subContent={<h1>Test Sub Content</h1>}>
<span>Test Content</span>
</IntroContainer>
);

expect(wrapper.find('h1').text()).toBe('Test Sub Content');
});
});
7 changes: 0 additions & 7 deletions src/components/IntroContainer/IntroContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,10 @@ const useStyles = makeStyles((theme: Theme) => ({
fontSize: '1.1rem',
},
},
subContentContainer: {
position: 'absolute',
marginTop: '1em',
width: '100%',
},
}));

interface IntroContainerProps {
children: React.ReactNode;
subContent?: React.ReactNode;
}

const IntroContainer = (props: IntroContainerProps) => {
Expand All @@ -120,7 +114,6 @@ const IntroContainer = (props: IntroContainerProps) => {
</div>
<div className={classes.content}>{props.children}</div>
</div>
{props.subContent && <div className={classes.subContentContainer}>{props.subContent}</div>}
</div>
</div>
);
Expand Down
48 changes: 2 additions & 46 deletions src/components/PreJoinScreens/PreJoinScreens.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { act } from 'react-dom/test-utils';
import DeviceSelectionScreen from './DeviceSelectionScreen/DeviceSelectionScreen';
import MediaErrorSnackbar from './MediaErrorSnackbar/MediaErrorSnackbar';
import { mount, shallow } from 'enzyme';
import PreflightTest from './PreflightTest/PreflightTest';
import PreJoinScreens from './PreJoinScreens';
import RoomNameScreen from './RoomNameScreen/RoomNameScreen';
import { useParams } from 'react-router-dom';
import { useAppState } from '../../state';
import useVideoContext from '../../hooks/useVideoContext/useVideoContext';
import Video from 'twilio-video';

delete window.location;
// @ts-ignore
Expand All @@ -25,6 +23,7 @@ Object.defineProperty(window.history, 'replaceState', { value: mockReplaceState
jest.mock('../../state');
jest.mock('react-router-dom', () => ({ useParams: jest.fn() }));
jest.mock('../../hooks/useVideoContext/useVideoContext');
jest.mock('./MediaErrorSnackbar/MediaErrorSnackbar', () => () => null);
const mockUseAppState = useAppState as jest.Mock<any>;
const mockUseParams = useParams as jest.Mock<any>;
const mockUseVideoContext = useVideoContext as jest.Mock<any>;
Expand Down Expand Up @@ -80,49 +79,6 @@ describe('the PreJoinScreens component', () => {
expect(wrapper.find(DeviceSelectionScreen).exists()).toBe(true);
});

it('should render the PreflightTest component only while on the DeviceSelection step', () => {
const wrapper = shallow(<PreJoinScreens />);

expect(wrapper.prop('subContent')).toBe(false);
expect(wrapper.find(DeviceSelectionScreen).exists()).toBe(false);

const handleSubmit = wrapper.find(RoomNameScreen).prop('handleSubmit');
handleSubmit({ preventDefault: () => {} } as any);

expect(wrapper.prop('subContent')).toEqual(
<>
<PreflightTest />
<MediaErrorSnackbar />
</>
);
expect(wrapper.find(DeviceSelectionScreen).exists()).toBe(true);
});

it('should not render the PreflightTest component when the Video.testPreflight function does not exist', () => {
// Save the testPreflight function
const testPreflightFunction = Video.testPreflight;

// @ts-ignore
delete Video.testPreflight;
const wrapper = shallow(<PreJoinScreens />);

expect(wrapper.prop('subContent')).toBe(false);
expect(wrapper.find(DeviceSelectionScreen).exists()).toBe(false);

const handleSubmit = wrapper.find(RoomNameScreen).prop('handleSubmit');
handleSubmit({ preventDefault: () => {} } as any);

expect(wrapper.prop('subContent')).toEqual(
<>
{undefined}
<MediaErrorSnackbar />
</>
);

// Restore the testPreflight function to the mock
Video.testPreflight = testPreflightFunction;
});

it('should populate the room name from the URL and switch to the DeviceSelectionScreen when the displayName is present for the user', () => {
const wrapper = mount(<PreJoinScreens />);
const roomName = wrapper.find(DeviceSelectionScreen).prop('roomName');
Expand Down Expand Up @@ -154,7 +110,7 @@ describe('the PreJoinScreens component', () => {
wrapper.update();
});

const error = wrapper.children().prop('subContent').props.children[1].props.error;
const error = wrapper.find(MediaErrorSnackbar).prop('error');
expect(error).toBe('testError');
expect(mockGetAudioAndVideoTracks).toHaveBeenCalledTimes(1); // This makes sure that 'getAudioAndVideoTracks' isn't called repeatedly
});
Expand Down
12 changes: 2 additions & 10 deletions src/components/PreJoinScreens/PreJoinScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import React, { useState, useEffect, FormEvent } from 'react';
import DeviceSelectionScreen from './DeviceSelectionScreen/DeviceSelectionScreen';
import IntroContainer from '../IntroContainer/IntroContainer';
import MediaErrorSnackbar from './MediaErrorSnackbar/MediaErrorSnackbar';
import PreflightTest from './PreflightTest/PreflightTest';
import RoomNameScreen from './RoomNameScreen/RoomNameScreen';
import { useAppState } from '../../state';
import { useParams } from 'react-router-dom';
import useVideoContext from '../../hooks/useVideoContext/useVideoContext';
import Video from 'twilio-video';

export enum Steps {
roomNameStep,
Expand Down Expand Up @@ -53,15 +51,9 @@ export default function PreJoinScreens() {
setStep(Steps.deviceSelectionStep);
};

const SubContent = (
<>
{Video.testPreflight && <PreflightTest />}
<MediaErrorSnackbar error={mediaError} />
</>
);

return (
<IntroContainer subContent={step === Steps.deviceSelectionStep && SubContent}>
<IntroContainer>
<MediaErrorSnackbar error={mediaError} />
{step === Steps.roomNameStep && (
<RoomNameScreen
name={name}
Expand Down
69 changes: 0 additions & 69 deletions src/components/PreJoinScreens/PreflightTest/PreflightTest.test.tsx

This file was deleted.

93 changes: 0 additions & 93 deletions src/components/PreJoinScreens/PreflightTest/PreflightTest.tsx

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0f76df6

Please sign in to comment.