Skip to content

Commit 41f6427

Browse files
committed
in project state tests, test resulting projectId in all tests
1 parent 3a8fe3f commit 41f6427

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

test/unit/reducers/project-state-reducer.test.js

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,142 +96,166 @@ test('onFetchedProjectData new loads project data into vm', () => {
9696

9797
test('onLoadedProject(LOADING_VM_WITH_ID, true, true) results in state SHOWING_WITH_ID', () => {
9898
const initialState = {
99+
projectId: '100',
99100
loadingState: LoadingState.LOADING_VM_WITH_ID
100101
};
101102
const action = onLoadedProject(initialState.loadingState, true, true);
102103
const resultState = projectStateReducer(initialState, action);
103104
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
105+
expect(resultState.projectId).toBe('100');
104106
});
105107

106108
test('onLoadedProject(LOADING_VM_WITH_ID, false, true) results in state SHOWING_WITH_ID', () => {
107109
const initialState = {
110+
projectId: '100',
108111
loadingState: LoadingState.LOADING_VM_WITH_ID
109112
};
110113
const action = onLoadedProject(initialState.loadingState, true, true);
111114
const resultState = projectStateReducer(initialState, action);
112115
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
116+
expect(resultState.projectId).toBe('100');
113117
});
114118

115119
test('onLoadedProject(LOADING_VM_WITH_ID, false, false), with project id, ' +
116120
'results in state SHOWING_WITH_ID', () => {
117121
const initialState = {
118-
loadingState: LoadingState.LOADING_VM_WITH_ID,
119-
projectId: '12345'
122+
projectId: '100',
123+
loadingState: LoadingState.LOADING_VM_WITH_ID
120124
};
121125
const action = onLoadedProject(initialState.loadingState, false, false);
122126
const resultState = projectStateReducer(initialState, action);
123127
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
128+
expect(resultState.projectId).toBe('100');
124129
});
125130

126131
test('onLoadedProject(LOADING_VM_WITH_ID, false, false), with no project id, ' +
127132
'results in state SHOWING_WITHOUT_ID', () => {
128133
const initialState = {
129-
loadingState: LoadingState.LOADING_VM_WITH_ID,
130-
projectId: null
134+
projectId: '0',
135+
loadingState: LoadingState.LOADING_VM_WITH_ID
131136
};
132137
const action = onLoadedProject(initialState.loadingState, false, false);
133138
const resultState = projectStateReducer(initialState, action);
134139
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
140+
expect(resultState.projectId).toBe('0');
135141
});
136142

137143
// onLoadedProject: LOADING_VM_FILE_UPLOAD
138144

139145
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, true, true) prepares to save', () => {
140146
const initialState = {
147+
projectId: '100',
141148
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
142149
};
143150
const action = onLoadedProject(initialState.loadingState, true, true);
144151
const resultState = projectStateReducer(initialState, action);
145152
expect(resultState.loadingState).toBe(LoadingState.AUTO_UPDATING);
153+
expect(resultState.projectId).toBe('100');
146154
});
147155

148156
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, false, true) results in state SHOWING_WITHOUT_ID', () => {
149157
const initialState = {
158+
projectId: '0',
150159
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
151160
};
152161
const action = onLoadedProject(initialState.loadingState, false, true);
153162
const resultState = projectStateReducer(initialState, action);
154163
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
164+
expect(resultState.projectId).toBe('0');
155165
});
156166

157167
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, false, false), when we know project id, ' +
158168
'results in state SHOWING_WITH_ID', () => {
159169
const initialState = {
160-
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD,
161-
projectId: '12345'
170+
projectId: '100',
171+
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
162172
};
163173
const action = onLoadedProject(initialState.loadingState, false, false);
164174
const resultState = projectStateReducer(initialState, action);
165175
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
176+
expect(resultState.projectId).toBe('100');
166177
});
167178

168179
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, false, false), when we ' +
169180
'don\'t know project id, results in state SHOWING_WITHOUT_ID', () => {
170181
const initialState = {
171-
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD,
172-
projectId: null
182+
projectId: '0',
183+
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
173184
};
174185
const action = onLoadedProject(initialState.loadingState, false, false);
175186
const resultState = projectStateReducer(initialState, action);
176187
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
188+
expect(resultState.projectId).toBe('0');
177189
});
178190

179191
// onLoadedProject: LOADING_VM_NEW_DEFAULT
180192

181193
test('onLoadedProject(LOADING_VM_NEW_DEFAULT, true, true) results in state SHOWING_WITHOUT_ID', () => {
182194
const initialState = {
195+
projectId: '0',
183196
loadingState: LoadingState.LOADING_VM_NEW_DEFAULT
184197
};
185198
const action = onLoadedProject(initialState.loadingState, true, true);
186199
const resultState = projectStateReducer(initialState, action);
187200
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
201+
expect(resultState.projectId).toBe('0');
188202
});
189203

