Skip to content

Commit

Permalink
Add test for decoration using local data
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Feb 11, 2024
1 parent 2754795 commit aa4955a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions test/fixtures/input-locals.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% from "x-nhsuk/decorated/input/macro.njk" import input with context %}

{{ input({
label: {
text: "Name"
},
decorate: "name"
}) }}
14 changes: 12 additions & 2 deletions test/lib/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const data = {
year: '1999'
},
status: 'published'
}
},
name: 'Aneurin Bevan'
}

test('Returns form component without decorate attribute', () => {
Expand All @@ -39,7 +40,7 @@ test('Returns form component without any session data', () => {
assert.match(result, /name=""/)
})

test('Decorates form component', (t) => {
test('Decorates form component from session data', (t) => {
const result = env.render('input.njk', data)

assert.match(result, /for="account-email-address"/)
Expand All @@ -48,6 +49,15 @@ test('Decorates form component', (t) => {
assert.match(result, /value="test@example.org"/)
})

test('Decorates form component from local data', (t) => {
const result = env.render('input-locals.njk', data)

assert.match(result, /for="name"/)
assert.match(result, /id="name"/)
assert.match(result, /name="\[name\]"/)
assert.match(result, /value="Aneurin Bevan"/)
})

test('Decorates form component with items', () => {
const result = env.render('radios.njk', data)

Expand Down

0 comments on commit aa4955a

Please sign in to comment.