Skip to content

Commit 6c9f665

Browse files
Tim MendozaGitHub Enterprise
authored andcommitted
Merge pull request #18 from tmendoza/feature/design-refresh-fix-cypress-tests
Feature/design refresh fix cypress tests
2 parents a9d74a2 + a27b6d9 commit 6c9f665

File tree

10 files changed

+54
-33
lines changed

10 files changed

+54
-33
lines changed

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"video": false,
3-
"defaultCommandTimeout": 10000,
3+
"defaultCommandTimeout": 30000,
44
"baseUrl": "http://localhost:3000",
55
"reporter": "cypress-multi-reporters",
66
"reporterOptions": {

cypress/integration/twilio-video.spec.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ context('A video app user', () => {
1212
describe('before entering a room', () => {
1313
it('should see their audio level indicator moving in the media device panel', () => {
1414
cy.visit('/');
15+
16+
cy.get('#input-user-name').type('testuser');
17+
cy.get('#input-room-name').type(getRoomName());
18+
cy.get('[type="submit"]').click();
19+
1520
cy.get('clipPath rect')
1621
.invoke('attr', 'y')
17-
.should('be', 21);
22+
.should('be', 14);
1823
cy.get('clipPath rect')
1924
.invoke('attr', 'y')
20-
.should('be.lessThan', 21);
25+
.should('be.lessThan', 14);
2126
});
2227
});
2328

@@ -34,7 +39,7 @@ context('A video app user', () => {
3439
});
3540

3641
it('should be inside the correct room', () => {
37-
cy.get('header').should('contain', ROOM_NAME);
42+
cy.get('footer').should('contain', ROOM_NAME);
3843
cy.getParticipant('testuser').should('contain', 'testuser');
3944
});
4045

@@ -53,10 +58,10 @@ context('A video app user', () => {
5358
cy.getParticipant('test1')
5459
.get('clipPath rect')
5560
.invoke('attr', 'y')
56-
.should('be', 21);
61+
.should('be', 14);
5762
cy.get('clipPath rect')
5863
.invoke('attr', 'y')
59-
.should('be.lessThan', 21);
64+
.should('be.lessThan', 14);
6065
});
6166

6267
it('should see other participants disconnect when they close their browser', () => {
@@ -158,32 +163,32 @@ context('A video app user', () => {
158163
it('should see participant "test1" when they are the dominant speaker', () => {
159164
cy.task('toggleParticipantAudio', 'test2');
160165
cy.task('toggleParticipantAudio', 'test3');
161-
cy.getParticipant('test2').find('[data-cy-audio-mute-icon]');
162-
cy.getParticipant('test3').find('[data-cy-audio-mute-icon]');
166+
cy.getParticipant('test2').find('[data-test-audio-mute-icon]');
167+
cy.getParticipant('test3').find('[data-test-audio-mute-icon]');
163168
cy.getParticipant('test1').shouldBeSameVideoAs('[data-cy-main-participant]');
164169
});
165170

166171
it('should see participant "test2" when they are the dominant speaker', () => {
167172
cy.task('toggleParticipantAudio', 'test1');
168173
cy.task('toggleParticipantAudio', 'test2');
169-
cy.getParticipant('test1').find('[data-cy-audio-mute-icon]');
170-
cy.getParticipant('test3').find('[data-cy-audio-mute-icon]');
174+
cy.getParticipant('test1').find('[data-test-audio-mute-icon]');
175+
cy.getParticipant('test3').find('[data-test-audio-mute-icon]');
171176
cy.getParticipant('test2').shouldBeSameVideoAs('[data-cy-main-participant]');
172177
});
173178

174179
it('should see participant "test3" when they are the dominant speaker', () => {
175180
cy.task('toggleParticipantAudio', 'test2');
176181
cy.task('toggleParticipantAudio', 'test3');
177-
cy.getParticipant('test1').find('[data-cy-audio-mute-icon]');
178-
cy.getParticipant('test2').find('[data-cy-audio-mute-icon]');
182+
cy.getParticipant('test1').find('[data-test-audio-mute-icon]');
183+
cy.getParticipant('test2').find('[data-test-audio-mute-icon]');
179184
cy.getParticipant('test3').shouldBeSameVideoAs('[data-cy-main-participant]');
180185
});
181186

182187
it('should see participant "test3" when there is no dominant speaker', () => {
183188
cy.task('toggleParticipantAudio', 'test3');
184-
cy.getParticipant('test1').find('[data-cy-audio-mute-icon]');
185-
cy.getParticipant('test2').find('[data-cy-audio-mute-icon]');
186-
cy.getParticipant('test3').find('[data-cy-audio-mute-icon]');
189+
cy.getParticipant('test1').find('[data-test-audio-mute-icon]');
190+
cy.getParticipant('test2').find('[data-test-audio-mute-icon]');
191+
cy.getParticipant('test3').find('[data-test-audio-mute-icon]');
187192
cy.getParticipant('test3').shouldBeSameVideoAs('[data-cy-main-participant]');
188193
});
189194
});

cypress/plugins/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const participants = {};
88
module.exports = (on, config) => {
99
const participantFunctions = {
1010
addParticipant: async ({ name, roomName, color }) => {
11-
const args = ['--use-fake-ui-for-media-stream', '--use-fake-device-for-media-stream'];
11+
const args = ['--use-fake-ui-for-media-stream', '--use-fake-device-for-media-stream', `--window-size=1920,1080`];
1212

1313
if (color) {
1414
args.push(`--use-file-for-fake-video-capture=cypress/fixtures/${color}.y4m`);
@@ -20,28 +20,27 @@ module.exports = (on, config) => {
2020
});
2121
const page = (participants[name] = await browser.newPage()); // keep track of this participant for future use
2222
await page.goto(config.baseUrl);
23-
await page.type('#menu-name', name);
24-
await page.type('#menu-room', roomName);
23+
await page.type('#input-user-name', name);
24+
await page.type('#input-room-name', roomName);
2525
await page.click('[type="submit"]');
26+
await page.waitForSelector('[data-cy-join-now]:not([disabled])');
27+
await page.click('[data-cy-join-now]');
2628
await page.waitForSelector('[data-cy-main-participant] video');
2729
return Promise.resolve(null);
2830
},
2931
toggleParticipantAudio: async name => {
3032
const page = participants[name];
31-
await page.click('body'); // To make controls reappear
3233
await page.click('[data-cy-audio-toggle]');
3334
return Promise.resolve(null);
3435
},
3536
shareParticipantScreen: async name => {
3637
const page = participants[name];
37-
await page.click('body');
38-
await page.click('[title="Share Screen"]');
38+
await page.click('[data-cy-share-screen]');
3939
return Promise.resolve(null);
4040
},
4141
removeParticipant: async name => {
4242
const page = participants[name];
43-
await page.click('body');
44-
await page.click('[title="End Call"]');
43+
await page.click('[data-cy-disconnect]');
4544
await page.close();
4645
delete participants[name];
4746
return Promise.resolve(null);

cypress/support/commands.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import detectSound from './detectSound';
22

33
Cypress.Commands.add('joinRoom', (username, roomname) => {
44
cy.visit('/');
5-
cy.get('#menu-name').type(username);
6-
cy.get('#menu-room').type(roomname);
5+
cy.get('#input-user-name').type(username);
6+
cy.get('#input-room-name').type(roomname);
77
cy.get('[type="submit"]').click();
8+
cy.get('[data-cy-join-now]').click();
89
cy.get('[data-cy-main-participant]');
910
});
1011

1112
Cypress.Commands.add('leaveRoom', () => {
1213
cy.wait(500);
1314
cy.get('body').click(); // Makes controls reappear
14-
cy.get('[title="End Call"]').click();
15+
cy.get('footer [data-cy-disconnect]').click();
1516
cy.task('removeAllParticipants');
16-
cy.get('#menu-room');
17+
cy.get('[type="submit"]');
1718
});
1819

1920
Cypress.Commands.add('shouldBeColor', { prevSubject: 'element' }, (subject, color) => {
@@ -56,7 +57,7 @@ Cypress.Commands.add('shouldBeMakingSound', { prevSubject: 'element' }, subject
5657
}
5758
);
5859
});
59-
60+
6061
cy.window()
6162
.then(win => {
6263
const participantIdentity = subject.attr('data-cy-participant');

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ module.exports = {
88
snapshotSerializers: ['enzyme-to-json/serializer'],
99
setupFiles: ['<rootDir>/src/setupTests.ts'],
1010
reporters: ['default', 'jest-junit'],
11+
12+
// We don't need to test the static JSX in the icons folder, so let's exclude it from our test coverage report
13+
coveragePathIgnorePatterns: ['node_modules', 'src/icons'],
1114
};

src/components/Buttons/EndCallButton/EndCallButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function EndCallButton(props: { className?: string }) {
2323
const { room } = useVideoContext();
2424

2525
return (
26-
<Button onClick={() => room.disconnect()} className={clsx(classes.button, props.className)}>
26+
<Button onClick={() => room.disconnect()} className={clsx(classes.button, props.className)} data-cy-disconnect>
2727
Disconnect
2828
</Button>
2929
);

src/components/Buttons/ToogleScreenShareButton/ToggleScreenShareButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default function ToggleScreenShareButton(props: { disabled?: boolean }) {
6060
onClick={toggleScreenShare}
6161
disabled={isDisabled}
6262
startIcon={<ScreenShareIcon />}
63+
data-cy-share-screen
6364
>
6465
{SCREEN_SHARE_TEXT}
6566
</Button>

src/components/MainParticipantInfo/MainParticipantInfo.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import clsx from 'clsx';
33
import { makeStyles, Theme } from '@material-ui/core/styles';
4-
import { LocalVideoTrack, Participant, RemoteVideoTrack } from 'twilio-video';
4+
import { LocalAudioTrack, LocalVideoTrack, Participant, RemoteAudioTrack, RemoteVideoTrack } from 'twilio-video';
55

66
import AvatarIcon from '../../icons/AvatarIcon';
77
import Typography from '@material-ui/core/Typography';
@@ -12,6 +12,7 @@ import useScreenShareParticipant from '../../hooks/useScreenShareParticipant/use
1212
import useTrack from '../../hooks/useTrack/useTrack';
1313
import useVideoContext from '../../hooks/useVideoContext/useVideoContext';
1414
import useParticipantIsReconnecting from '../../hooks/useParticipantIsReconnecting/useParticipantIsReconnecting';
15+
import AudioLevelIndicator from '../AudioLevelIndicator/AudioLevelIndicator';
1516

1617
const useStyles = makeStyles((theme: Theme) => ({
1718
container: {
@@ -22,7 +23,7 @@ const useStyles = makeStyles((theme: Theme) => ({
2223
identity: {
2324
background: 'rgba(0, 0, 0, 0.5)',
2425
color: 'white',
25-
padding: '0.1em 0.3em',
26+
padding: '0.1em 0.3em 0.1em 0',
2627
fontSize: '1.2em',
2728
display: 'inline-flex',
2829
'& svg': {
@@ -92,18 +93,23 @@ export default function MainParticipantInfo({ participant, children }: MainParti
9293
const videoTrack = useTrack(screenSharePublication || videoPublication);
9394
const isVideoEnabled = Boolean(videoTrack);
9495

96+
const audioPublication = publications.find(p => p.kind === 'audio');
97+
const audioTrack = useTrack(audioPublication) as LocalAudioTrack | RemoteAudioTrack | undefined;
98+
9599
const isVideoSwitchedOff = useIsTrackSwitchedOff(videoTrack as LocalVideoTrack | RemoteVideoTrack);
96100
const isParticipantReconnecting = useParticipantIsReconnecting(participant);
97101

98102
return (
99103
<div
100104
data-cy-main-participant
105+
data-cy-participant={participant.identity}
101106
className={clsx(classes.container, {
102107
[classes.fullWidth]: !isRemoteParticipantScreenSharing,
103108
})}
104109
>
105110
<div className={classes.infoContainer}>
106111
<div className={classes.identity}>
112+
<AudioLevelIndicator audioTrack={audioTrack} />
107113
<Typography variant="body1" color="inherit">
108114
{participant.identity}
109115
{isLocal && ' (You)'}

src/components/ParticipantInfo/ParticipantInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export default function ParticipantInfo({
165165
const videoTrack = useTrack(videoPublication);
166166
const isVideoSwitchedOff = useIsTrackSwitchedOff(videoTrack as LocalVideoTrack | RemoteVideoTrack);
167167

168-
const audioTrack = useTrack(audioPublication) as LocalAudioTrack | RemoteAudioTrack;
168+
const audioTrack = useTrack(audioPublication) as LocalAudioTrack | RemoteAudioTrack | undefined;
169169
const isParticipantReconnecting = useParticipantIsReconnecting(participant);
170170

171171
const classes = useStyles();

src/components/PreJoinScreens/DeviceSelectionScreen/DeviceSelectionScreen.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ export default function DeviceSelectionScreen({ name, roomName, setStep }: Devic
9797
<Button variant="outlined" color="primary" onClick={() => setStep(Steps.roomNameStep)}>
9898
Cancel
9999
</Button>
100-
<Button variant="contained" color="primary" onClick={handleJoin} disabled={disableButtons}>
100+
<Button
101+
variant="contained"
102+
color="primary"
103+
data-cy-join-now
104+
onClick={handleJoin}
105+
disabled={disableButtons}
106+
>
101107
Join Now
102108
</Button>
103109
</div>

0 commit comments

Comments
 (0)