Skip to content

Commit 46a6557

Browse files
committed
fix: classrooms do not share instances, tests
1 parent 2f9336b commit 46a6557

File tree

5 files changed

+80
-21
lines changed

5 files changed

+80
-21
lines changed

public/app/listeners/addClassroom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const ObjectId = require('bson-objectid');
2+
const _ = require('lodash');
23
const { ADD_CLASSROOM_CHANNEL } = require('../config/channels');
34
const {
45
ERROR_GENERAL,
@@ -40,7 +41,7 @@ const addClassroom = (mainWindow, db) => async (event, { name, userId }) => {
4041
const id = ObjectId().str;
4142
const now = new Date();
4243
const newClassroom = {
43-
...DEFAULT_CLASSROOM,
44+
..._.cloneDeep(DEFAULT_CLASSROOM),
4445
id,
4546
name,
4647
createdAt: now,

src/components/classrooms/ClassroomCard.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import {
1919
CLASSROOM_CARD_CLASS,
2020
buildClassroomCardId,
2121
DELETE_CLASSROOM_BUTTON_CLASS,
22+
CLASSROOM_CARD_SPACES_CLASS,
23+
CLASSROOM_CARD_STUDENTS_CLASS,
24+
CLASSROOM_CARD_NAME_CLASS,
2225
} from '../../config/selectors';
2326

2427
const styles = theme => ({
@@ -93,13 +96,21 @@ class ClassroomCard extends Component {
9396
>
9497
<CardActionArea onClick={this.viewLink}>
9598
<CardContent>
96-
<Typography variant="h5" component="h2">
99+
<Typography
100+
variant="h5"
101+
component="h2"
102+
className={CLASSROOM_CARD_NAME_CLASS}
103+
>
97104
{name}
98105
</Typography>
99106
<Typography>
100-
{`${nbSpaces} ${t('space(s)')}`}
107+
<span className={CLASSROOM_CARD_SPACES_CLASS}>
108+
{`${nbSpaces} ${t('space(s)')}`}
109+
</span>
101110
<span className={classes.bullet}></span>
102-
{`${nbUsers} ${t('student(s)')}`}
111+
<span className={CLASSROOM_CARD_STUDENTS_CLASS}>
112+
{`${nbUsers} ${t('student(s)')}`}
113+
</span>
103114
</Typography>
104115
</CardContent>
105116
</CardActionArea>

src/components/classrooms/ClassroomScreen.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import StudentsTable from './StudentsTable';
1616
import AddUserInClassroomButton from './AddUserInClassroomButton';
1717
import { getClassroom } from '../../actions';
1818
import ImportDataButton from './ImportDataButton';
19+
import { CLASSROOM_SCREEN_BACK_BUTTON_ID } from '../../config/selectors';
1920

2021
const styles = theme => ({
2122
...Styles(theme),
@@ -69,6 +70,7 @@ class ClassroomScreen extends Component {
6970
} = this.props;
7071
return (
7172
<Button
73+
id={CLASSROOM_SCREEN_BACK_BUTTON_ID}
7274
variant="contained"
7375
onClick={goBack}
7476
color="primary"

src/config/selectors.js

+4
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,7 @@ export const EDIT_USER_IN_CLASSROOM_VALIDATE_BUTTON_ID =
115115
export const CLASSROOM_TABLE_BODY_ID = 'classroomTableBody';
116116
export const DELETE_USER_IN_CLASSROOM_BUTTON_CLASS =
117117
'deleteUserInClassroomButton';
118+
export const CLASSROOM_CARD_SPACES_CLASS = 'classroomCardSpaces';
119+
export const CLASSROOM_CARD_STUDENTS_CLASS = 'classroomCardStudents';
120+
export const CLASSROOM_SCREEN_BACK_BUTTON_ID = 'classroomScreenBackButton';
121+
export const CLASSROOM_CARD_NAME_CLASS = 'classroomCardName';

test/classrooms.test.js

+58-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-unused-expressions */
22
/* eslint-disable no-await-in-loop */
33
/* eslint-disable no-restricted-syntax */
4+
import { expect } from 'chai';
45
import {
56
mochaAsync,
67
expectElementToNotExist,
@@ -29,6 +30,10 @@ import {
2930
EDIT_USER_IN_CLASSROOM_BUTTON_CLASS,
3031
CLASSROOM_TABLE_BODY_ID,
3132
DELETE_USER_IN_CLASSROOM_BUTTON_CLASS,
33+
CLASSROOM_CARD_SPACES_CLASS,
34+
CLASSROOM_CARD_STUDENTS_CLASS,
35+
CLASSROOM_SCREEN_BACK_BUTTON_ID,
36+
CLASSROOM_CARD_NAME_CLASS,
3237
} from '../src/config/selectors';
3338
import {
3439
DEFAULT_GLOBAL_TIMEOUT,
@@ -43,6 +48,11 @@ import { openDrawer, menuGoToSettings, menuGoToClassrooms } from './menu.test';
4348
import { userSignIn } from './userSignIn.test';
4449
import { USER_GRAASP } from './fixtures/users';
4550

51+
const openClassroom = async (client, name) => {
52+
await client.click(`.${CLASSROOM_CARD_CLASS}[data-name='${name}']`);
53+
await client.pause(OPEN_CLASSROOM_PAUSE);
54+
};
55+
4656
const addClassroom = async (client, name) => {
4757
await client.click(`#${ADD_CLASSROOM_BUTTON_ID}`);
4858
await client.pause(MODAL_OPEN_PAUSE);
@@ -54,15 +64,15 @@ const addClassroom = async (client, name) => {
5464
await client.pause(MODAL_CLOSE_PAUSE);
5565
};
5666

57-
// newName is appended to name
58-
const editClassroom = async (client, name, changes) => {
67+
const editClassroom = async (client, name, newName) => {
5968
// search based on name since id is generated on the fly
6069
const classroomSelector = `.${CLASSROOM_CARD_CLASS}[data-name='${name}']`;
6170

6271
await client.click(`${classroomSelector} .${EDIT_CLASSROOM_BUTTON_CLASS}`);
6372
await client.pause(MODAL_OPEN_PAUSE);
6473
const editInput = `#${EDIT_CLASSROOM_INPUT_ID}`;
65-
await client.setValue(editInput, changes);
74+
await clearInput(client, editInput);
75+
await client.setValue(editInput, newName);
6676
await client.pause(INPUT_TYPE_PAUSE);
6777
await client.click(`#${EDIT_CLASSROOM_VALIDATE_BUTTON_ID}`);
6878
await client.pause(MODAL_CLOSE_PAUSE);
@@ -127,6 +137,34 @@ const hasStudentsTableLayout = async (client, usernames = []) => {
127137
}
128138
};
129139

140+
const hasClassroomCardLayout = async (
141+
client,
142+
name,
143+
nbSpace = 0,
144+
nbStudent = 0
145+
) => {
146+
const classroomSelector = `.${CLASSROOM_CARD_CLASS}[data-name='${name}']`;
147+
await expectElementToExist(client, classroomSelector);
148+
149+
// check title
150+
const title = await client.getText(
151+
`${classroomSelector} .${CLASSROOM_CARD_NAME_CLASS}`
152+
);
153+
expect(title).to.equal(name);
154+
155+
// check space number
156+
const spacesText = await client.getText(
157+
`${classroomSelector} .${CLASSROOM_CARD_SPACES_CLASS}`
158+
);
159+
expect(spacesText).to.include(nbSpace);
160+
161+
// check student number
162+
const studentsText = await client.getText(
163+
`${classroomSelector} .${CLASSROOM_CARD_STUDENTS_CLASS}`
164+
);
165+
expect(studentsText).to.include(nbStudent);
166+
};
167+
130168
describe('Classrooms Scenarios', function() {
131169
this.timeout(DEFAULT_GLOBAL_TIMEOUT);
132170
let app;
@@ -185,19 +223,12 @@ describe('Classrooms Scenarios', function() {
185223

186224
// add classroom
187225
await addClassroom(client, name);
188-
await expectElementToExist(
189-
client,
190-
`.${CLASSROOM_CARD_CLASS}[data-name='${name}']`
191-
);
226+
await hasClassroomCardLayout(client, name);
192227

193228
// edit
194-
const changes = ' graasp';
195-
const newName = name + changes;
196-
await editClassroom(client, name, changes);
197-
await expectElementToExist(
198-
client,
199-
`.${CLASSROOM_CARD_CLASS}[data-name='${newName}']`
200-
);
229+
const newName = 'graasp';
230+
await editClassroom(client, name, newName);
231+
await hasClassroomCardLayout(client, newName);
201232

202233
// delete
203234
await deleteClassroom(client, newName);
@@ -228,8 +259,7 @@ describe('Classrooms Scenarios', function() {
228259

229260
// add classroom
230261
await addClassroom(client, name);
231-
await client.click(`.${CLASSROOM_CARD_CLASS}[data-name='${name}']`);
232-
await client.pause(OPEN_CLASSROOM_PAUSE);
262+
await openClassroom(client, name);
233263

234264
// add user
235265
const username = 'anna';
@@ -247,7 +277,18 @@ describe('Classrooms Scenarios', function() {
247277
await editUserInClassroom(client, username, changes);
248278
await hasStudentsTableLayout(client, [newName]);
249279

250-
// delete user
280+
// check classroom layout
281+
await client.click(`#${CLASSROOM_SCREEN_BACK_BUTTON_ID}`);
282+
await hasClassroomCardLayout(client, name, 0, 2);
283+
284+
// check data is not shared between classrooms
285+
// create new classroom
286+
const classroomName = 'name';
287+
await addClassroom(client, classroomName);
288+
await hasClassroomCardLayout(client, classroomName, 0, 0);
289+
290+
// delete user in first classroom
291+
await openClassroom(client, name);
251292
await deleteUserInClassroom(client, newName);
252293
await hasStudentsTableLayout(client, [username1]);
253294
})

0 commit comments

Comments
 (0)