Skip to content

Commit

Permalink
Return params if no stored data
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Feb 11, 2024
1 parent 55eac05 commit 0efb7d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lib/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ exports.decorate = function (params, keyPath, componentName) {
}

// Get stored value from session data, else local data
const storedValue = _.get(data, keyPath) || _.get(this.ctx, keyPath)
if (!storedValue) {
return ''
}
const storedValue = _.get(data, keyPath) || _.get(this.ctx, keyPath) || ''

params.id = params.id ? params.id : keyPath.join('-')
params.name = params.name
Expand Down
18 changes: 16 additions & 2 deletions test/lib/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ test('Returns form component without decorate attribute', () => {
test('Returns form component without any session data', () => {
const result = env.render('input.njk', {})

assert.match(result, /id=""/)
assert.match(result, /name=""/)
assert.match(result, /Email address/)
assert.match(result, /for="account-email-address"/)
assert.match(result, /id="account-email-address"/)
assert.match(result, /name="\[account\]\[email-address\]"/)
assert.doesNotMatch(result, /value/)
})

test('Decorates form component from session data', (t) => {
Expand All @@ -49,9 +52,20 @@ test('Decorates form component from session data', (t) => {
assert.match(result, /value="test@example.org"/)
})

test('Returns form component without any local data', () => {
const result = env.render('input-locals.njk', {})

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

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

assert.match(result, /Name/)
assert.match(result, /for="name"/)
assert.match(result, /id="name"/)
assert.match(result, /name="\[name\]"/)
Expand Down

0 comments on commit 0efb7d7

Please sign in to comment.