diff --git a/test/fixtures/input-locals.njk b/test/fixtures/input-locals.njk new file mode 100644 index 0000000..f5c5162 --- /dev/null +++ b/test/fixtures/input-locals.njk @@ -0,0 +1,8 @@ +{% from "x-nhsuk/decorated/input/macro.njk" import input with context %} + +{{ input({ + label: { + text: "Name" + }, + decorate: "name" +}) }} diff --git a/test/lib/decorate.js b/test/lib/decorate.js index fa02f42..4271c84 100644 --- a/test/lib/decorate.js +++ b/test/lib/decorate.js @@ -22,7 +22,8 @@ const data = { year: '1999' }, status: 'published' - } + }, + name: 'Aneurin Bevan' } test('Returns form component without decorate attribute', () => { @@ -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"/) @@ -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)