Skip to content

Commit 2e11787

Browse files
committed
test resulting projectId; add comments; fix params
1 parent 3a8fe3f commit 2e11787

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

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

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,142 +96,173 @@ 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
};
110-
const action = onLoadedProject(initialState.loadingState, true, true);
113+
const action = onLoadedProject(initialState.loadingState, false, true);
111114
const resultState = projectStateReducer(initialState, action);
112115
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
116+
expect(resultState.projectId).toBe('100');
113117
});
114118

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.
115122
test('onLoadedProject(LOADING_VM_WITH_ID, false, false), with project id, ' +
116123
'results in state SHOWING_WITH_ID', () => {
117124
const initialState = {
118-
loadingState: LoadingState.LOADING_VM_WITH_ID,
119-
projectId: '12345'
125+
projectId: '100',
126+
loadingState: LoadingState.LOADING_VM_WITH_ID
120127
};
121128
const action = onLoadedProject(initialState.loadingState, false, false);
122129
const resultState = projectStateReducer(initialState, action);
123130
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
131+
expect(resultState.projectId).toBe('100');
124132
});
125133

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.
126138
test('onLoadedProject(LOADING_VM_WITH_ID, false, false), with no project id, ' +
127139
'results in state SHOWING_WITHOUT_ID', () => {
128140
const initialState = {
129-
loadingState: LoadingState.LOADING_VM_WITH_ID,
130-
projectId: null
141+
projectId: '0',
142+
loadingState: LoadingState.LOADING_VM_WITH_ID
131143
};
132144
const action = onLoadedProject(initialState.loadingState, false, false);
133145
const resultState = projectStateReducer(initialState, action);
134146
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
147+
expect(resultState.projectId).toBe('0');
135148
});
136149

137150
// onLoadedProject: LOADING_VM_FILE_UPLOAD
138151

139152
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, true, true) prepares to save', () => {
140153
const initialState = {
154+
projectId: '100',
141155
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
142156
};
143157
const action = onLoadedProject(initialState.loadingState, true, true);
144158
const resultState = projectStateReducer(initialState, action);
145159
expect(resultState.loadingState).toBe(LoadingState.AUTO_UPDATING);
160+
expect(resultState.projectId).toBe('100');
146161
});
147162

148163
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, false, true) results in state SHOWING_WITHOUT_ID', () => {
149164
const initialState = {
165+
projectId: '0',
150166
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
151167
};
152168
const action = onLoadedProject(initialState.loadingState, false, true);
153169
const resultState = projectStateReducer(initialState, action);
154170
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
171+
expect(resultState.projectId).toBe('0');
155172
});
156173

157174
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, false, false), when we know project id, ' +
158175
'results in state SHOWING_WITH_ID', () => {
159176
const initialState = {
160-
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD,
161-
projectId: '12345'
177+
projectId: '100',
178+
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
162179
};
163180
const action = onLoadedProject(initialState.loadingState, false, false);
164181
const resultState = projectStateReducer(initialState, action);
165182
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
183+
expect(resultState.projectId).toBe('100');
166184
});
167185

168186
test('onLoadedProject(LOADING_VM_FILE_UPLOAD, false, false), when we ' +
169187
'don\'t know project id, results in state SHOWING_WITHOUT_ID', () => {
170188
const initialState = {
171-
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD,
172-
projectId: null
189+
projectId: '0',
190+
loadingState: LoadingState.LOADING_VM_FILE_UPLOAD
173191
};
174192
const action = onLoadedProject(initialState.loadingState, false, false);
175193
const resultState = projectStateReducer(initialState, action);
176194
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
195+
expect(resultState.projectId).toBe('0');
177196
});
178197

179198
// onLoadedProject: LOADING_VM_NEW_DEFAULT
180199

181200
test('onLoadedProject(LOADING_VM_NEW_DEFAULT, true, true) results in state SHOWING_WITHOUT_ID', () => {
182201
const initialState = {
202+
projectId: '0',
183203
loadingState: LoadingState.LOADING_VM_NEW_DEFAULT
184204
};
185205
const action = onLoadedProject(initialState.loadingState, true, true);
186206
const resultState = projectStateReducer(initialState, action);
187207
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
208+
expect(resultState.projectId).toBe('0');
188209
});
189210

190211
test('onLoadedProject(LOADING_VM_NEW_DEFAULT, false, true) results in state SHOWING_WITHOUT_ID', () => {
191212
const initialState = {
213+
projectId: '0',
192214
loadingState: LoadingState.LOADING_VM_NEW_DEFAULT
193215
};
194216
const action = onLoadedProject(initialState.loadingState, false, true);
195217
const resultState = projectStateReducer(initialState, action);
196218
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
219+
expect(resultState.projectId).toBe('0');
197220
});
198221

