Skip to content

Commit

Permalink
Allow Error Summary component to not include an error list
Browse files Browse the repository at this point in the history
  • Loading branch information
querkmachine committed May 7, 2024
1 parent 78cdffb commit 48de999
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ params:
description: Not strictly a parameter but [Nunjucks code convention](https://mozilla.github.io/nunjucks/templating.html#call). Using a `call` block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire error summary component in a `call` block.
- name: errorList
type: array
required: true
description: The list of errors to include in the error summary.
required: false
description: A list of errors to include in the error summary.
params:
- name: href
type: string
Expand Down Expand Up @@ -77,6 +77,10 @@ examples:
- text: Invalid username or password
- text: Agree to the terms of service to log in
href: '#example-error-1'
- name: with description
options:
titleText: There is a problem
descriptionText: The file couldn't be loaded. Try again later.
- name: with everything
options:
titleText: There is a problem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
{{ caller() if caller else (params.descriptionHtml | safe | trim | indent(8) if params.descriptionHtml else params.descriptionText) }}
</p>
{% endif %}
<ul class="govuk-list govuk-error-summary__list">
{% for item in params.errorList %}
<li>
{% if item.href %}
<a href="{{ item.href }}"
{{- govukAttributes(item.attributes) }}>
{{- item.html | safe | trim | indent(12) if item.html else item.text -}}
</a>
{% else %}
{{ item.html | safe | trim | indent(10) if item.html else item.text }}
{% endif %}
</li>
{% endfor %}
</ul>
{% if params.errorList | length %}
<ul class="govuk-list govuk-error-summary__list">
{% for item in params.errorList %}
<li>
{% if item.href %}
<a href="{{ item.href }}"
{{- govukAttributes(item.attributes) }}>
{{- item.html | safe | trim | indent(12) if item.html else item.text -}}
</a>
{% else %}
{{ item.html | safe | trim | indent(10) if item.html else item.text }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ describe('Error-summary', () => {
expect(summaryTitle).toBe('There is a problem')
})

it('renders error list element', () => {
const $ = render('error-summary', examples.default)
const $errorList = $('.govuk-error-summary__list')

expect($errorList).toHaveLength(1)
})

it('number of error items matches the number of items specified', () => {
const $ = render('error-summary', examples.default)
const errorList = $('.govuk-error-summary .govuk-error-summary__list li')
Expand Down Expand Up @@ -112,6 +119,13 @@ describe('Error-summary', () => {
expect($component.attr('second-attribute')).toBe('bar')
})

it("doesn't render the error list element if no errors are passed", () => {
const $ = render('error-summary', examples['with description'])
const $errorList = $('.govuk-error-summary__list')

expect($errorList).toHaveLength(0)
})

it('renders anchor tag with attributes', () => {
const $ = render('error-summary', examples['error list with attributes'])

Expand Down

0 comments on commit 48de999

Please sign in to comment.