Skip to content

Commit 06950b2

Browse files
authored
Merge pull request #103 from serconde/#101--Accessibility-check-html-element-roles-student
#101 Accessibility: check html element roles (student)
2 parents 6e08599 + 1a433a2 commit 06950b2

5 files changed

Lines changed: 107 additions & 10 deletions

File tree

‎front/config/test/jest.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ module.exports = {
77
modulePathIgnorePatterns: ['cypress'],
88
moduleNameMapper: {
99
'^.+\\.png$': '<rootDir>/pngTransform.js',
10-
},
10+
}
1111
};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import * as React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import { StudentComponent } from './student.component';
4+
5+
describe('StudentComponent tests', () => {
6+
it('It should show the session name and the text when passing valid parameters', () => {
7+
// Arrange
8+
const props = {
9+
room: 'Room I',
10+
log: 'This is test',
11+
};
12+
13+
const expectedSessionNameText = `Session name: ${props.room}`;
14+
15+
// Act
16+
render(<StudentComponent {...props} />);
17+
18+
// Assert
19+
const sessionName = screen.getByRole('heading');
20+
const textArea = screen.getByRole('textbox');
21+
22+
expect(sessionName).toHaveTextContent(expectedSessionNameText);
23+
expect(textArea).toHaveValue(props.log);
24+
});
25+
26+
it('It should show an empty session name when passing an undefined room value', () => {
27+
// Arrange
28+
const props = {
29+
room: undefined,
30+
log: 'This is test',
31+
};
32+
33+
const expectedSessionNameText = `Session name:`;
34+
35+
// Act
36+
render(<StudentComponent {...props} />);
37+
38+
// Assert
39+
const sessionName = screen.getByRole('heading');
40+
expect(sessionName).toHaveTextContent(expectedSessionNameText);
41+
});
42+
43+
it('It should show an empty session name when passing a null room value', () => {
44+
// Arrange
45+
const props = {
46+
room: null,
47+
log: 'This is test',
48+
};
49+
50+
const expectedSessionNameText = `Session name:`;
51+
52+
// Act
53+
render(<StudentComponent {...props} />);
54+
55+
// Assert
56+
const sessionName = screen.getByRole('heading');
57+
58+
expect(sessionName).toHaveTextContent(expectedSessionNameText);
59+
});
60+
61+
it('It should show an empty text when passing an undefined log value', () => {
62+
// Arrange
63+
const props = {
64+
room: 'Room I',
65+
log: undefined,
66+
};
67+
68+
// Act
69+
render(<StudentComponent {...props} />);
70+
71+
// Assert
72+
const textArea = screen.getByRole('textbox');
73+
expect(textArea).toHaveTextContent('');
74+
});
75+
76+
it('It should show an empty text when passing a null log value', () => {
77+
// Arrange
78+
const props = {
79+
room: 'Room I',
80+
log: null,
81+
};
82+
83+
// Act
84+
render(<StudentComponent {...props} />);
85+
86+
// Assert
87+
const textArea = screen.getByRole('textbox');
88+
expect(textArea).toHaveTextContent('');
89+
});
90+
});

‎front/src/pods/student/student.component.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const StudentComponent: React.FC<Props> = props => {
1616
return (
1717
<>
1818
<main className={mainContainer}>
19-
<Typography className={sessionName} variant="body1">
20-
Session name: {room}
19+
<Typography className={sessionName} variant="body1" role="heading">
20+
Session name: {room ?? ''}
2121
</Typography>
2222
<label className={labelTextarea} htmlFor="session">
2323
Content
@@ -27,7 +27,7 @@ export const StudentComponent: React.FC<Props> = props => {
2727
rowsMax={30}
2828
rowsMin={30}
2929
className={studentBoard}
30-
value={log}
30+
value={log ?? ''}
3131
/>
3232
</main>
3333
</>

‎front/src/pods/student/student.container.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { useParams } from 'react-router-dom';
32
import {
43
createSocket,
54
SocketOuputMessageLiteral,
@@ -10,12 +9,13 @@ import { useLog } from 'core';
109
import { StudentComponent } from './student.component';
1110
import { useWithRef } from 'common';
1211
import { getPreviousSessionContent } from 'common-app';
12+
import { useParams } from 'react-router-dom';
1313

1414
interface Params {
1515
room: string;
1616
}
1717

18-
export const PlayerContainer = () => {
18+
export const StudentContainer = () => {
1919
const { room } = useParams<Params>();
2020
const { log, appendToLog, setLog } = useLog();
2121
const [socket, setSocket, socketRef] = useWithRef<SocketIO.Socket>(null);
@@ -50,7 +50,10 @@ export const PlayerContainer = () => {
5050

5151
React.useEffect(() => {
5252
handleConnection();
53-
getPreviousSessionContent(socketRef, SocketEmitMessageTypes.STUDENT_REQUEST_FULL_CONTENT);
53+
getPreviousSessionContent(
54+
socketRef,
55+
SocketEmitMessageTypes.STUDENT_REQUEST_FULL_CONTENT
56+
);
5457
}, []);
5558

5659
return (

‎front/src/scenes/student.scene.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import * as React from 'react';
22
import { SessionLayout } from 'layout';
3-
import { PlayerContainer } from 'pods/student';
3+
import { StudentContainer } from 'pods/student';
4+
import { useParams } from 'react-router-dom';
5+
6+
interface Params {
7+
room: string;
8+
}
49

510
export const StudentScene = () => {
611
React.useEffect(() => {
712
document.title = `Student - Code Paster`;
813
}, []);
9-
1014
return (
1115
<SessionLayout>
12-
<PlayerContainer />
16+
<StudentContainer />
1317
</SessionLayout>
1418
);
1519
};

0 commit comments

Comments
 (0)