Skip to content

Commit

Permalink
feat: make optional prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
BecioProton authored and shivanshuit914 committed Mar 5, 2024
1 parent d1e57f4 commit b9f6393
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion components/hmpo-template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
serviceName: govukServiceName,
navigation: govukNavigation,
serviceUrl: govukServiceUrl or "/",
containerClasses: "govuk-width-container"
containerClasses: "govuk-width-container",
useTudorCrown: true
}) }}
{% endblock %}
{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion components/hmpo-text/macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
hmpoGetOptions(ctx, params, "label")
),
hint: hmpoGetOptions(ctx, params, "hint", true),
prefix: hmpoGetOptions(ctx, params, "prefix", true),
prefix: hmpoGetOptions(ctx, params, "prefix", true) if params.prefix else "",
value: hmpoGetValue(ctx, params),
errorMessage: hmpoGetError(ctx, params),
type: params.type,
Expand Down
14 changes: 12 additions & 2 deletions components/hmpo-text/spec.macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,23 @@ describe('hmpoText', () => {
});

it('renders with label and prefix', () => {
const $ = render({ component: 'hmpoText', params: { id: 'my-input' }, ctx: true }, locals);
const $ = render({ component: 'hmpoText', params: { id: 'my-input', prefix: '£' }, ctx: true }, locals);

const $label = $('.govuk-label');
expect($label.text().trim()).to.equal('[fields.my-input.label]');
expect($label.attr('id')).to.equal('my-input-label');
const $prefix = $('.govuk-input__prefix');
expect($prefix.text()).to.equal('£');
});

it('renders with label and without prefix', () => {
const $ = render({ component: 'hmpoText', params: { id: 'my-input', prefix: '' }, ctx: true }, locals);

const $label = $('.govuk-label');
expect($label.text().trim()).to.equal('[fields.my-input.label]');
expect($label.attr('id')).to.equal('my-input-label');
const $prefix = $('.govuk-input__prefix');
expect($prefix.text().trim()).to.equal('[fields.my-input.prefix]');
expect($prefix.text().trim()).to.equal('');
});

it('renders with value', () => {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"devDependencies": {
"chai": "^4.3.7",
"eslint": "^8.44.0",
"govuk-frontend": "^4.6.0",
"govuk-frontend": "^4.8.0",
"hmpo-nunjucks-test": "^1.4.1",
"husky": "^2.7.0",
"mocha": "^10.2.0",
Expand Down

0 comments on commit b9f6393

Please sign in to comment.