190204
test('onLoadedProject(LOADING_VM_NEW_DEFAULT, false, true) results in state SHOWING_WITHOUT_ID', () => {
191205
const initialState = {
206+
projectId: '0',
192207
loadingState: LoadingState.LOADING_VM_NEW_DEFAULT
193208
};
194209
const action = onLoadedProject(initialState.loadingState, false, true);
195210
const resultState = projectStateReducer(initialState, action);
196211
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
212+
expect(resultState.projectId).toBe('0');
197213
});
198214

199215
test('onLoadedProject(LOADING_VM_NEW_DEFAULT, false, false) results in ERROR state', () => {
200216
const initialState = {
217+
projectId: '0',
201218
loadingState: LoadingState.LOADING_VM_NEW_DEFAULT
202219
};
203220
const action = onLoadedProject(initialState.loadingState, false, false);
204221
const resultState = projectStateReducer(initialState, action);
205222
expect(resultState.loadingState).toBe(LoadingState.ERROR);
223+
expect(resultState.projectId).toBe('0');
206224
});
207225

208226
// doneUpdatingProject
209227

210228
test('doneUpdatingProject with id results in state SHOWING_WITH_ID', () => {
211229
const initialState = {
230+
projectId: '100',
212231
loadingState: LoadingState.MANUAL_UPDATING
213232
};
214233
const action = doneUpdatingProject(initialState.loadingState);
215234
const resultState = projectStateReducer(initialState, action);
216235
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
236+
expect(resultState.projectId).toBe('100');
217237
});
218238

219239
test('doneUpdatingProject with id, before copy occurs, results in state CREATING_COPY', () => {
220240
const initialState = {
241+
projectId: '100',
221242
loadingState: LoadingState.UPDATING_BEFORE_COPY
222243
};
223244
const action = doneUpdatingProject(initialState.loadingState);
224245
const resultState = projectStateReducer(initialState, action);
225246
expect(resultState.loadingState).toBe(LoadingState.CREATING_COPY);
247+
expect(resultState.projectId).toBe('100');
226248
});
227249

228250
test('doneUpdatingProject with id, before new, results in state FETCHING_NEW_DEFAULT', () => {
229251
const initialState = {
252+
projectId: '100',
230253
loadingState: LoadingState.UPDATING_BEFORE_NEW
231254
};
232255
const action = doneUpdatingProject(initialState.loadingState);
233256
const resultState = projectStateReducer(initialState, action);
234257
expect(resultState.loadingState).toBe(LoadingState.FETCHING_NEW_DEFAULT);
258+
expect(resultState.projectId).toBe('0'); // resets id
235259
});
236260

