Skip to content

Commit 1a433a2

Browse files
authored
Merge branch 'master' into #101--Accessibility-check-html-element-roles-student
2 parents 3c31c2e + 6e08599 commit 1a433a2

10 files changed

Lines changed: 393 additions & 41 deletions

File tree

‎front/config/test/jest.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ module.exports = {
44
restoreMocks: true,
55
moduleDirectories: ['<rootDir>/src', 'node_modules'],
66
setupFilesAfterEnv: ['<rootDir>/config/test/setup.ts'],
7-
modulePathIgnorePatterns: ['cypress']
7+
modulePathIgnorePatterns: ['cypress'],
8+
moduleNameMapper: {
9+
'^.+\\.png$': '<rootDir>/pngTransform.js',
10+
}
811
};

‎front/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@
4545
"@babel/preset-typescript": "^7.7.4",
4646
"@hot-loader/react-dom": "^16.11.0",
4747
"@svgr/webpack": "^5.4.0",
48+
"@testing-library/dom": "^7.26.6",
4849
"@testing-library/jest-dom": "^4.2.4",
4950
"@testing-library/react": "^9.3.2",
5051
"@testing-library/react-hooks": "^3.2.1",
51-
"@testing-library/user-event": "^12.1.6",
52+
"@testing-library/user-event": "^12.2.2",
5253
"@types/jest": "^24.0.23",
5354
"@types/react": "^16.9.13",
5455
"@types/react-dom": "^16.9.4",

