-
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
d26406a
commit 9c5438b
Showing
13 changed files
with
2,235 additions
and
3,905 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,131 @@ | ||
const assert = require('node:assert/strict') | ||
const test = require('node:test') | ||
const nunjucks = require('nunjucks') | ||
const { decorate } = require('../../lib/decorate.js') | ||
|
||
const env = nunjucks.configure([ | ||
'./', | ||
'./node_modules/nhsuk-frontend/packages/components', | ||
'./test/fixtures' | ||
]) | ||
env.addGlobal('decorate', decorate) | ||
|
||
const data = { | ||
data: { | ||
account: { | ||
'email-address': '[email protected]' | ||
}, | ||
country: 'england', | ||
'passport-issued': { | ||
day: '31', | ||
month: '12', | ||
year: '1999' | ||
}, | ||
status: 'published' | ||
} | ||
} | ||
|
||
test('Returns form component without decorate attribute', () => { | ||
const result = env.render('input-not-decorated.njk', data) | ||
|
||
assert.match(result, /id=""/) | ||
assert.match(result, /name=""/) | ||
}) | ||
|
||
test('Returns form component without any session data', () => { | ||
const result = env.render('input.njk', {}) | ||
|
||
assert.match(result, /id=""/) | ||
assert.match(result, /name=""/) | ||
}) | ||
|
||
test('Decorates form component', t => { | ||
const result = env.render('input.njk', data) | ||
|
||
assert.match(result, /for="account-email-address"/) | ||
assert.match(result, /id="account-email-address"/) | ||
assert.match(result, /name="\[account\]\[email-address\]"/) | ||
assert.match(result, /value="test@example.org"/) | ||
}) | ||
|
||
test('Decorates form component with items', () => { | ||
const result = env.render('radios.njk', data) | ||
|
||
assert.match(result, /for="country-1"/) | ||
assert.match(result, /for="country-2"/) | ||
assert.match(result, /id="country-1".*name="\[country\].*value="england".*checked/) | ||
assert.match(result, /id="country-2".*name="\[country\].*value="scotland"/) | ||
}) | ||
|
||
test('Decorates form component with items (data stored in array)', () => { | ||
const result = env.render('radios.njk', { | ||
data: { country: ['england'] } | ||
}) | ||
|
||
assert.match(result, /for="country-1"/) | ||
assert.match(result, /for="country-2"/) | ||
assert.match(result, /id="country-1".*name="\[country\].*value="england".*checked/) | ||
assert.match(result, /id="country-2".*name="\[country\].*value="scotland"/) | ||
}) | ||
|
||
test('Decorates button component', () => { | ||
const result = env.render('button.njk', data) | ||
|
||
assert.match(result, /name="\[status\]"/) | ||
assert.match(result, /value="published"/) | ||
}) | ||
|
||
test('Does not decorate button link component', () => { | ||
const result = env.render('button-href.njk', data) | ||
|
||
assert.doesNotMatch(result, /name="\[status\]"/) | ||
assert.doesNotMatch(result, /value="published"/) | ||
}) | ||
|
||
test('Uses label text if no value given for option', () => { | ||
const result = env.render('radios-no-values.njk', data) | ||
|
||
assert.match(result, /id="country-1".*name="\[country\].*value="England"/) | ||
assert.match(result, /id="country-2".*name="\[country\].*value="Scotland"/) | ||
assert.match(result, /id="country-3".*name="\[country\].*value="Wales"/) | ||
assert.match(result, /id="country-4".*name="\[country\].*value="Northern Ireland"/) | ||
assert.match(result, /id="country-6".*name="\[country\].*value="Another country"/) | ||
}) | ||
|
||
test('Decorates date input component', () => { | ||
const result = env.render('date-input.njk', data) | ||
|
||
assert.match(result, /for="passport-issued-day"/) | ||
assert.match(result, /for="passport-issued-month"/) | ||
assert.match(result, /for="passport-issued-year"/) | ||
assert.match(result, /id="passport-issued-day".*name="\[passport-issued\]\[day\].*value="31"/) | ||
assert.match(result, /id="passport-issued-month".*name="\[passport-issued\]\[month\].*value="12"/) | ||
assert.match(result, /id="passport-issued-year".*name="\[passport-issued\]\[year\].*value="1999"/) | ||
}) | ||
|
||
test('Strips data from key path', () => { | ||
const result = env.render('input-data-in-key-path.njk', data) | ||
|
||
assert.match(result, /for="account-email-address"/) | ||
assert.match(result, /id="account-email-address"/) | ||
assert.match(result, /name="\[account\]\[email-address\]"/) | ||
assert.match(result, /value="test@example.org"/) | ||
}) | ||
|
||
test('Add message if error', () => { | ||
const result = env.render('input.njk', { | ||
...data, | ||
...{ | ||
errors: { | ||
'account.email-address': { | ||
msg: 'Enter an email address in the correct format' | ||
} | ||
} | ||
} | ||
}) | ||
|
||
assert.match(result, /id="account-email-address-error"/) | ||
assert.match(result, /Error:/) | ||
assert.match(result, /Enter an email address in the correct format/) | ||
assert.match(result, /aria-describedby="account-email-address-error"/) | ||
}) |
This file was deleted.
Oops, something went wrong.