hmpo-form-wizard
Advanced tools
Comparing version 11.0.2 to 11.1.0
@@ -51,11 +51,14 @@ 'use strict'; | ||
getBackLink(req, res) { | ||
let backLink = super.getBackLink(req, res); | ||
if (!req.isEditing) { | ||
return backLink; | ||
return super.getBackLink(req, res); | ||
} | ||
let previousStep = this.walkJourneyHistory(req, res, step => step.path === backLink); | ||
if (previousStep && (previousStep.continueOnEdit || previousStep.editing)) { | ||
return backLink + req.form.options.editSuffix; | ||
let path = req.form.options.fullPath; | ||
let previousEditStep; | ||
this.walkJourneyHistory(req, res, step => { | ||
if (step.path === path) return true; | ||
if (step.editing) previousEditStep = step; | ||
}); | ||
if (previousEditStep) { | ||
return previousEditStep.path + req.form.options.editSuffix; | ||
} | ||
@@ -71,10 +74,12 @@ | ||
let nextStep = this.getNextStepObject(req, res); | ||
if (typeof req.query.next !== 'string') { | ||
let nextStep = this.getNextStepObject(req, res); | ||
// if the user should continue in edit mode: continue to next step in edit mode | ||
if ((nextStep.condition && nextStep.condition.continueOnEdit) || (!nextStep.condition && req.form.options.continueOnEdit)) { | ||
let nextStepUrl = this.resolvePath(req.baseUrl, nextStep.url); | ||
if (nextStepUrl.startsWith('/')) nextStepUrl += req.form.options.editSuffix; | ||
debug('edit journey continuing', nextStepUrl); | ||
return nextStepUrl; | ||
// if the user should continue in edit mode: continue to next step in edit mode | ||
if ((nextStep.condition && nextStep.condition.continueOnEdit) || (!nextStep.condition && req.form.options.continueOnEdit)) { | ||
let nextStepUrl = this.resolvePath(req.baseUrl, nextStep.url); | ||
if (nextStepUrl.startsWith('/')) nextStepUrl += req.form.options.editSuffix; | ||
debug('edit journey continuing', nextStepUrl); | ||
return nextStepUrl; | ||
} | ||
} | ||
@@ -81,0 +86,0 @@ |
{ | ||
"name": "hmpo-form-wizard", | ||
"version": "11.0.2", | ||
"version": "11.1.0", | ||
"description": "Routing and request handling for a multi-step form processes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -87,15 +87,28 @@ 'use strict'; | ||
it('returns previous edit step if it has continueOnEdit option set', () => { | ||
it('returns previous edit step from history', () => { | ||
req.isEditing = true; | ||
req.journeyModel.set('history', [{ path: '/base/backlink', continueOnEdit: true }]); | ||
req.form.options.fullPath = '/base/currentpage'; | ||
req.journeyModel.set('history', [ | ||
{ path: '/base/firstpage', next: '/base/wrongbacklink' }, | ||
{ path: '/base/wrongbacklink', next: '/base/anotherpage', editing: true }, | ||
{ path: '/base/anotherpage', next: '/base/backlink' }, | ||
{ path: '/base/backlink', next: '/base/anotherpage2', editing: true }, | ||
{ path: '/base/anotherpage2', next: '/base/currentpage' }, | ||
{ path: '/base/currentpage' } | ||
]); | ||
controller.getBackLink(req, res).should.equal('/base/backlink/editsuffix'); | ||
}); | ||
it('returns editBackStep if the previous step does not have continueOnEdit set', () => { | ||
it('returns editBackStep if not previous editing steps', () => { | ||
req.isEditing = true; | ||
req.journeyModel.set('history', [{ path: '/base/backlink' }]); | ||
req.journeyModel.set('history', [ | ||
{ path: '/base/firstpage', next: '/base/anotherpage' }, | ||
{ path: '/base/anotherpage', next: '/base/anotherpage2' }, | ||
{ path: '/base/anotherpage2', next: '/base/currentpage' }, | ||
{ path: '/base/currentpage' } | ||
]); | ||
controller.getBackLink(req, res).should.equal('/base/url/backstep'); | ||
}); | ||
it('returns editBackStep if the previous step is not in history', () => { | ||
it('returns editBackStep if the current step is not in history', () => { | ||
req.isEditing = true; | ||
@@ -184,2 +197,10 @@ req.journeyModel.set('history', []); | ||
it('does not return next continueOnEdit step if only checking the next condition', () => { | ||
req.isEditing = true; | ||
req.query.next = ''; | ||
controller.options.continueOnEdit = true; | ||
controller.getNextStepObject.returns({ url: 'c' }); | ||
controller.getNextStep(req, res).should.equal('/base/url/backstep'); | ||
}); | ||
it('returns next remote url if the step has the continueOnEdit option set', () => { | ||
@@ -186,0 +207,0 @@ req.isEditing = true; |
374201
8682