Skip to content

Commit

Permalink
increase prettier width to 120 (twilio#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
timmydoza authored and timmydoza committed Mar 6, 2020
1 parent ab3ed58 commit 2db6e9b
Show file tree
Hide file tree
Showing 33 changed files with 85 additions and 291 deletions.
8 changes: 2 additions & 6 deletions components/AudioTrack/AudioTrack.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ describe('the AudioTrack component', () => {
it('should call the attach method when the component mounts', () => {
const mockTrack = { attach: jest.fn(), detach: jest.fn() } as any;
render(<AudioTrack track={mockTrack} />);
expect(mockTrack.attach).toHaveBeenCalledWith(
expect.any(window.HTMLAudioElement)
);
expect(mockTrack.attach).toHaveBeenCalledWith(expect.any(window.HTMLAudioElement));
expect(mockTrack.detach).not.toHaveBeenCalled();
});

it('it should call the detach method when the component unmounts', () => {
const mockTrack = { attach: jest.fn(), detach: jest.fn() } as any;
const { unmount } = render(<AudioTrack track={mockTrack} />);
unmount();
expect(mockTrack.detach).toHaveBeenCalledWith(
expect.any(window.HTMLAudioElement)
);
expect(mockTrack.detach).toHaveBeenCalledWith(expect.any(window.HTMLAudioElement));
});
});
4 changes: 1 addition & 3 deletions components/LocalVideoPreview/LocalVideoPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('the LocalVideoPreview component', () => {
it('should render null when there are no "camera" tracks', () => {
mockedVideoContext.mockImplementation(() => {
return {
localTracks: [
{ name: 'microphone', attach: jest.fn(), detach: jest.fn() },
],
localTracks: [{ name: 'microphone', attach: jest.fn(), detach: jest.fn() }],
} as any;
});
const { container } = render(<LocalVideoPreview />);
Expand Down
4 changes: 1 addition & 3 deletions components/LocalVideoPreview/LocalVideoPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { useVideoContext } from '../../hooks/context';
export default function LocalVideoPreview() {
const { localTracks } = useVideoContext();

const videoTrack = localTracks.find(
track => track.name === 'camera'
) as IVideoTrack;
const videoTrack = localTracks.find(track => track.name === 'camera') as IVideoTrack;

return videoTrack ? <VideoTrack track={videoTrack} isLocal /> : null;
}
32 changes: 8 additions & 24 deletions components/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,28 @@ const mockedUseVideoContext = useVideoContext as jest.Mock<IVideoContext>;
describe('the Menu component', () => {
it('should hide inputs when connected to a room', () => {
mockedUseRoomState.mockImplementation(() => 'connected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: false } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: false } as any));
const { container } = render(<Menu />);
expect(container.querySelector('input')).toEqual(null);
});

it('should display inputs when disconnected from a room', () => {
mockedUseRoomState.mockImplementation(() => 'disconnected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: false } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: false } as any));
const { container } = render(<Menu />);
expect(container.querySelectorAll('input').length).toEqual(2);
});

it('should display a loading spinner when connecting to a room', () => {
mockedUseRoomState.mockImplementation(() => 'disconnected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: true } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: true } as any));
const { container } = render(<Menu />);
expect(container.querySelector('svg')).not.toBeNull();
});

it('should disable the Join Room button when the Name input or Room input are empty', () => {
mockedUseRoomState.mockImplementation(() => 'disconnected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: false } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: false } as any));
const { getByLabelText, getByRole } = render(<Menu />);
expect(getByRole('button').getAttribute('disabled')).toEqual('');
fireEvent.change(getByLabelText('Name'), { target: { value: 'Foo' } });
Expand All @@ -57,9 +49,7 @@ describe('the Menu component', () => {

it('should enable the Join Room button when the Name input and Room input are not empty', () => {
mockedUseRoomState.mockImplementation(() => 'disconnected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: false } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: false } as any));
const { getByLabelText, getByRole } = render(<Menu />);
fireEvent.change(getByLabelText('Name'), { target: { value: 'Foo' } });
fireEvent.change(getByLabelText('Room'), { target: { value: 'Foo' } });
Expand All @@ -68,9 +58,7 @@ describe('the Menu component', () => {

it('should disable the Join Room button when connecting to a room', () => {
mockedUseRoomState.mockImplementation(() => 'disconnected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: true } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: true } as any));
const { getByLabelText, getByRole } = render(<Menu />);
fireEvent.change(getByLabelText('Name'), { target: { value: 'Foo' } });
fireEvent.change(getByLabelText('Room'), { target: { value: 'Foo' } });
Expand All @@ -79,9 +67,7 @@ describe('the Menu component', () => {

it('should dispatch a redux action when the Join Room button is clicked', () => {
mockedUseRoomState.mockImplementation(() => 'disconnected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: false } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: false } as any));
const { getByLabelText, getByRole } = render(<Menu />);
fireEvent.change(getByLabelText('Name'), { target: { value: 'Username' } });
fireEvent.change(getByLabelText('Room'), { target: { value: 'Roomname' } });
Expand All @@ -91,9 +77,7 @@ describe('the Menu component', () => {

it('should dispatch a redux action when the Leave Room button is clicked', () => {
mockedUseRoomState.mockImplementation(() => 'connected');
mockedUseVideoContext.mockImplementation(
() => ({ isConnecting: false } as any)
);
mockedUseVideoContext.mockImplementation(() => ({ isConnecting: false } as any));
const { getByRole } = render(<Menu />);
fireEvent.click(getByRole('button'));
expect(receiveToken).toHaveBeenCalledWith('');
Expand Down
7 changes: 1 addition & 6 deletions components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ export default function Menu() {
onChange={handleRoomNameChange}
margin="dense"
/>
<Button
type="submit"
color="primary"
variant="contained"
disabled={isConnecting || !name || !roomName}
>
<Button type="submit" color="primary" variant="contained" disabled={isConnecting || !name || !roomName}>
Join Room
</Button>
{isConnecting && <CircularProgress></CircularProgress>}
Expand Down
12 changes: 3 additions & 9 deletions components/NewtorkQualityLevel/NetworkQualityLevel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ import NetworkQualityLevel from './NetworkQualityLevel';

describe('the NetworkQualityLevel component', () => {
it('should render correctly for level 5', () => {
const tree = renderer
.create(<NetworkQualityLevel qualityLevel={5} />)
.toJSON();
const tree = renderer.create(<NetworkQualityLevel qualityLevel={5} />).toJSON();
expect(tree).toMatchSnapshot();
});

it('should render correctly for level 3', () => {
const tree = renderer
.create(<NetworkQualityLevel qualityLevel={3} />)
.toJSON();
const tree = renderer.create(<NetworkQualityLevel qualityLevel={3} />).toJSON();
expect(tree).toMatchSnapshot();
});

it('should render correctly for level 0', () => {
const tree = renderer
.create(<NetworkQualityLevel qualityLevel={0} />)
.toJSON();
const tree = renderer.create(<NetworkQualityLevel qualityLevel={0} />).toJSON();
expect(tree).toMatchSnapshot();
});
});
6 changes: 1 addition & 5 deletions components/NewtorkQualityLevel/NetworkQualityLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ const Container = styled('div')({

const STEP = 3;

export default function NetworkQualityLevel({
qualityLevel,
}: {
qualityLevel: number | null;
}) {
export default function NetworkQualityLevel({ qualityLevel }: { qualityLevel: number | null }) {
if (qualityLevel === null) return null;
return (
<Container>
Expand Down
10 changes: 2 additions & 8 deletions components/Participant/Participant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ interface ParticipantProps {
disableAudio?: boolean;
}

export default function Participant({
participant,
disableAudio,
}: ParticipantProps) {
export default function Participant({ participant, disableAudio }: ParticipantProps) {
return (
<ParticipantInfo participant={participant}>
<ParticipantTracks
participant={participant}
disableAudio={disableAudio}
/>
<ParticipantTracks participant={participant} disableAudio={disableAudio} />
</ParticipantInfo>
);
}
41 changes: 10 additions & 31 deletions components/ParticipantInfo/ParticipantInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import ParticipantInfo from './ParticipantInfo';
import { shallow } from 'enzyme';
import usePublications from '../../hooks/usePublications/usePublications';

jest.mock(
'../../hooks/useParticipantNetworkQualityLevel/useParticipantNetworkQualityLevel',
() => () => 4
);
jest.mock('../../hooks/useParticipantNetworkQualityLevel/useParticipantNetworkQualityLevel', () => () => 4);

jest.mock('../../hooks/usePublications/usePublications');
const mockUsePublications = usePublications as jest.Mock<any>;
Expand All @@ -15,45 +12,31 @@ describe('the ParticipantInfo component', () => {
it('should render correctly', () => {
mockUsePublications.mockImplementation(() => []);
const wrapper = shallow(
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>
mock children
</ParticipantInfo>
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>mock children</ParticipantInfo>
);
expect(wrapper).toMatchSnapshot();
});

it('should display MicOff icon when microphone is disabled', () => {
mockUsePublications.mockImplementation(() => [
{ trackName: 'microphone', isTrackEnabled: false },
]);
mockUsePublications.mockImplementation(() => [{ trackName: 'microphone', isTrackEnabled: false }]);
const wrapper = shallow(
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>
mock children
</ParticipantInfo>
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>mock children</ParticipantInfo>
);
expect(wrapper.find('MicOffIcon').exists()).toEqual(true);
});

it('should not display MicOff icon when microphone is enabled', () => {
mockUsePublications.mockImplementation(() => [
{ trackName: 'microphone', isTrackEnabled: true },
]);
mockUsePublications.mockImplementation(() => [{ trackName: 'microphone', isTrackEnabled: true }]);
const wrapper = shallow(
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>
mock children
</ParticipantInfo>
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>mock children</ParticipantInfo>
);
expect(wrapper.find('MicOffIcon').exists()).toEqual(false);
});

it('should add hideVideoProp to InfoContainer component when video is disabled', () => {
mockUsePublications.mockImplementation(() => [
{ trackName: 'camera', isTrackEnabled: false },
]);
mockUsePublications.mockImplementation(() => [{ trackName: 'camera', isTrackEnabled: false }]);
const wrapper = shallow(
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>
mock children
</ParticipantInfo>
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>mock children</ParticipantInfo>
);
expect(
wrapper
Expand All @@ -64,13 +47,9 @@ describe('the ParticipantInfo component', () => {
});

it('should not add hideVideoProp to InfoContainer component when video is enabled', () => {
mockUsePublications.mockImplementation(() => [
{ trackName: 'camera', isTrackEnabled: true },
]);
mockUsePublications.mockImplementation(() => [{ trackName: 'camera', isTrackEnabled: true }]);
const wrapper = shallow(
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>
mock children
</ParticipantInfo>
<ParticipantInfo participant={{ identity: 'mockIdentity' } as any}>mock children</ParticipantInfo>
);
expect(
wrapper
Expand Down
16 changes: 4 additions & 12 deletions components/ParticipantInfo/ParticipantInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const InfoContainer = styled('div')({
height: '100%',
padding: '0.4em',
width: '100%',
background: ({ hideVideo }: { hideVideo?: boolean }) =>
hideVideo ? 'black' : 'transparent',
background: ({ hideVideo }: { hideVideo?: boolean }) => (hideVideo ? 'black' : 'transparent'),
});

const Identity = styled('h4')({
Expand All @@ -40,18 +39,11 @@ interface ParticipantInfoProps {
children: React.ReactNode;
}

export default function ParticipantInfo({
participant,
children,
}: ParticipantInfoProps) {
export default function ParticipantInfo({ participant, children }: ParticipantInfoProps) {
const networkQualityLevel = useParticipantNetworkQualityLevel(participant);
const publications = usePublications(participant);
const isAudioEnabled = usePublicationIsTrackEnabled(
publications.find(p => p.trackName === 'microphone')
);
const isVideoEnabled = usePublicationIsTrackEnabled(
publications.find(p => p.trackName === 'camera')
);
const isAudioEnabled = usePublicationIsTrackEnabled(publications.find(p => p.trackName === 'microphone'));
const isVideoEnabled = usePublicationIsTrackEnabled(publications.find(p => p.trackName === 'camera'));

return (
<Container>
Expand Down
12 changes: 3 additions & 9 deletions components/ParticipantTracks/ParticipantTracks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ import usePublications from '../../hooks/usePublications/usePublications';
import { shallow } from 'enzyme';
import { useVideoContext } from '../../hooks/context';

jest.mock('../../hooks/usePublications/usePublications', () =>
jest.fn(() => [{ trackSid: 0 }, { trackSid: 1 }])
);
jest.mock('../../hooks/usePublications/usePublications', () => jest.fn(() => [{ trackSid: 0 }, { trackSid: 1 }]));
jest.mock('../../hooks/context');

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} />
);
const wrapper = shallow(<ParticipantTracks participant={'mockParticipant' as any} />);
expect(usePublications).toHaveBeenCalledWith('mockParticipant');
expect(wrapper).toMatchSnapshot();
});
Expand All @@ -25,9 +21,7 @@ describe('the ParticipantTracks component', () => {
mockUseVideoContext.mockImplementation(() => ({
room: { localParticipant: 'mockParticipant' },
}));
const wrapper = shallow(
<ParticipantTracks participant={'mockParticipant' as any} />
);
const wrapper = shallow(<ParticipantTracks participant={'mockParticipant' as any} />);
expect(
wrapper
.find('Publication')
Expand Down
5 changes: 1 addition & 4 deletions components/ParticipantTracks/ParticipantTracks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ interface ParticipantTracksProps {
disableAudio?: boolean;
}

export default function ParticipantTracks({
participant,
disableAudio,
}: ParticipantTracksProps) {
export default function ParticipantTracks({ participant, disableAudio }: ParticipantTracksProps) {
const { room } = useVideoContext();
const publications = usePublications(participant);
const isLocal = participant === room.localParticipant;
Expand Down
18 changes: 3 additions & 15 deletions components/Publication/Publication.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ describe('the Publication component', () => {
it('should render a VideoTrack when the track has name "camera"', () => {
mockUseTrack.mockImplementation(() => ({ name: 'camera' }));
const wrapper = shallow(
<Publication
isLocal
publication={'mockPublication' as any}
participant={'mockParticipant' as any}
/>
<Publication isLocal publication={'mockPublication' as any} participant={'mockParticipant' as any} />
);
expect(useTrack).toHaveBeenCalledWith('mockPublication');
expect(wrapper.find('VideoTrack').length).toBe(1);
Expand All @@ -23,11 +19,7 @@ describe('the Publication component', () => {
it('should render an AudioTrack when the track has name "microphone"', () => {
mockUseTrack.mockImplementation(() => ({ name: 'microphone' }));
const wrapper = shallow(
<Publication
isLocal
publication={'mockPublication' as any}
participant={'mockParticipant' as any}
/>
<Publication isLocal publication={'mockPublication' as any} participant={'mockParticipant' as any} />
);
expect(useTrack).toHaveBeenCalledWith('mockPublication');
expect(wrapper.find('AudioTrack').length).toBe(1);
Expand All @@ -50,11 +42,7 @@ describe('the Publication component', () => {
it('should render null when there is no track', () => {
mockUseTrack.mockImplementation(() => null);
const wrapper = shallow(
<Publication
isLocal
publication={'mockPublication' as any}
participant={'mockParticipant' as any}
/>
<Publication isLocal publication={'mockPublication' as any} participant={'mockParticipant' as any} />
);
expect(useTrack).toHaveBeenCalledWith('mockPublication');
expect(wrapper.find('*').length).toBe(0);
Expand Down
Loading

0 comments on commit 2db6e9b

Please sign in to comment.