Skip to content

Commit

Permalink
Merge pull request #714 from digital-land/rosado/659-default-error-st…
Browse files Browse the repository at this point in the history
…atus-hint

Default error hint on LPA overview page
  • Loading branch information
rosado authored Dec 12, 2024
2 parents f15459a + 5ab2be1 commit aa6942c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/views/organisations/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% set serviceType = 'Manage' %}

{% macro datasetItem(dataset) %}
<li class="govuk-task-list__item govuk-task-list__item--with-link" data-dataset="{{ dataset.dataset }}">
<li class="govuk-task-list__item govuk-task-list__item--with-link" data-dataset="{{ dataset.dataset }}" data-dataset-status="{{ dataset.status }}">
<div class="govuk-task-list__name-and-hint">
<h3 class="govuk-heading-m">
{% if dataset.status == 'Not submitted' %}
Expand All @@ -31,7 +31,11 @@ <h3 class="govuk-heading-m">
{% elif dataset.status == 'Not submitted' %}
<p>Data URL not submitted</p>
{% elif dataset.status == 'Error' %}
<p>{{dataset.error}}</p>
{% if not dataset.error or dataset.error === '' %}
<p>There was an error accessing the data URL</p>
{% else %}
<p>{{ dataset.error }}</p>
{% endif %}
{% elif dataset.status == 'Needs fixing' %}
<p>There {{ "is" | pluralise(dataset.issue_count) }} {{ dataset.issue_count }} {{ "issue" | pluralise(dataset.issue_count) }} in this dataset</p>
{% else %}
Expand Down
33 changes: 29 additions & 4 deletions test/unit/middleware/overview.middleware.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { describe, it, vi, expect, beforeEach, afterEach } from 'vitest'
import { addNoticesToDatasets, aggregateOverviewData, datasetSubmissionDeadlineCheck, getOverview, prepareOverviewTemplateParams } from '../../../src/middleware/overview.middleware'
import { setupNunjucks } from '../../../src/serverSetup/nunjucks.js'
import jsdom from 'jsdom'

const nunjucks = setupNunjucks({ datasetNameMapping: new Map() })

vi.mock('../../../src/utils/utils.js', async (importOriginal) => {
const original = await importOriginal()
Expand All @@ -17,6 +21,13 @@ vi.mock('../../../src/utils/utils.js', async (importOriginal) => {
describe('overview.middleware', () => {
const exampleLpa = { name: 'Example LPA', organisation: 'LPA' }

const getRenderedErrorCards = (templateParams) => {
const html = nunjucks.render('organisations/overview.html', templateParams)
const doc = new jsdom.JSDOM(html).window.document
const errorNodes = doc.querySelectorAll('[data-dataset-status="Error"]')
return Array.from(errorNodes)
}

describe('prepareOverviewTemplateParams', () => {
it('should render the overview page', async () => {
const req = {
Expand All @@ -43,12 +54,21 @@ describe('overview.middleware', () => {
endpoint: 'https://example.com',
error: undefined,
status: 'Error'
},
{
dataset: 'dataset4',
issue_count: 0,
endpoint: null,
error: 'There was a 404 error',
status: 'Error'
}

],
provisions: [
{ dataset: 'dataset1', provision_reason: 'statutory', project: 'open-digital-planning' },
{ dataset: 'dataset2', provision_reason: 'expected', project: 'open-digital-planning' },
{ dataset: 'dataset3', provision_reason: 'statutory', project: 'open-digital-planning' }
{ dataset: 'dataset3', provision_reason: 'statutory', project: 'open-digital-planning' },
{ dataset: 'dataset4', provision_reason: 'expected', project: 'open-digital-planning' }
]
}
const res = { render: vi.fn() }
Expand All @@ -63,16 +83,21 @@ describe('overview.middleware', () => {
{ endpoint: 'https://example.com', status: 'Error', dataset: 'dataset3', error: undefined, issue_count: 0, project: 'open-digital-planning' }
]),
other: expect.arrayContaining([
{ endpoint: null, status: 'Needs fixing', dataset: 'dataset2', error: undefined, issue_count: 0, project: 'open-digital-planning' }
{ endpoint: null, status: 'Needs fixing', dataset: 'dataset2', error: undefined, issue_count: 0, project: 'open-digital-planning' },
{ endpoint: null, status: 'Error', dataset: 'dataset4', error: 'There was a 404 error', issue_count: 0, project: 'open-digital-planning' }
])
},
totalDatasets: 3,
totalDatasets: 4,
datasetsWithEndpoints: 2,
datasetsWithIssues: 1,
datasetsWithErrors: 1
datasetsWithErrors: 2
}

expect(req.templateParams).toEqual(expectedTemplateParams)

const errorCardNodes = getRenderedErrorCards(req.templateParams)
expect(errorCardNodes[0].querySelector('.govuk-task-list__hint').textContent.trim()).toBe('There was an error accessing the data URL')
expect(errorCardNodes[1].querySelector('.govuk-task-list__hint').textContent.trim()).toBe('There was a 404 error')
})
})

Expand Down

0 comments on commit aa6942c

Please sign in to comment.