199222
test('onLoadedProject(LOADING_VM_NEW_DEFAULT, false, false) results in ERROR state', () => {
200223
const initialState = {
224+
projectId: '0',
201225
loadingState: LoadingState.LOADING_VM_NEW_DEFAULT
202226
};
203227
const action = onLoadedProject(initialState.loadingState, false, false);
204228
const resultState = projectStateReducer(initialState, action);
205229
expect(resultState.loadingState).toBe(LoadingState.ERROR);
230+
expect(resultState.projectId).toBe('0');
206231
});
207232

208233
// doneUpdatingProject
209234

210235
test('doneUpdatingProject with id results in state SHOWING_WITH_ID', () => {
211236
const initialState = {
237+
projectId: '100',
212238
loadingState: LoadingState.MANUAL_UPDATING
213239
};
214240
const action = doneUpdatingProject(initialState.loadingState);
215241
const resultState = projectStateReducer(initialState, action);
216242
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
243+
expect(resultState.projectId).toBe('100');
217244
});
218245

219246
test('doneUpdatingProject with id, before copy occurs, results in state CREATING_COPY', () => {
220247
const initialState = {
248+
projectId: '100',
221249
loadingState: LoadingState.UPDATING_BEFORE_COPY
222250
};
223251
const action = doneUpdatingProject(initialState.loadingState);
224252
const resultState = projectStateReducer(initialState, action);
225253
expect(resultState.loadingState).toBe(LoadingState.CREATING_COPY);
254+
expect(resultState.projectId).toBe('100');
226255
});
227256

228257
test('doneUpdatingProject with id, before new, results in state FETCHING_NEW_DEFAULT', () => {
229258
const initialState = {
259+
projectId: '100',
230260
loadingState: LoadingState.UPDATING_BEFORE_NEW
231261
};
232262
const action = doneUpdatingProject(initialState.loadingState);
233263
const resultState = projectStateReducer(initialState, action);
234264
expect(resultState.loadingState).toBe(LoadingState.FETCHING_NEW_DEFAULT);
265+
expect(resultState.projectId).toBe('0'); // resets id
235266
});
236267

237268
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, ' +
272303

273304
test('requestNewProject, when can\'t create/save, results in FETCHING_NEW_DEFAULT', () => {
274305
const initialState = {
306+
projectId: '0',
275307
loadingState: LoadingState.SHOWING_WITHOUT_ID
276308
};
277309
const action = requestNewProject(false);
278310
const resultState = projectStateReducer(initialState, action);
279311
expect(resultState.loadingState).toBe(LoadingState.FETCHING_NEW_DEFAULT);
312+
expect(resultState.projectId).toBe('0');
280313
});
281314

282315
test('requestNewProject, when can create/save, results in UPDATING_BEFORE_NEW ' +
283316
'(in order to save before fetching default project)', () => {
284317
const initialState = {
318+
projectId: '100',
285319
loadingState: LoadingState.SHOWING_WITH_ID
286320
};
287321
const action = requestNewProject(true);
288322
const resultState = projectStateReducer(initialState, action);
289323
expect(resultState.loadingState).toBe(LoadingState.UPDATING_BEFORE_NEW);
324+
expect(resultState.projectId).toBe('100');
290325
});
291326

292327
test('requestProjectUpload when project not loaded results in state LOADING_VM_FILE_UPLOAD', () => {
293328
const initialState = {
329+
projectId: null,
294330
loadingState: LoadingState.NOT_LOADED
295331
};
296332
const action = requestProjectUpload(initialState.loadingState);
297333
const resultState = projectStateReducer(initialState, action);
298334
expect(resultState.loadingState).toBe(LoadingState.LOADING_VM_FILE_UPLOAD);
335+
expect(resultState.projectId).toBe(null);
299336
});
300337

301338
test('requestProjectUpload when showing project with id results in state LOADING_VM_FILE_UPLOAD', () => {
302339
const initialState = {
340+
projectId: '100',
303341
loadingState: LoadingState.SHOWING_WITH_ID
304342
};
305343
const action = requestProjectUpload(initialState.loadingState);
306344
const resultState = projectStateReducer(initialState, action);
307345
expect(resultState.loadingState).toBe(LoadingState.LOADING_VM_FILE_UPLOAD);
346+
expect(resultState.projectId).toBe('100');
308347
});
309348

