-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48279f4
commit 86a6304
Showing
3 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const assert = require('node:assert/strict') | ||
const { describe, it } = require('node:test') | ||
const wizard = require('../wizard.js') | ||
|
||
describe('GOV.UK Prototype Wizard (with baseUrl)', () => { | ||
const journey = { | ||
'/name': {}, | ||
'/do-you-have-a-national-insurance-number': { | ||
'/email': { data: 'have-nino', value: 'No' } | ||
}, | ||
'/what-is-your-national-insurance-number': {}, | ||
'/email': {} | ||
} | ||
|
||
it('Returns current, next and previous paths', () => { | ||
const req = { | ||
baseUrl: '/questions', | ||
method: 'POST', | ||
originalUrl: '/questions/do-you-have-a-national-insurance-number', | ||
path: '/do-you-have-a-national-insurance-number', | ||
session: { data: { 'have-nino': 'No' } } | ||
} | ||
|
||
assert.deepEqual(wizard(journey, req), { | ||
back: '/questions/name', | ||
current: '/questions/do-you-have-a-national-insurance-number', | ||
next: '/questions/email' | ||
}) | ||
}) | ||
|
||
it('Returns next path with modified query string', () => { | ||
const journey = { | ||
'/filter/location': {}, | ||
'/list?success=1': {} | ||
} | ||
|
||
const req = { | ||
baseUrl: '/results', | ||
method: 'POST', | ||
originalUrl: '/results/filter/location?page=2&sort=asc', | ||
path: '/filter/location', | ||
query: { | ||
page: '2', | ||
sort: 'asc' | ||
}, | ||
session: { data: {} } | ||
} | ||
|
||
assert.deepEqual(wizard(journey, req), { | ||
back: '', | ||
current: '/results/filter/location?page=2&sort=asc', | ||
next: '/results/list?success=1&page=2&sort=asc' | ||
}) | ||
}) | ||
|
||
it('Adds fork data pointing back to where user forked from', () => { | ||
const req = { | ||
baseUrl: '/questions', | ||
method: 'GET', | ||
originalUrl: '/questions/email', | ||
path: '/email', | ||
session: { | ||
data: { | ||
'forked-to': '/email', | ||
'forked-from': '/do-you-have-a-national-insurance-number' | ||
} | ||
} | ||
} | ||
|
||
assert.deepEqual(wizard(journey, req), { | ||
back: '/questions/do-you-have-a-national-insurance-number', | ||
current: '/questions/email', | ||
next: '' | ||
}) | ||
}) | ||
|
||
it('Removes fork data when returning to page that created it', () => { | ||
const req = { | ||
baseUrl: '/questions', | ||
method: 'GET', | ||
session: { | ||
data: { | ||
'forked-from': '/do-you-have-a-national-insurance-number', | ||
'forked-to': '/email' | ||
} | ||
}, | ||
originalUrl: '/questions/do-you-have-a-national-insurance-number', | ||
path: '/do-you-have-a-national-insurance-number' | ||
} | ||
|
||
wizard(journey, req) | ||
|
||
assert.equal(req.session.data['forked-from'], undefined) | ||
assert.equal(req.session.data['forked-to'], undefined) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86a6304
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wishing for this yesterday when I discovered this nice little plugin you've created @paulrobertlloyd - Did you read my mind?
86a6304
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn’t read your mind, but perhaps @fofr did? It was he who originally put this plugin together – I’ve been tending to it as I push the limits of Express and find various path related bugs!