From 1772a0b11db856571b0b6755847a047b7e562710 Mon Sep 17 00:00:00 2001 From: BecioProton Date: Thu, 22 Feb 2024 00:51:19 +0000 Subject: [PATCH] feat: make optional prefix --- components/hmpo-text/macro.njk | 2 +- components/hmpo-text/spec.macro.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/components/hmpo-text/macro.njk b/components/hmpo-text/macro.njk index 4c19eb6..111c619 100644 --- a/components/hmpo-text/macro.njk +++ b/components/hmpo-text/macro.njk @@ -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, value: hmpoGetValue(ctx, params), errorMessage: hmpoGetError(ctx, params), type: params.type, diff --git a/components/hmpo-text/spec.macro.js b/components/hmpo-text/spec.macro.js index 37956bd..5e6ba47 100644 --- a/components/hmpo-text/spec.macro.js +++ b/components/hmpo-text/spec.macro.js @@ -50,13 +50,33 @@ describe('hmpoText', () => { }); it('renders with label and 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()).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(''); + }); + + it('renders with label and without prefix when prefix not provided', () => { const $ = render({ component: 'hmpoText', params: { id: 'my-input' }, 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', () => {