hof-component-date
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -42,2 +42,6 @@ 'use strict'; | ||
const getLegendClassName = field => { | ||
return field && field.legend && field.legend.className || ''; | ||
}; | ||
module.exports = (key, options) => { | ||
@@ -112,4 +116,5 @@ if (!key) { | ||
const hint = conditionalTranslate(`fields.${key}.hint`, req.translate); | ||
const legendClassName = getLegendClassName(options); | ||
const error = req.form.errors && req.form.errors[key]; | ||
res.render(template, { key, legend, hint, error }, (err, html) => { | ||
res.render(template, { key, legend, legendClassName, hint, error }, (err, html) => { | ||
if (err) { | ||
@@ -116,0 +121,0 @@ next(err); |
{ | ||
"name": "hof-component-date", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A hof middleware for rendering and processing 3 part date fields", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -145,5 +145,5 @@ 'use strict'; | ||
it('calls res.render with template, key, legend and hint. Where the latter two are null', () => { | ||
it('calls res.render with template & key.', () => { | ||
date.hooks['pre-render'](req, res, next); | ||
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error: undefined, key: 'date-field', legend: null, hint: null }); | ||
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), sinon.match({key: 'date-field'})); | ||
}); | ||
@@ -157,6 +157,6 @@ | ||
date.hooks['pre-render'](req, res, next); | ||
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error, key: 'date-field', legend: null, hint: null }); | ||
expect(res.render).to.have.been.calledWith(sinon.match.string, sinon.match({error})); | ||
}); | ||
it('calls res.render with template, key, legend and hint with values NOT null', () => { | ||
it('calls res.render with a legend and hint', () => { | ||
req.translate = sinon.stub(); | ||
@@ -166,5 +166,19 @@ req.translate.withArgs('fields.date-field.legend').returns('you legend'); | ||
date.hooks['pre-render'](req, res, next); | ||
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error: undefined, key: 'date-field', legend: 'you legend', hint: 'some hint' }); | ||
const args = res.render.lastCall.args; | ||
expect(args[1]).to.have.property('legend').and.to.equal('you legend'); | ||
expect(args[1]).to.have.property('hint').and.to.equal('some hint'); | ||
}); | ||
it('checks the legendClassName and the value', () => { | ||
date = dateComponent('date-field', { | ||
legend: { | ||
className: 'testClass' | ||
} | ||
}); | ||
date.hooks['pre-render'](req, res, next); | ||
const args = res.render.lastCall.args; | ||
expect(args[1]).to.have.property('legendClassName'); | ||
expect(args[1].legendClassName).to.equal('testClass'); | ||
}); | ||
it('calls next with an error if res.render calls callback with err', () => { | ||
@@ -171,0 +185,0 @@ res.render.yields('err'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38857
26
392
1