File tree Expand file tree Collapse file tree 3 files changed +12
-38
lines changed Top Open diff view settings
web-app/src/services/state/actions Expand file tree Collapse file tree 3 files changed +12
-38
lines changed Top Open diff view settings Original file line number Diff line number Diff line change @@ -34,28 +34,7 @@ export const initPosition = assign({
3434
3535export const updateStepPosition = assign ( {
3636 position : ( context : T . MachineContext , event : T . MachineEvent ) : any => {
37- const { position } = context
38- // merge in the updated position
39- // sent with the test to ensure consistency
40- const level : TT . Level = selectors . currentLevel ( context )
41- const steps : TT . Step [ ] = level . steps
42-
43- // final step now completed
44- if ( steps [ steps . length - 1 ] . id === position . stepId ) {
45- return { ...position , complete : true }
46- }
47-
48- const stepIndex = steps . findIndex ( ( s : TT . Step ) => s . id === position . stepId )
49-
50- const step : TT . Step = steps [ stepIndex + 1 ]
51-
52- const nextPosition : T . Position = {
53- ...position ,
54- stepId : step . id ,
55- complete : false ,
56- }
57-
58- return nextPosition
37+ return event . payload . position
5938 } ,
6039} )
6140
Original file line number Diff line number Diff line change @@ -29,16 +29,6 @@ describe('stepNext', () => {
2929 it ( 'should LOAD_NEXT_STEP when there is another step' , ( ) => {
3030 const position = { levelId : '1' , stepId : '1.2' , complete : false }
3131 const result = getStepNext ( position , level )
32- expect ( result ) . toEqual ( {
33- type : 'LOAD_NEXT_STEP' ,
34- payload : {
35- step : level . steps [ 1 ] ,
36- } ,
37- } )
38- } )
39- it ( 'should LOAD_NEXT_STEP when there is another step but no more' , ( ) => {
40- const position = { levelId : '1' , stepId : '1.3' , complete : false }
41- const result = getStepNext ( position , level )
4232 expect ( result ) . toEqual ( {
4333 type : 'LOAD_NEXT_STEP' ,
4434 payload : {
Original file line number Diff line number Diff line change 11import * as T from 'typings'
22import * as TT from 'typings/tutorial'
3+ import logger from '../../../../services/logger'
34
45const getStepNext = ( position : T . Position , level : TT . Level ) : T . Action => {
6+ logger ( 'getStepNext position' , position )
57 const { steps } = level
68
79 if ( steps . length ) {
810 const stepIndex = steps . findIndex ( ( s : TT . Step ) => s . id === position . stepId )
9- const nextStep = steps [ stepIndex ]
10- return {
11- type : 'LOAD_NEXT_STEP' ,
12- payload : {
13- step : nextStep ,
14- } ,
11+ const finalStepIndex = steps . length - 1
12+ if ( stepIndex < finalStepIndex ) {
13+ const nextStep = steps [ stepIndex + 1 ]
14+ return {
15+ type : 'LOAD_NEXT_STEP' ,
16+ payload : {
17+ step : nextStep ,
18+ } ,
19+ }
1520 }
1621 }
1722 return {
You can’t perform that action at this time.
0 commit comments