237261
test('calling setProjectId, using with same id as already showing, ' +
@@ -272,84 +296,102 @@ test('setProjectId, with same id as before, but not same type, ' +
272296

273297
test('requestNewProject, when can\'t create/save, results in FETCHING_NEW_DEFAULT', () => {
274298
const initialState = {
299+
projectId: '0',
275300
loadingState: LoadingState.SHOWING_WITHOUT_ID
276301
};
277302
const action = requestNewProject(false);
278303
const resultState = projectStateReducer(initialState, action);
279304
expect(resultState.loadingState).toBe(LoadingState.FETCHING_NEW_DEFAULT);
305+
expect(resultState.projectId).toBe('0');
280306
});
281307

282308
test('requestNewProject, when can create/save, results in UPDATING_BEFORE_NEW ' +
283309
'(in order to save before fetching default project)', () => {
284310
const initialState = {
311+
projectId: '100',
285312
loadingState: LoadingState.SHOWING_WITH_ID
286313
};
287314
const action = requestNewProject(true);
288315
const resultState = projectStateReducer(initialState, action);
289316
expect(resultState.loadingState).toBe(LoadingState.UPDATING_BEFORE_NEW);
317+
expect(resultState.projectId).toBe('100');
290318
});
291319

292320
test('requestProjectUpload when project not loaded results in state LOADING_VM_FILE_UPLOAD', () => {
293321
const initialState = {
322+
projectId: null,
294323
loadingState: LoadingState.NOT_LOADED
295324
};
296325
const action = requestProjectUpload(initialState.loadingState);
297326
const resultState = projectStateReducer(initialState, action);
298327
expect(resultState.loadingState).toBe(LoadingState.LOADING_VM_FILE_UPLOAD);
328+
expect(resultState.projectId).toBe(null);
299329
});
300330

301331
test('requestProjectUpload when showing project with id results in state LOADING_VM_FILE_UPLOAD', () => {
302332
const initialState = {
333+
projectId: '100',
303334
loadingState: LoadingState.SHOWING_WITH_ID
304335
};
305336
const action = requestProjectUpload(initialState.loadingState);
306337
const resultState = projectStateReducer(initialState, action);
307338
expect(resultState.loadingState).toBe(LoadingState.LOADING_VM_FILE_UPLOAD);
339+
expect(resultState.projectId).toBe('100');
308340
});
309341

310342
test('requestProjectUpload when showing project without id results in state LOADING_VM_FILE_UPLOAD', () => {
311343
const initialState = {
344+
projectId: null,
312345
loadingState: LoadingState.SHOWING_WITHOUT_ID
313346
};
314347
const action = requestProjectUpload(initialState.loadingState);
315348
const resultState = projectStateReducer(initialState, action);
316349
expect(resultState.loadingState).toBe(LoadingState.LOADING_VM_FILE_UPLOAD);
350+
expect(resultState.projectId).toBe(null);
317351
});
318352

319353
test('manualUpdateProject should prepare to update', () => {
320354
const initialState = {
355+
projectId: '100',
321356
loadingState: LoadingState.SHOWING_WITH_ID
322357
};
323358
const action = manualUpdateProject();
324359
const resultState = projectStateReducer(initialState, action);
325360
expect(resultState.loadingState).toBe(LoadingState.MANUAL_UPDATING);
361+
expect(resultState.projectId).toBe('100');
326362
});
327363

328364
test('autoUpdateProject should prepare to update', () => {
329365
const initialState = {
366+
projectId: '100',
330367
loadingState: LoadingState.SHOWING_WITH_ID
331368
};
332369
const action = autoUpdateProject();
333370
const resultState = projectStateReducer(initialState, action);
334371
expect(resultState.loadingState).toBe(LoadingState.AUTO_UPDATING);
372+
expect(resultState.projectId).toBe('100');
335373
});
336374

337375
test('saveProjectAsCopy should save, before preparing to save as a copy', () => {
338376
const initialState = {
377+
projectId: '100',
339378
loadingState: LoadingState.SHOWING_WITH_ID
340379
};
341380
const action = saveProjectAsCopy();
342381
const resultState = projectStateReducer(initialState, action);
343382
expect(resultState.loadingState).toBe(LoadingState.UPDATING_BEFORE_COPY);
383+
expect(resultState.projectId).toBe('100');
344384
});
345385

346386
test('remixProject should prepare to remix', () => {
347387
const initialState = {
388+
projectId: '100',
348389
loadingState: LoadingState.SHOWING_WITH_ID
349390
};
350391
const action = remixProject();
351392
const resultState = projectStateReducer(initialState, action);
352393
expect(resultState.loadingState).toBe(LoadingState.REMIXING);
394+
expect(resultState.projectId).toBe('100');
353395
});
354396

355397
test('projectError from various states should show error', () => {
@@ -368,11 +410,13 @@ test('projectError from various states should show error', () => {
368410
for (const startState of startStates) {
369411
const initialState = {
370412
error: null,
413+
projectId: '100',
371414
loadingState: startState
372415
};
373416
const action = projectError('Error string');
374417
const resultState = projectStateReducer(initialState, action);
375418
expect(resultState.error).toEqual('Error string');
419+
expect(resultState.projectId).toBe('100');
376420
}
377421
});
378422

@@ -386,11 +430,13 @@ test('fatal projectError should show error state', () => {
386430
for (const startState of startStates) {
387431
const initialState = {
388432
error: null,
433+
projectId: '100',
389434
loadingState: startState
390435
};
391436
const action = projectError('Error string');
392437
const resultState = projectStateReducer(initialState, action);
393438
expect(resultState.loadingState).toBe(LoadingState.ERROR);
439+
expect(resultState.projectId).toBe('100');
394440
}
395441
});
396442

@@ -405,11 +451,13 @@ test('non-fatal projectError should show normal state', () => {
405451
for (const startState of startStates) {
406452
const initialState = {
407453
error: null,
454+
projectId: '100',
408455
loadingState: startState
409456
};
410457
const action = projectError('Error string');
411458
const resultState = projectStateReducer(initialState, action);
412459
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
460+
expect(resultState.projectId).toBe('100');
413461
}
414462
});
415463

@@ -423,6 +471,7 @@ test('projectError when creating new while viewing project with id should ' +
423471
const action = projectError('Error string');
424472
const resultState = projectStateReducer(initialState, action);
425473
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
474+
expect(resultState.projectId).toBe('12345');
426475
});
427476

428477
test('projectError when creating new while logged out, looking at default project ' +
@@ -435,16 +484,19 @@ test('projectError when creating new while logged out, looking at default projec
435484
const action = projectError('Error string');
436485
const resultState = projectStateReducer(initialState, action);
437486
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
487+
expect(resultState.projectId).toBe('0');
438488
});
439489

440490
test('projectError encountered while in state FETCHING_WITH_ID results in ' +
441491
'ERROR state', () => {
442492
const initialState = {
443493
error: null,
494+
projectId: null,
444495
loadingState: LoadingState.FETCHING_WITH_ID
445496
};
446497
const action = projectError('Error string');
447498
const resultState = projectStateReducer(initialState, action);
448499
expect(resultState.loadingState).toBe(LoadingState.ERROR);
500+
expect(resultState.projectId).toBe(null);
449501
expect(resultState.error).toEqual('Error string');
450502
});

0 commit comments

Comments
 (0)