1
1
/* eslint-disable no-unused-expressions */
2
2
/* eslint-disable no-await-in-loop */
3
3
/* eslint-disable no-restricted-syntax */
4
+ import { expect } from 'chai' ;
4
5
import {
5
6
mochaAsync ,
6
7
expectElementToNotExist ,
@@ -29,6 +30,10 @@ import {
29
30
EDIT_USER_IN_CLASSROOM_BUTTON_CLASS ,
30
31
CLASSROOM_TABLE_BODY_ID ,
31
32
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 ,
32
37
} from '../src/config/selectors' ;
33
38
import {
34
39
DEFAULT_GLOBAL_TIMEOUT ,
@@ -43,6 +48,11 @@ import { openDrawer, menuGoToSettings, menuGoToClassrooms } from './menu.test';
43
48
import { userSignIn } from './userSignIn.test' ;
44
49
import { USER_GRAASP } from './fixtures/users' ;
45
50
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
+
46
56
const addClassroom = async ( client , name ) => {
47
57
await client . click ( `#${ ADD_CLASSROOM_BUTTON_ID } ` ) ;
48
58
await client . pause ( MODAL_OPEN_PAUSE ) ;
@@ -54,15 +64,15 @@ const addClassroom = async (client, name) => {
54
64
await client . pause ( MODAL_CLOSE_PAUSE ) ;
55
65
} ;
56
66
57
- // newName is appended to name
58
- const editClassroom = async ( client , name , changes ) => {
67
+ const editClassroom = async ( client , name , newName ) => {
59
68
// search based on name since id is generated on the fly
60
69
const classroomSelector = `.${ CLASSROOM_CARD_CLASS } [data-name='${ name } ']` ;
61
70
62
71
await client . click ( `${ classroomSelector } .${ EDIT_CLASSROOM_BUTTON_CLASS } ` ) ;
63
72
await client . pause ( MODAL_OPEN_PAUSE ) ;
64
73
const editInput = `#${ EDIT_CLASSROOM_INPUT_ID } ` ;
65
- await client . setValue ( editInput , changes ) ;
74
+ await clearInput ( client , editInput ) ;
75
+ await client . setValue ( editInput , newName ) ;
66
76
await client . pause ( INPUT_TYPE_PAUSE ) ;
67
77
await client . click ( `#${ EDIT_CLASSROOM_VALIDATE_BUTTON_ID } ` ) ;
68
78
await client . pause ( MODAL_CLOSE_PAUSE ) ;
@@ -127,6 +137,34 @@ const hasStudentsTableLayout = async (client, usernames = []) => {
127
137
}
128
138
} ;
129
139
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
+
130
168
describe ( 'Classrooms Scenarios' , function ( ) {
131
169
this . timeout ( DEFAULT_GLOBAL_TIMEOUT ) ;
132
170
let app ;
@@ -185,19 +223,12 @@ describe('Classrooms Scenarios', function() {
185
223
186
224
// add classroom
187
225
await addClassroom ( client , name ) ;
188
- await expectElementToExist (
189
- client ,
190
- `.${ CLASSROOM_CARD_CLASS } [data-name='${ name } ']`
191
- ) ;
226
+ await hasClassroomCardLayout ( client , name ) ;
192
227
193
228
// 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 ) ;
201
232
202
233
// delete
203
234
await deleteClassroom ( client , newName ) ;
@@ -228,8 +259,7 @@ describe('Classrooms Scenarios', function() {
228
259
229
260
// add classroom
230
261
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 ) ;
233
263
234
264
// add user
235
265
const username = 'anna' ;
@@ -247,7 +277,18 @@ describe('Classrooms Scenarios', function() {
247
277
await editUserInClassroom ( client , username , changes ) ;
248
278
await hasStudentsTableLayout ( client , [ newName ] ) ;
249
279
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 ) ;
251
292
await deleteUserInClassroom ( client , newName ) ;
252
293
await hasStudentsTableLayout ( client , [ username1 ] ) ;
253
294
} )
0 commit comments