310349
test('requestProjectUpload when showing project without id results in state LOADING_VM_FILE_UPLOAD', () => {
311350
const initialState = {
351+
projectId: null,
312352
loadingState: LoadingState.SHOWING_WITHOUT_ID
313353
};
314354
const action = requestProjectUpload(initialState.loadingState);
315355
const resultState = projectStateReducer(initialState, action);
316356
expect(resultState.loadingState).toBe(LoadingState.LOADING_VM_FILE_UPLOAD);
357+
expect(resultState.projectId).toBe(null);
317358
});
318359

319360
test('manualUpdateProject should prepare to update', () => {
320361
const initialState = {
362+
projectId: '100',
321363
loadingState: LoadingState.SHOWING_WITH_ID
322364
};
323365
const action = manualUpdateProject();
324366
const resultState = projectStateReducer(initialState, action);
325367
expect(resultState.loadingState).toBe(LoadingState.MANUAL_UPDATING);
368+
expect(resultState.projectId).toBe('100');
326369
});
327370

328371
test('autoUpdateProject should prepare to update', () => {
329372
const initialState = {
373+
projectId: '100',
330374
loadingState: LoadingState.SHOWING_WITH_ID
331375
};
332376
const action = autoUpdateProject();
333377
const resultState = projectStateReducer(initialState, action);
334378
expect(resultState.loadingState).toBe(LoadingState.AUTO_UPDATING);
379+
expect(resultState.projectId).toBe('100');
335380
});
336381

337382
test('saveProjectAsCopy should save, before preparing to save as a copy', () => {
338383
const initialState = {
384+
projectId: '100',
339385
loadingState: LoadingState.SHOWING_WITH_ID
340386
};
341387
const action = saveProjectAsCopy();
342388
const resultState = projectStateReducer(initialState, action);
343389
expect(resultState.loadingState).toBe(LoadingState.UPDATING_BEFORE_COPY);
390+
expect(resultState.projectId).toBe('100');
344391
});
345392

346393
test('remixProject should prepare to remix', () => {
347394
const initialState = {
395+
projectId: '100',
348396
loadingState: LoadingState.SHOWING_WITH_ID
349397
};
350398
const action = remixProject();
351399
const resultState = projectStateReducer(initialState, action);
352400
expect(resultState.loadingState).toBe(LoadingState.REMIXING);
401+
expect(resultState.projectId).toBe('100');
353402
});
354403

355404
test('projectError from various states should show error', () => {
@@ -368,11 +417,13 @@ test('projectError from various states should show error', () => {
368417
for (const startState of startStates) {
369418
const initialState = {
370419
error: null,
420+
projectId: '100',
371421
loadingState: startState
372422
};
373423
const action = projectError('Error string');
374424
const resultState = projectStateReducer(initialState, action);
375425
expect(resultState.error).toEqual('Error string');
426+
expect(resultState.projectId).toBe('100');
376427
}
377428
});
378429

@@ -386,11 +437,13 @@ test('fatal projectError should show error state', () => {
386437
for (const startState of startStates) {
387438
const initialState = {
388439
error: null,
440+
projectId: '100',
389441
loadingState: startState
390442
};
391443
const action = projectError('Error string');
392444
const resultState = projectStateReducer(initialState, action);
393445
expect(resultState.loadingState).toBe(LoadingState.ERROR);
446+
expect(resultState.projectId).toBe('100');
394447
}
395448
});
396449

@@ -405,11 +458,13 @@ test('non-fatal projectError should show normal state', () => {
405458
for (const startState of startStates) {
406459
const initialState = {
407460
error: null,
461+
projectId: '100',
408462
loadingState: startState
409463
};
410464
const action = projectError('Error string');
411465
const resultState = projectStateReducer(initialState, action);
412466
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
467+
expect(resultState.projectId).toBe('100');
413468
}
414469
});
415470

@@ -423,6 +478,7 @@ test('projectError when creating new while viewing project with id should ' +
423478
const action = projectError('Error string');
424479
const resultState = projectStateReducer(initialState, action);
425480
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID);
481+
expect(resultState.projectId).toBe('12345');
426482
});
427483

428484
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
435491
const action = projectError('Error string');
436492
const resultState = projectStateReducer(initialState, action);
437493
expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID);
494+
expect(resultState.projectId).toBe('0');
438495
});
439496

440497
test('projectError encountered while in state FETCHING_WITH_ID results in ' +
441498
'ERROR state', () => {
442499
const initialState = {
443500
error: null,
501+
projectId: null,
444502
loadingState: LoadingState.FETCHING_WITH_ID
445503
};
446504
const action = projectError('Error string');
447505
const resultState = projectStateReducer(initialState, action);
448506
expect(resultState.loadingState).toBe(LoadingState.ERROR);
507+
expect(resultState.projectId).toBe(null);
449508
expect(resultState.error).toEqual('Error string');
450509
});

0 commit comments

Comments
 (0)