‎front/pngTransform.js‎

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import useEvent from '@testing-library/user-event';
4+
import { CreateSessionComponent } from './create-session.component';
5+
6+
describe('CreateSessionComponent unit tests', () => {
7+
it('should show the elements with the expected roles', () => {
8+
// Arrange
9+
10+
const props = {
11+
handleCreateSession: jest.fn(),
12+
};
13+
14+
// Act
15+
16+
render(<CreateSessionComponent {...props} />);
17+
18+
const main = screen.getByRole('main');
19+
const button = screen.getByRole('button');
20+
const description = screen.getByText('The best tool for sharing code with your students!');
21+
22+
// Assert
23+
24+
expect(main).toBeInTheDocument();
25+
expect(button).toBeInTheDocument();
26+
expect(button).toHaveTextContent('Create Session');
27+
expect(description).toBeInTheDocument();
28+
});
29+
30+
it('should create a new session when clicking the create session button', () => {
31+
// Arrange
32+
33+
const props = {
34+
handleCreateSession: jest.fn(),
35+
};
36+
37+
// Act
38+
39+
render(<CreateSessionComponent {...props} />);
40+
41+
const createSessionButton = screen.getByRole('button');
42+
useEvent.click(createSessionButton);
43+
44+
// Assert
45+
46+
expect(props.handleCreateSession).toHaveBeenCalledTimes(1);
47+
});
48+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import { HeaderComponent } from './header.component';
4+
5+
describe('HeaderComponent unit tests', () => {
6+
it('should show the trainer and the students links when passing valid values', () => {
7+
// Arrange
8+
const props = {
9+
currentTrainerUrl: 'http://current.trainer.url',
10+
currentStudentUrl: 'http://current.student.url',
11+
};
12+
13+
// Act
14+
render(<HeaderComponent {...props} />);
15+
const linkCopyInputs = screen.getAllByRole('textbox');
16+
const linkCopyButtons = screen.getAllByRole('button');
17+
18+
// Assert
19+
20+
expect(linkCopyInputs.length).toBe(2);
21+
expect(linkCopyButtons.length).toBe(2);
22+
linkCopyInputs.forEach(input => expect(input).toHaveAttribute('readonly'));
23+
expect(linkCopyInputs[0]).toHaveValue(props.currentTrainerUrl);
24+
expect(linkCopyInputs[1]).toHaveValue(props.currentStudentUrl);
25+
});
26+
27+
it('should show empty trainer and the students link when passing undefined values', () => {
28+
// Arrange
29+
const props = {
30+
currentTrainerUrl: undefined,
31+
currentStudentUrl: undefined,
32+
};
33+
34+
// Act
35+
render(<HeaderComponent {...props} />);
36+
const linkCopyInputs = screen.getAllByRole('textbox');
37+
38+
// Assert
39+
40+
expect(linkCopyInputs[0]).toBeEmpty();
41+
expect(linkCopyInputs[1]).toBeEmpty();
42+
});
43+
44+
it('should show empty trainer and the students link when passing null values', () => {
45+
// Arrange
46+
const props = {
47+
currentTrainerUrl: null,
48+
currentStudentUrl: null,
49+
};
50+
51+
// Act
52+
render(<HeaderComponent {...props} />);
53+
const linkCopyInputs = screen.getAllByRole('textbox');
54+
55+
// Assert
56+
57+
expect(linkCopyInputs[0]).toBeEmpty();
58+
expect(linkCopyInputs[1]).toBeEmpty();
59+
});
60+
});

‎front/src/pods/trainer/components/header.component.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export const HeaderComponent: React.FC<Props> = props => {
1818
<CopyFieldComponent
1919
labelName="Trainer Link"
2020
inputId="trainer-link"
21-
urlLink={currentTrainerUrl}
21+
urlLink={currentTrainerUrl ?? ''}
2222
/>
2323
<CopyFieldComponent
2424
labelName="Students Link"
2525
inputId="student-link"
26-
urlLink={currentStudentUrl}
26+
urlLink={currentStudentUrl ?? ''}
2727
/>
2828
</div>
2929
);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { fireEvent, render, screen } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
4+
import { NewTextComponent } from './new-text.component';
5+
6+
describe('NewTextComponent unit tests', () => {
7+
it('should handle the entered text when clicking on the send button', () => {
8+
// Arrange
9+
const handleAppendTrainerText = jest.fn();
10+
11+
// Act
12+
render(
13+
<NewTextComponent handleAppendTrainerText={handleAppendTrainerText} />
14+
);
15+
16+
const inputText = screen.getByRole('textbox');
17+
const sendButton = screen.getByRole('button');
18+
19+
userEvent.type(inputText, 'Test text');
20+
userEvent.click(sendButton);
21+
22+
// Assert
23+
expect(handleAppendTrainerText).toHaveBeenCalledTimes(1);
24+
});
25+
26+
it('should not handle any text when there is not entered text and clicking on the send button', () => {
27+
// Arrange
28+
const handleAppendTrainerText = jest.fn();
29+
30+
// Act
31+
render(
32+
<NewTextComponent handleAppendTrainerText={handleAppendTrainerText} />
33+
);
34+
35+
const sendButton = screen.getByRole('button');
36+
37+
userEvent.click(sendButton);
38+
39+
// Assert
40+
expect(handleAppendTrainerText).not.toHaveBeenCalled();
41+
});
42+
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from 'react';
2+
import {render, screen} from '@testing-library/react';
3+
import { SessionComponent } from './session.component';
4+
import userEvent from '@testing-library/user-event';
5+
6+
describe('SessionComponent unit tests', () => {
7+
it('should send the concatenation of the session saved text plus the entered one when clicking the send full content button', () => {
8+
// Arrange
9+
const props = {
10+
log: 'Hello! ',
11+
handleSendFullContentLog: jest.fn(),
12+
}
13+
const expectedSentText = 'Hello! How are you doing?';
14+
15+
// Act
16+
17+
render(<SessionComponent {...props} />);
18+
19+
const textArea = screen.getByRole('textbox');
20+
const sendFullContentButton = screen.getAllByRole('button')[1];
21+
22+
userEvent.type(textArea, 'How are you doing?');
23+
userEvent.click(sendFullContentButton);
24+
25+
// Assert
26+
27+
expect(props.handleSendFullContentLog).toHaveBeenCalledTimes(1);
28+
expect(props.handleSendFullContentLog).toHaveBeenCalledWith(expectedSentText);
29+
});
30+
31+
it('should send the concatenation of the previous session text plus the entered one when clicking the send full content button', () => {
32+
// Arrange
33+
const props = {
34+
log: 'Hello! ',
35+
handleSendFullContentLog: jest.fn(),
36+
}
37+
const expectedSentText = 'Hello! How are you doing?';
38+
39+
// Act
40+
41+
render(<SessionComponent {...props} />);
42+
43+
const textArea = screen.getByRole('textbox');
44+
const sendFullContentButton = screen.getAllByRole('button')[1];
45+
46+
userEvent.type(textArea, 'How are you doing?');
47+
userEvent.click(sendFullContentButton);
48+
49+
// Assert
50+
51+
expect(props.handleSendFullContentLog).toHaveBeenCalledTimes(1);
52+
expect(props.handleSendFullContentLog).toHaveBeenCalledWith(expectedSentText);
53+
});
54+
55+
it('should reset the session text to the original one when clicking the undo button', () => {
56+
// Arrange
57+
const props = {
58+
log: 'Hello! ',
59+
handleSendFullContentLog: jest.fn(),
60+
}
61+
const expectedSentText = 'Hello! ';
62+
63+
// Act
64+
65+
render(<SessionComponent {...props} />);
66+
67+
const textArea = screen.getByRole('textbox');
68+
const undoButton = screen.getAllByRole('button')[0];
69+
70+
userEvent.type(textArea, 'How are you doing?');
71+
undoButton.click();
72+
73+
// Assert
74+
75+
expect(textArea).toHaveValue(expectedSentText);
76+
});
77+
});

‎front/static/index.html‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ <h3 class="instructions__subtitle">How does it work?</h3>
8585
</div>
8686
<!-- / video / -->
8787
<section class="box-content border-bottom">
88-
<div>
88+
<div class="video-section-container">
8989
<h2 class="heading">Video tutorial</h2>
90-
<iframe
91-
width="720"
92-
height="405"
93-
src="https://www.youtube.com/embed/4sswp02n0Yg"
94-
frameborder="0"
95-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
96-
allowfullscreen
97-
></iframe>
90+
<div class="video-container">
91+
<iframe
92+
src="https://www.youtube.com/embed/4sswp02n0Yg"
93+
frameborder="0"
94+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
95+
allowfullscreen
96+
></iframe>
97+
</div>
9898
</div>
9999
</section>
100100

0 commit comments

Comments
 (0)