@@ -96,142 +96,173 @@ test('onFetchedProjectData new loads project data into vm', () => {
96
96
97
97
test ( 'onLoadedProject(LOADING_VM_WITH_ID, true, true) results in state SHOWING_WITH_ID' , ( ) => {
98
98
const initialState = {
99
+ projectId : '100' ,
99
100
loadingState : LoadingState . LOADING_VM_WITH_ID
100
101
} ;
101
102
const action = onLoadedProject ( initialState . loadingState , true , true ) ;
102
103
const resultState = projectStateReducer ( initialState , action ) ;
103
104
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITH_ID ) ;
105
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
104
106
} ) ;
105
107
106
108
test ( 'onLoadedProject(LOADING_VM_WITH_ID, false, true) results in state SHOWING_WITH_ID' , ( ) => {
107
109
const initialState = {
110
+ projectId : '100' ,
108
111
loadingState : LoadingState . LOADING_VM_WITH_ID
109
112
} ;
110
- const action = onLoadedProject ( initialState . loadingState , true , true ) ;
113
+ const action = onLoadedProject ( initialState . loadingState , false , true ) ;
111
114
const resultState = projectStateReducer ( initialState , action ) ;
112
115
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITH_ID ) ;
116
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
113
117
} ) ;
114
118
119
+ // case where we started out viewing a project with a projectId, then
120
+ // started to load another project; but loading fails. We go back to
121
+ // showing the original project.
115
122
test ( 'onLoadedProject(LOADING_VM_WITH_ID, false, false), with project id, ' +
116
123
'results in state SHOWING_WITH_ID' , ( ) => {
117
124
const initialState = {
118
- loadingState : LoadingState . LOADING_VM_WITH_ID ,
119
- projectId : '12345'
125
+ projectId : '100' ,
126
+ loadingState : LoadingState . LOADING_VM_WITH_ID
120
127
} ;
121
128
const action = onLoadedProject ( initialState . loadingState , false , false ) ;
122
129
const resultState = projectStateReducer ( initialState , action ) ;
123
130
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITH_ID ) ;
131
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
124
132
} ) ;
125
133
134
+ // case where we started out viewing a project with default projectId, then
135
+ // started to load one with an id, such as in standalone mode when user adds
136
+ // '#PROJECT_ID_NUMBER' to the URI; but loading fails. We go back to
137
+ // showing the original project.
126
138
test ( 'onLoadedProject(LOADING_VM_WITH_ID, false, false), with no project id, ' +
127
139
'results in state SHOWING_WITHOUT_ID' , ( ) => {
128
140
const initialState = {
129
- loadingState : LoadingState . LOADING_VM_WITH_ID ,
130
- projectId : null
141
+ projectId : '0' ,
142
+ loadingState : LoadingState . LOADING_VM_WITH_ID
131
143
} ;
132
144
const action = onLoadedProject ( initialState . loadingState , false , false ) ;
133
145
const resultState = projectStateReducer ( initialState , action ) ;
134
146
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITHOUT_ID ) ;
147
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
135
148
} ) ;
136
149
137
150
// onLoadedProject: LOADING_VM_FILE_UPLOAD
138
151
139
152
test ( 'onLoadedProject(LOADING_VM_FILE_UPLOAD, true, true) prepares to save' , ( ) => {
140
153
const initialState = {
154
+ projectId : '100' ,
141
155
loadingState : LoadingState . LOADING_VM_FILE_UPLOAD
142
156
} ;
143
157
const action = onLoadedProject ( initialState . loadingState , true , true ) ;
144
158
const resultState = projectStateReducer ( initialState , action ) ;
145
159
expect ( resultState . loadingState ) . toBe ( LoadingState . AUTO_UPDATING ) ;
160
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
146
161
} ) ;
147
162
148
163
test ( 'onLoadedProject(LOADING_VM_FILE_UPLOAD, false, true) results in state SHOWING_WITHOUT_ID' , ( ) => {
149
164
const initialState = {
165
+ projectId : '0' ,
150
166
loadingState : LoadingState . LOADING_VM_FILE_UPLOAD
151
167
} ;
152
168
const action = onLoadedProject ( initialState . loadingState , false , true ) ;
153
169
const resultState = projectStateReducer ( initialState , action ) ;
154
170
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITHOUT_ID ) ;
171
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
155
172
} ) ;
156
173
157
174
test ( 'onLoadedProject(LOADING_VM_FILE_UPLOAD, false, false), when we know project id, ' +
158
175
'results in state SHOWING_WITH_ID' , ( ) => {
159
176
const initialState = {
160
- loadingState : LoadingState . LOADING_VM_FILE_UPLOAD ,
161
- projectId : '12345'
177
+ projectId : '100' ,
178
+ loadingState : LoadingState . LOADING_VM_FILE_UPLOAD
162
179
} ;
163
180
const action = onLoadedProject ( initialState . loadingState , false , false ) ;
164
181
const resultState = projectStateReducer ( initialState , action ) ;
165
182
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITH_ID ) ;
183
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
166
184
} ) ;
167
185
168
186
test ( 'onLoadedProject(LOADING_VM_FILE_UPLOAD, false, false), when we ' +
169
187
'don\'t know project id, results in state SHOWING_WITHOUT_ID' , ( ) => {
170
188
const initialState = {
171
- loadingState : LoadingState . LOADING_VM_FILE_UPLOAD ,
172
- projectId : null
189
+ projectId : '0' ,
190
+ loadingState : LoadingState . LOADING_VM_FILE_UPLOAD
173
191
} ;
174
192
const action = onLoadedProject ( initialState . loadingState , false , false ) ;
175
193
const resultState = projectStateReducer ( initialState , action ) ;
176
194
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITHOUT_ID ) ;
195
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
177
196
} ) ;
178
197
179
198
// onLoadedProject: LOADING_VM_NEW_DEFAULT
180
199
181
200
test ( 'onLoadedProject(LOADING_VM_NEW_DEFAULT, true, true) results in state SHOWING_WITHOUT_ID' , ( ) => {
182
201
const initialState = {
202
+ projectId : '0' ,
183
203
loadingState : LoadingState . LOADING_VM_NEW_DEFAULT
184
204
} ;
185
205
const action = onLoadedProject ( initialState . loadingState , true , true ) ;
186
206
const resultState = projectStateReducer ( initialState , action ) ;
187
207
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITHOUT_ID ) ;
208
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
188
209
} ) ;
189
210
190
211
test ( 'onLoadedProject(LOADING_VM_NEW_DEFAULT, false, true) results in state SHOWING_WITHOUT_ID' , ( ) => {
191
212
const initialState = {
213
+ projectId : '0' ,
192
214
loadingState : LoadingState . LOADING_VM_NEW_DEFAULT
193
215
} ;
194
216
const action = onLoadedProject ( initialState . loadingState , false , true ) ;
195
217
const resultState = projectStateReducer ( initialState , action ) ;
196
218
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITHOUT_ID ) ;
219
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
197
220
} ) ;
198
221
199
222
test ( 'onLoadedProject(LOADING_VM_NEW_DEFAULT, false, false) results in ERROR state' , ( ) => {
200
223
const initialState = {
224
+ projectId : '0' ,
201
225
loadingState : LoadingState . LOADING_VM_NEW_DEFAULT
202
226
} ;
203
227
const action = onLoadedProject ( initialState . loadingState , false , false ) ;
204
228
const resultState = projectStateReducer ( initialState , action ) ;
205
229
expect ( resultState . loadingState ) . toBe ( LoadingState . ERROR ) ;
230
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
206
231
} ) ;
207
232
208
233
// doneUpdatingProject
209
234
210
235
test ( 'doneUpdatingProject with id results in state SHOWING_WITH_ID' , ( ) => {
211
236
const initialState = {
237
+ projectId : '100' ,
212
238
loadingState : LoadingState . MANUAL_UPDATING
213
239
} ;
214
240
const action = doneUpdatingProject ( initialState . loadingState ) ;
215
241
const resultState = projectStateReducer ( initialState , action ) ;
216
242
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITH_ID ) ;
243
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
217
244
} ) ;
218
245
219
246
test ( 'doneUpdatingProject with id, before copy occurs, results in state CREATING_COPY' , ( ) => {
220
247
const initialState = {
248
+ projectId : '100' ,
221
249
loadingState : LoadingState . UPDATING_BEFORE_COPY
222
250
} ;
223
251
const action = doneUpdatingProject ( initialState . loadingState ) ;
224
252
const resultState = projectStateReducer ( initialState , action ) ;
225
253
expect ( resultState . loadingState ) . toBe ( LoadingState . CREATING_COPY ) ;
254
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
226
255
} ) ;
227
256
228
257
test ( 'doneUpdatingProject with id, before new, results in state FETCHING_NEW_DEFAULT' , ( ) => {
229
258
const initialState = {
259
+ projectId : '100' ,
230
260
loadingState : LoadingState . UPDATING_BEFORE_NEW
231
261
} ;
232
262
const action = doneUpdatingProject ( initialState . loadingState ) ;
233
263
const resultState = projectStateReducer ( initialState , action ) ;
234
264
expect ( resultState . loadingState ) . toBe ( LoadingState . FETCHING_NEW_DEFAULT ) ;
265
+ expect ( resultState . projectId ) . toBe ( '0' ) ; // resets id
235
266
} ) ;
236
267
237
268
test ( 'calling setProjectId, using with same id as already showing, ' +
@@ -272,84 +303,102 @@ test('setProjectId, with same id as before, but not same type, ' +
272
303
273
304
test ( 'requestNewProject, when can\'t create/save, results in FETCHING_NEW_DEFAULT' , ( ) => {
274
305
const initialState = {
306
+ projectId : '0' ,
275
307
loadingState : LoadingState . SHOWING_WITHOUT_ID
276
308
} ;
277
309
const action = requestNewProject ( false ) ;
278
310
const resultState = projectStateReducer ( initialState , action ) ;
279
311
expect ( resultState . loadingState ) . toBe ( LoadingState . FETCHING_NEW_DEFAULT ) ;
312
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
280
313
} ) ;
281
314
282
315
test ( 'requestNewProject, when can create/save, results in UPDATING_BEFORE_NEW ' +
283
316
'(in order to save before fetching default project)' , ( ) => {
284
317
const initialState = {
318
+ projectId : '100' ,
285
319
loadingState : LoadingState . SHOWING_WITH_ID
286
320
} ;
287
321
const action = requestNewProject ( true ) ;
288
322
const resultState = projectStateReducer ( initialState , action ) ;
289
323
expect ( resultState . loadingState ) . toBe ( LoadingState . UPDATING_BEFORE_NEW ) ;
324
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
290
325
} ) ;
291
326
292
327
test ( 'requestProjectUpload when project not loaded results in state LOADING_VM_FILE_UPLOAD' , ( ) => {
293
328
const initialState = {
329
+ projectId : null ,
294
330
loadingState : LoadingState . NOT_LOADED
295
331
} ;
296
332
const action = requestProjectUpload ( initialState . loadingState ) ;
297
333
const resultState = projectStateReducer ( initialState , action ) ;
298
334
expect ( resultState . loadingState ) . toBe ( LoadingState . LOADING_VM_FILE_UPLOAD ) ;
335
+ expect ( resultState . projectId ) . toBe ( null ) ;
299
336
} ) ;
300
337
301
338
test ( 'requestProjectUpload when showing project with id results in state LOADING_VM_FILE_UPLOAD' , ( ) => {
302
339
const initialState = {
340
+ projectId : '100' ,
303
341
loadingState : LoadingState . SHOWING_WITH_ID
304
342
} ;
305
343
const action = requestProjectUpload ( initialState . loadingState ) ;
306
344
const resultState = projectStateReducer ( initialState , action ) ;
307
345
expect ( resultState . loadingState ) . toBe ( LoadingState . LOADING_VM_FILE_UPLOAD ) ;
346
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
308
347
} ) ;
309
348
310
349
test ( 'requestProjectUpload when showing project without id results in state LOADING_VM_FILE_UPLOAD' , ( ) => {
311
350
const initialState = {
351
+ projectId : null ,
312
352
loadingState : LoadingState . SHOWING_WITHOUT_ID
313
353
} ;
314
354
const action = requestProjectUpload ( initialState . loadingState ) ;
315
355
const resultState = projectStateReducer ( initialState , action ) ;
316
356
expect ( resultState . loadingState ) . toBe ( LoadingState . LOADING_VM_FILE_UPLOAD ) ;
357
+ expect ( resultState . projectId ) . toBe ( null ) ;
317
358
} ) ;
318
359
319
360
test ( 'manualUpdateProject should prepare to update' , ( ) => {
320
361
const initialState = {
362
+ projectId : '100' ,
321
363
loadingState : LoadingState . SHOWING_WITH_ID
322
364
} ;
323
365
const action = manualUpdateProject ( ) ;
324
366
const resultState = projectStateReducer ( initialState , action ) ;
325
367
expect ( resultState . loadingState ) . toBe ( LoadingState . MANUAL_UPDATING ) ;
368
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
326
369
} ) ;
327
370
328
371
test ( 'autoUpdateProject should prepare to update' , ( ) => {
329
372
const initialState = {
373
+ projectId : '100' ,
330
374
loadingState : LoadingState . SHOWING_WITH_ID
331
375
} ;
332
376
const action = autoUpdateProject ( ) ;
333
377
const resultState = projectStateReducer ( initialState , action ) ;
334
378
expect ( resultState . loadingState ) . toBe ( LoadingState . AUTO_UPDATING ) ;
379
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
335
380
} ) ;
336
381
337
382
test ( 'saveProjectAsCopy should save, before preparing to save as a copy' , ( ) => {
338
383
const initialState = {
384
+ projectId : '100' ,
339
385
loadingState : LoadingState . SHOWING_WITH_ID
340
386
} ;
341
387
const action = saveProjectAsCopy ( ) ;
342
388
const resultState = projectStateReducer ( initialState , action ) ;
343
389
expect ( resultState . loadingState ) . toBe ( LoadingState . UPDATING_BEFORE_COPY ) ;
390
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
344
391
} ) ;
345
392
346
393
test ( 'remixProject should prepare to remix' , ( ) => {
347
394
const initialState = {
395
+ projectId : '100' ,
348
396
loadingState : LoadingState . SHOWING_WITH_ID
349
397
} ;
350
398
const action = remixProject ( ) ;
351
399
const resultState = projectStateReducer ( initialState , action ) ;
352
400
expect ( resultState . loadingState ) . toBe ( LoadingState . REMIXING ) ;
401
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
353
402
} ) ;
354
403
355
404
test ( 'projectError from various states should show error' , ( ) => {
@@ -368,11 +417,13 @@ test('projectError from various states should show error', () => {
368
417
for ( const startState of startStates ) {
369
418
const initialState = {
370
419
error : null ,
420
+ projectId : '100' ,
371
421
loadingState : startState
372
422
} ;
373
423
const action = projectError ( 'Error string' ) ;
374
424
const resultState = projectStateReducer ( initialState , action ) ;
375
425
expect ( resultState . error ) . toEqual ( 'Error string' ) ;
426
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
376
427
}
377
428
} ) ;
378
429
@@ -386,11 +437,13 @@ test('fatal projectError should show error state', () => {
386
437
for ( const startState of startStates ) {
387
438
const initialState = {
388
439
error : null ,
440
+ projectId : '100' ,
389
441
loadingState : startState
390
442
} ;
391
443
const action = projectError ( 'Error string' ) ;
392
444
const resultState = projectStateReducer ( initialState , action ) ;
393
445
expect ( resultState . loadingState ) . toBe ( LoadingState . ERROR ) ;
446
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
394
447
}
395
448
} ) ;
396
449
@@ -405,11 +458,13 @@ test('non-fatal projectError should show normal state', () => {
405
458
for ( const startState of startStates ) {
406
459
const initialState = {
407
460
error : null ,
461
+ projectId : '100' ,
408
462
loadingState : startState
409
463
} ;
410
464
const action = projectError ( 'Error string' ) ;
411
465
const resultState = projectStateReducer ( initialState , action ) ;
412
466
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITH_ID ) ;
467
+ expect ( resultState . projectId ) . toBe ( '100' ) ;
413
468
}
414
469
} ) ;
415
470
@@ -423,6 +478,7 @@ test('projectError when creating new while viewing project with id should ' +
423
478
const action = projectError ( 'Error string' ) ;
424
479
const resultState = projectStateReducer ( initialState , action ) ;
425
480
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITH_ID ) ;
481
+ expect ( resultState . projectId ) . toBe ( '12345' ) ;
426
482
} ) ;
427
483
428
484
test ( 'projectError when creating new while logged out, looking at default project ' +
@@ -435,16 +491,19 @@ test('projectError when creating new while logged out, looking at default projec
435
491
const action = projectError ( 'Error string' ) ;
436
492
const resultState = projectStateReducer ( initialState , action ) ;
437
493
expect ( resultState . loadingState ) . toBe ( LoadingState . SHOWING_WITHOUT_ID ) ;
494
+ expect ( resultState . projectId ) . toBe ( '0' ) ;
438
495
} ) ;
439
496
440
497
test ( 'projectError encountered while in state FETCHING_WITH_ID results in ' +
441
498
'ERROR state' , ( ) => {
442
499
const initialState = {
443
500
error : null ,
501
+ projectId : null ,
444
502
loadingState : LoadingState . FETCHING_WITH_ID
445
503
} ;
446
504
const action = projectError ( 'Error string' ) ;
447
505
const resultState = projectStateReducer ( initialState , action ) ;
448
506
expect ( resultState . loadingState ) . toBe ( LoadingState . ERROR ) ;
507
+ expect ( resultState . projectId ) . toBe ( null ) ;
449
508
expect ( resultState . error ) . toEqual ( 'Error string' ) ;
450
509
} ) ;
0 commit comments