- {% if dataset.endpoint is null %}
+ {% if dataset.status == 'Not submitted' %}
Data URL not submitted
- {% elif dataset.error %}
+ {% elif dataset.status == 'Error' %}
{{dataset.error}}
- {% elif dataset.issue_count > 0 %}
+ {% elif dataset.status == 'Needs fixing' > 0 %}
There are {{ dataset.issue_count }} {{ "issue" | pluralise(dataset.issue_count) }} in this dataset
{% else %}
Data URL submitted
diff --git a/test/unit/dataset-details.test.js b/test/unit/dataset-details.test.js
index 5d802230..18a70a97 100644
--- a/test/unit/dataset-details.test.js
+++ b/test/unit/dataset-details.test.js
@@ -5,10 +5,12 @@ import { setupNunjucks } from '../../src/serverSetup/nunjucks.js'
import { runGenericPageTests } from './generic-page.js'
import { stripWhitespace } from '../utils/stripWhiteSpace.js'
import { testValidationErrorMessage } from './validation-tests.js'
-import { mockDataSubjects } from './data.js'
import { render } from '../../src/utils/custom-renderer.js'
import * as v from 'valibot'
+import mock from '../utils/mocker.js'
+import { DatasetDetails } from '../../src/routes/schemas.js'
+
const nunjucks = setupNunjucks({ datasetNameMapping: new Map() })
function errorTestFn ({
@@ -39,31 +41,18 @@ function errorTestFn ({
}
describe('dataset details View', () => {
- const params = {
- organisation: {
- name: 'mock org',
- organisation: 'mock-org'
- },
- dataset: {
- name: 'mock dataset',
- dataset: 'mock-dataset',
- collection: 'mock-collection'
- },
- values: {
- dataset: 'mockDataset'
- },
- errors: {}
- }
+ const params = mock(DatasetDetails)
+ params.errors = {}
const html = stripWhitespace(nunjucks.render('dataset-details.html', params))
- const datasetName = mockDataSubjects.mockDataset.dataSets[0].value
+ const datasetName = params.values.dataset.toLowerCase()
runGenericPageTests(html, {
- pageTitle: `Enter ${datasetName.toLowerCase()} details - Submit and update your planning data`
+ pageTitle: `Enter ${datasetName} details - Submit and update your planning data`
})
it('should render the correct header', () => {
const regex = new RegExp(
- `
`,
+ ``,
'g'
)
diff --git a/test/unit/datasetTaskListPage.test.js b/test/unit/datasetTaskListPage.test.js
index cffa7b6e..d5470a42 100644
--- a/test/unit/datasetTaskListPage.test.js
+++ b/test/unit/datasetTaskListPage.test.js
@@ -3,6 +3,8 @@ import nunjucks from 'nunjucks'
import addFilters from '../../src/filters/filters'
import { runGenericPageTests } from './generic-page.js'
import jsdom from 'jsdom'
+import mocker from '../utils/mocker.js'
+import { OrgDatasetTaskList } from '../../src/routes/schemas.js'
const nunjucksEnv = nunjucks.configure([
'src/views',
@@ -21,61 +23,15 @@ const datasetNameMapping = new Map()
addFilters(nunjucksEnv, { datasetNameMapping })
describe('Dataset Task List Page', () => {
- const params = {
- organisation: {
- name: 'mock org',
- organisation: 'mock-org'
- },
- dataset: {
- name: 'Article 4 direction area'
- },
- taskList: [
- {
- title: {
- text: '2 fields have future entry dates'
- },
- href: 'toDo',
- status: {
- tag: {
- text: 'Error',
- classes: 'govuk-tag--red'
- }
- }
- },
- {
- title: {
- text: '3 fields have invalid coordinates'
- },
- href: 'toDo',
- status: {
- tag: {
- text: 'Issue',
- classes: undefined
- }
- }
- },
- {
- title: {
- text: 'one field has an invalid decimal'
- },
- href: 'toDo',
- status: {
- tag: {
- text: 'Warning',
- classes: 'govuk-tag--blue'
- }
- }
- }
- ]
- }
+ const params = mocker(OrgDatasetTaskList)
const html = nunjucks.render('organisations/datasetTaskList.html', params)
const dom = new jsdom.JSDOM(html)
const document = dom.window.document
runGenericPageTests(html, {
- pageTitle: 'mock org - Article 4 direction area - Task list - Submit and update your planning data',
- breadcrumbs: [{ text: 'Home', href: '/' }, { text: 'Organisations', href: '/organisations' }, { text: 'mock org', href: '/organisations/mock-org' }, { text: 'Article 4 direction area' }]
+ pageTitle: `${params.organisation.name} - ${params.dataset.name} - Task list - Submit and update your planning data`,
+ breadcrumbs: [{ text: 'Home', href: '/' }, { text: 'Organisations', href: '/organisations' }, { text: 'mock org', href: `/organisations/${params.organisation.organisation}` }, { text: 'Article 4 direction area' }]
})
it('Renders the correct headings', () => {
@@ -91,7 +47,7 @@ describe('Dataset Task List Page', () => {
expect(document.querySelector('.app-c-dataset-navigation')).not.toBeNull()
expect(links.length).toEqual(2)
expect(activeLink.textContent).toContain('Task list')
- expect(issueCount.textContent).toContain('3 issues')
+ expect(issueCount.textContent).toContain(`${params.taskList.length} issue${params.taskList.length > 1 ? 's' : ''}`)
})
const taskListItems = document.querySelectorAll('.govuk-task-list__item')
@@ -107,7 +63,7 @@ describe('Dataset Task List Page', () => {
expect(link.href).toContain(task.href)
expect(status.textContent).toContain(task.status.tag.text)
if (task.status.tag.classes) {
- expect(statusStrong.classList.contains(task.status.tag.classes)).toBe(true)
+ expect(statusStrong.classList.toString()).toContain(task.status.tag.classes)
}
})
})
diff --git a/test/unit/findPage.test.js b/test/unit/findPage.test.js
index a541df3d..e2c6d7cf 100644
--- a/test/unit/findPage.test.js
+++ b/test/unit/findPage.test.js
@@ -4,6 +4,8 @@ import addFilters from '../../src/filters/filters'
import jsdom from 'jsdom'
import { runGenericPageTests } from './generic-page.js'
import config from '../../config/index.js'
+import mock from '../utils/mocker.js'
+import { OrgFindPage } from '../../src/routes/schemas.js'
const nunjucksEnv = nunjucks.configure([
'src/views',
@@ -20,32 +22,7 @@ const nunjucksEnv = nunjucks.configure([
addFilters(nunjucksEnv, {})
describe('Organisations Find Page', () => {
- const params = {
- alphabetisedOrgs: {
- A: [
- {
- name: 'Aberdeen'
- },
- {
- name: 'Aylesbury'
- },
- {
- name: 'Ashford'
- }
- ],
- B: [
- {
- name: 'Bath'
- },
- {
- name: 'Birmingham'
- },
- {
- name: 'Brighton'
- }
- ]
- }
- }
+ const params = mock(OrgFindPage)
const html = nunjucks.render('organisations/find.html', params)
diff --git a/test/unit/get-startedPage.test.js b/test/unit/get-startedPage.test.js
index 95e85464..c6d77600 100644
--- a/test/unit/get-startedPage.test.js
+++ b/test/unit/get-startedPage.test.js
@@ -5,6 +5,8 @@ import nunjucks from 'nunjucks'
import addFilters from '../../src/filters/filters'
import { runGenericPageTests } from './generic-page.js'
import jsdom from 'jsdom'
+import mocker from '../utils/mocker.js'
+import { OrgGetStarted } from '../../src/routes/schemas.js'
const nunjucksEnv = nunjucks.configure([
'src/views',
@@ -27,27 +29,20 @@ const datasetNameMapping = new Map([
addFilters(nunjucksEnv, { datasetNameMapping })
describe('Get Started Page', () => {
- const params = {
- organisation: {
- name: 'Mock org'
- },
- dataset: {
- name: 'World heritage site buffer zone'
- }
- }
+ const params = mocker(OrgGetStarted)
const html = nunjucks.render('organisations/get-started.html', params)
const dom = new jsdom.JSDOM(html)
const document = dom.window.document
runGenericPageTests(html, {
- pageTitle: 'Mock org - World heritage site buffer zone - Get started - Submit and update your planning data'
+ pageTitle: `${params.organisation.name} - ${params.dataset.name} - Get started - Submit and update your planning data`
})
it('Renders the correct headings', () => {
- expect(document.querySelector('span.govuk-caption-xl').textContent).toEqual('Mock org')
- expect(document.querySelector('h1').textContent).toContain('World heritage site buffer zone')
- expect(document.querySelector('h2').textContent).toContain('How to prepare and submit your World heritage site buffer zone data')
+ expect(document.querySelector('span.govuk-caption-xl').textContent).toEqual(params.organisation.name)
+ expect(document.querySelector('h1').textContent).toContain(`${params.dataset.name}`)
+ expect(document.querySelector('h2').textContent).toContain(`How to prepare and submit your ${params.dataset.name} data`)
})
it('Renders breadcrumbs correctly', () => {
@@ -55,7 +50,7 @@ describe('Get Started Page', () => {
expect(breadcrumbs.length).toEqual(4)
expect(breadcrumbs[0].textContent).toContain('Home')
expect(breadcrumbs[1].textContent).toContain('Organisations')
- expect(breadcrumbs[2].textContent).toContain('Mock org')
+ expect(breadcrumbs[2].textContent).toContain(params.organisation.name)
expect(breadcrumbs[3].textContent).toContain('Get started')
})
})
diff --git a/test/unit/http-errorPage.test.js b/test/unit/http-errorPage.test.js
index 19536ea9..ca5f2b3d 100644
--- a/test/unit/http-errorPage.test.js
+++ b/test/unit/http-errorPage.test.js
@@ -2,34 +2,22 @@ import { describe, it, expect } from 'vitest'
import { setupNunjucks } from '../../src/serverSetup/nunjucks.js'
import { JSDOM } from 'jsdom'
import { runGenericPageTests } from './generic-page.js'
+import mock from '../utils/mocker.js'
+import { OrgEndpointError } from '../../src/routes/schemas.js'
const nunjucks = setupNunjucks({ datasetNameMapping: new Map() })
+const dateRegex = /\d{1,2} \w{3,9} \d{4} at \d{1,2}(?::\d{2})?(?:am|pm)/g
+
describe('http-error.html', () => {
- const params = {
- organisation: {
- name: 'mock org',
- organisation: 'mock-org'
- },
- dataset: {
- name: 'mock-dataset',
- dataset: 'mock-dataset',
- collection: 'mock-collection'
- },
- errorData: {
- endpoint_url: 'https://example.com/data-url',
- http_status: 404,
- latest_log_entry_date: '2022-01-01T12:00:00Z',
- latest_200_date: '2022-01-02T12:00:00Z'
- }
- }
+ const params = mock(OrgEndpointError)
const html = nunjucks.render('organisations/http-error.html', params)
const dom = new JSDOM(html)
const document = dom.window.document
runGenericPageTests(html, {
- pageTitle: 'mock org - mock-dataset - Task list - Submit and update your planning data'
+ pageTitle: `${params.organisation.name} - ${params.dataset.name} - Task list - Submit and update your planning data`
})
it('Renders the correct heading', () => {
@@ -49,14 +37,14 @@ describe('http-error.html', () => {
expect(rows[1].querySelector('.govuk-summary-list__value').textContent).toContain(String(params.errorData.http_status))
expect(rows[2].querySelector('.govuk-summary-list__key').textContent).toContain('Last attempted access')
- expect(rows[2].querySelector('.govuk-summary-list__value').textContent).toMatch(/\d{1,2} [A-Za-z]{3,9} \d{4} at \d{1,2}(am|pm)/)
+ expect(rows[2].querySelector('.govuk-summary-list__value').textContent).toMatch(dateRegex)
expect(rows[3].querySelector('.govuk-summary-list__key').textContent).toContain('Last successful access')
- expect(rows[3].querySelector('.govuk-summary-list__value').textContent).toMatch(/\d{1,2} [A-Za-z]{3,9} \d{4} at \d{1,2}(am|pm)/)
+ expect(rows[3].querySelector('.govuk-summary-list__value').textContent).toMatch(dateRegex)
})
it('re-submit link points to get-started page', () => {
const resubmitLink = document.querySelector('a.resubmit-link')
- expect(resubmitLink.getAttribute('href')).toBe(`/organisations/${params.organisation.organisation}/${params.dataset.name}/get-started`)
+ expect(resubmitLink.getAttribute('href')).toBe(`/organisations/${encodeURIComponent(params.organisation.organisation)}/${encodeURIComponent(params.dataset.name)}/get-started`)
})
})
diff --git a/test/unit/issueDetailsPage.test.js b/test/unit/issueDetailsPage.test.js
index 57e5a231..4f17f8c8 100644
--- a/test/unit/issueDetailsPage.test.js
+++ b/test/unit/issueDetailsPage.test.js
@@ -4,6 +4,8 @@ import addFilters from '../../src/filters/filters'
import { JSDOM } from 'jsdom'
import { runGenericPageTests } from './generic-page.js'
import config from '../../config/index.js'
+import { OrgIssueDetails } from '../../src/routes/schemas.js'
+import mocker from '../utils/mocker.js'
const nunjucksEnv = nunjucks.configure([
'src/views',
@@ -21,83 +23,23 @@ const datasetNameMapping = new Map()
addFilters(nunjucksEnv, { datasetNameMapping })
describe('issueDetails.html', () => {
- const organisation = {
- name: 'mock org',
- organisation: 'mock-org'
- }
-
- const dataset = {
- name: 'mock Dataset',
- dataset: 'mock-dataset'
- }
-
- const errorHeading = 'Example error heading'
- const issueItems = [
- {
- html: '2 fields are missing values in entry 949',
- href: 'todo'
- },
- {
- html: '3 fields are missing values in entry 950',
- href: 'todo'
- }
- ]
+ const params = mocker(OrgIssueDetails)
- const entry = {
- title: '20 and 20A Whitbourne Springs',
- fields: [
- {
- key: {
- text: 'description'
- },
- value: {
- html: '20 and 20A Whitbourne Springs'
- },
- classes: ''
- },
- {
- key: {
- text: 'document-url'
- },
- value: {
- html: '
document-url missing
'
- },
- classes: 'dl-summary-card-list__row--error'
- },
- {
- key: {
- text: 'documentation-url'
- },
- value: {
- html: '
documentation-url missing
'
- },
- classes: 'dl-summary-card-list__row--error'
- }
- ]
- }
-
- const issueType = 'mock issue'
-
- const params = {
- organisation,
- dataset,
- errorHeading,
- issueItems,
- entry,
- issueType
- }
+ params.pagination = undefined
+ params.issueEntitiesCount = undefined
+ params.entityNumber = undefined
const html = nunjucks.render('organisations/issueDetails.html', params)
const dom = new JSDOM(html)
const document = dom.window.document
runGenericPageTests(html, {
- pageTitle: `mock org - mock Dataset - Issues - ${config.serviceNames.submit}`,
+ pageTitle: `${params.organisation.name} - ${params.dataset.name} - Issues - ${config.serviceNames.submit}`,
breadcrumbs: [
{ text: 'Home', href: '/' },
{ text: 'Organisations', href: '/organisations' },
- { text: 'mock org', href: '/organisations/mock-org' },
- { text: 'mock Dataset', href: '/organisations/mock-org/mock-dataset' },
+ { text: params.organisation.name, href: `/organisations/${params.organisation.organisation}` },
+ { text: params.dataset.name, href: `/organisations/${params.organisation.organisation}/${params.dataset.dataset}` },
{ text: 'mock issue' }
]
})
@@ -109,7 +51,7 @@ describe('issueDetails.html', () => {
describe('error summary', () => {
it('should render the correct heading', () => {
- expect(document.querySelector('.govuk-error-summary__title').textContent).toContain(errorHeading)
+ expect(document.querySelector('.govuk-error-summary__title').textContent).toContain(params.errorHeading || 'There is a problem')
})
it('should render the correct heading if none is supplied', () => {
@@ -127,24 +69,24 @@ describe('issueDetails.html', () => {
it('should render the issue items', () => {
const issueList = document.querySelector('.govuk-error-summary__list')
const issueItemElements = [...issueList.children]
- expect(issueItemElements.length).toBe(issueItems.length)
+ expect(issueItemElements.length).toBe(params.issueItems.length)
issueItemElements.forEach((element, index) => {
- expect(element.textContent).toContain(issueItems[index].html)
+ expect(element.textContent).toContain(params.issueItems[index].html)
})
})
})
it('should render the entry details', () => {
const cardHeader = document.querySelector('.govuk-summary-card__title')
- expect(cardHeader.textContent).toContain('20 and 20A Whitbourne Springs')
+ expect(cardHeader.textContent).toContain(params.entry.title)
const cardBody = document.querySelector('.govuk-summary-list')
const entryFields = [...cardBody.children]
- expect(entryFields.length).toBe(entry.fields.length)
+ expect(entryFields.length).toBe(params.entry.fields.length)
entryFields.forEach((element, index) => {
- expect(element.innerHTML).toContain(entry.fields[index].value.html)
+ expect(element.innerHTML).toContain(params.entry.fields[index].value.html)
})
})
@@ -188,25 +130,24 @@ describe('issueDetails.html', () => {
number: 1,
href: 'organisations/mock-org/mock-dataset/mock issue/1'
}
- const multiPageHtml = nunjucks.render('organisations/issueDetails.html', {
- ...params,
- pagination: {
- previous,
- next,
- items
- },
- issueEntitiesCount: 10,
- entityNumber: 2
- })
+ params.pagination = {
+ previous,
+ next,
+ items
+ }
+ params.issueEntitiesCount = 10
+ params.entityNumber = 2
+ const multiPageHtml = nunjucks.render('organisations/issueDetails.html', params)
// const multiPageDom = new JSDOM(multiPageHtml)
// const multiPageDocument = multiPageDom.window.document
+ const paginationTitleSection = params.issueEntitiesCount > 1 ? `(Page ${params.pageNumber} of ${params.issueEntitiesCount}) ` : ''
runGenericPageTests(multiPageHtml, {
- pageTitle: `mock org - mock Dataset - Issues (Page 2 of 10) - ${config.serviceNames.submit}`,
+ pageTitle: `${params.organisation.name} - ${params.dataset.name} - Issues ${paginationTitleSection}- ${config.serviceNames.submit}`,
breadcrumbs: [
{ text: 'Home', href: '/' },
{ text: 'Organisations', href: '/organisations' },
- { text: 'mock org', href: '/organisations/mock-org' },
- { text: 'mock Dataset', href: '/organisations/mock-org/mock-dataset' },
+ { text: params.organisation.name, href: `/organisations/${params.organisation.organisation}` },
+ { text: params.dataset.name, href: `/organisations/${params.organisation.organisation}/${params.dataset.dataset}` },
{ text: 'mock issue' }
]
})
@@ -251,15 +192,15 @@ describe('issueDetails.html', () => {
describe('Dataset visualisation: Maps', () => {
it('should render a map when geometries are passed in', () => {
const paramWithGeometry = {
- organisation,
- dataset,
- errorHeading,
- issueItems,
+ organisation: params.organisation,
+ dataset: params.dataset,
+ errorHeading: params.errorHeading,
+ issueItems: params.issueItems,
entry: {
- ...entry,
+ ...params.entry,
geometries: ['POINT(0 0)']
},
- issueType
+ issueType: params.issueType
}
const mapHtml = nunjucks.render('organisations/issueDetails.html', paramWithGeometry)
@@ -269,20 +210,20 @@ describe('issueDetails.html', () => {
expect(map).not.toBeNull()
expect(map.getAttribute('role')).toEqual('region')
- expect(map.getAttribute('aria-label')).toEqual('Static map showing mock Dataset for mock org.')
+ expect(map.getAttribute('aria-label')).toEqual(`Static map showing ${params.dataset.name} for ${params.organisation.name}.`)
})
it('should not render a map when no geometries are passed in', () => {
const paramWithGeometry = {
- organisation,
- dataset,
- errorHeading,
- issueItems,
+ organisation: params.organisation,
+ dataset: params.dataset,
+ errorHeading: params.errorHeading,
+ issueItems: params.issueItems,
entry: {
- ...entry,
+ ...params.entry,
geometries: []
},
- issueType
+ issueType: params.issueType
}
const mapHtml = nunjucks.render('organisations/issueDetails.html', paramWithGeometry)
diff --git a/test/unit/lpaOverviewPage.test.js b/test/unit/lpaOverviewPage.test.js
index d3f6c8c2..6f3a1d59 100644
--- a/test/unit/lpaOverviewPage.test.js
+++ b/test/unit/lpaOverviewPage.test.js
@@ -3,102 +3,37 @@ import { setupNunjucks } from '../../src/serverSetup/nunjucks.js'
import { runGenericPageTests } from './generic-page.js'
import jsdom from 'jsdom'
import { makeDatasetSlugToReadableNameFilter } from '../../src/filters/makeDatasetSlugToReadableNameFilter.js'
+import mocker from '../utils/mocker.js'
+import { datasetStatusEnum, OrgOverviewPage } from '../../src/routes/schemas.js'
const datasetNameMapping = new Map()
const nunjucks = setupNunjucks({ datasetNameMapping })
describe('LPA Overview Page', () => {
- const params = {
- organisation: {
- name: 'mock org',
- organisation: 'mock-org'
- },
- datasetsWithEndpoints: 2,
- totalDatasets: 8,
- datasetsWithErrors: 2,
- datasetsWithIssues: 2,
- datasets: [
- {
- slug: 'article-4-direction',
- endpoint: null,
- status: 'Not submitted',
- issue_count: 0
- },
- {
- slug: 'article-4-direction-area',
- endpoint: null,
- status: 'Not submitted'
- },
- {
- slug: 'conservation-area',
- endpoint: 'http://conservation-area.json',
- status: 'Needs fixing',
- error: null,
- issue: 'Endpoint has not been updated since 21 May 2023',
- issue_count: 1
- },
- {
- slug: 'conservation-area-document',
- endpoint: 'http://conservation-area-document.json',
- status: 'Live',
- error: null,
- issue_count: 0
- },
- {
- slug: 'listed-building-outline',
- endpoint: 'http://listed-building-outline.json',
- status: 'Live',
- error: null,
- issue_count: 0
- },
- {
- slug: 'tree',
- endpoint: 'http://tree.json',
- error: null,
- status: 'Needs fixing',
- issue: 'There are 20 issues in this dataset',
- issue_count: 1
- },
- {
- slug: 'tree-preservation-order',
- endpoint: 'http://tree-preservation-order.json',
- http_error: '404',
- error: 'There was 404 error accessing the data URL',
- status: 'Error',
- issue_count: 0
- },
- {
- slug: 'tree-preservation-zone',
- endpoint: 'http://tree-preservation-zone.json',
- status: 'Error',
- error: '400',
- issue_count: 0
- }
- ]
- }
+ const params = mocker(OrgOverviewPage)
const html = nunjucks.render('organisations/overview.html', params)
const dom = new jsdom.JSDOM(html)
const document = dom.window.document
runGenericPageTests(html, {
- pageTitle: 'mock org overview - Submit and update your planning data',
- breadcrumbs: [{ text: 'Home', href: '/' }, { text: 'Organisations', href: '/organisations' }, { text: 'mock org' }]
+ pageTitle: `${params.organisation.name} overview - Submit and update your planning data`,
+ breadcrumbs: [{ text: 'Home', href: '/' }, { text: 'Organisations', href: '/organisations' }, { text: params.organisation.name }]
})
const statsBoxes = document.querySelector('.dataset-status').children
it('Datasets provided gives the correct value', () => {
- expect(statsBoxes[0].textContent).toContain('2/8')
+ expect(statsBoxes[0].textContent).toContain(`${params.datasetsWithEndpoints}/${params.totalDatasets}`)
expect(statsBoxes[0].textContent).toContain('datasets submitted')
})
it('Datasets with errors gives the correct value', () => {
- expect(statsBoxes[1].textContent).toContain('2')
+ expect(statsBoxes[1].textContent).toContain(params.datasetsWithErrors)
expect(statsBoxes[1].textContent).toContain('data URL with errors')
})
it('Datasets with issues gives the correct value', () => {
- expect(statsBoxes[2].textContent).toContain('2')
+ expect(statsBoxes[2].textContent).toContain(params.datasetsWithIssues)
expect(statsBoxes[2].textContent).toContain('datasets need fixing')
})
@@ -118,13 +53,14 @@ describe('LPA Overview Page', () => {
let expectedHint = 'Data URL submitted'
if (dataset.status === 'Not submitted') {
expectedHint = 'Data URL not submitted'
- } else if (dataset.error) {
- expectedHint = dataset.error
- } else if (dataset.issue_count === 1) {
+ } else if (dataset.status === 'Error') {
+ expectedHint = dataset.error || ''
+ } else if (dataset.status === 'Error' && dataset.issue_count <= 1) {
expectedHint = `There are ${dataset.issue_count} issue in this dataset`
- } else if (dataset.issue_count > 1) {
+ } else if (dataset.status === 'Error' && dataset.issue_count > 1) {
expectedHint = `There are ${dataset.issue_count} issues in this dataset`
}
+
expect(datasetCards[i].querySelector('.govuk-task-list__hint').textContent.trim()).toContain(expectedHint)
})
})
@@ -148,15 +84,12 @@ describe('LPA Overview Page', () => {
params.datasets.forEach((dataset, i) => {
it(`Renders the correct status on each dataset card for dataset='${dataset.slug}'`, () => {
- let expectedStatus = 'Live'
- if (dataset.status === 'Not submitted') {
- expectedStatus = 'Not submitted'
- } else if (dataset.status === 'Error') {
- expectedStatus = dataset.status
- } else if (dataset.status === 'Needs fixing') {
- expectedStatus = 'Needs fixing'
+ if (!(dataset.status in datasetStatusEnum)) {
+ throw new Error(`Unknown dataset status: ${dataset.status}`)
}
+ const expectedStatus = datasetStatusEnum[dataset.status]
+
const statusIndicator = datasetCards[i].querySelector('.govuk-task-list__status')
expect(statusIndicator.textContent.trim()).toContain(expectedStatus)
})
@@ -165,9 +98,9 @@ describe('LPA Overview Page', () => {
const expectedLink = datasetCards[i].querySelector('.govuk-task-list__link').href
if (dataset.status === 'Not submitted') {
- expect(expectedLink).toEqual(`/organisations/mock-org/${dataset.slug}/get-started`)
+ expect(expectedLink).toEqual(`/organisations/${params.organisation.organisation}/${dataset.slug}/get-started`)
} else {
- expect(expectedLink).toEqual(`/organisations/mock-org/${dataset.slug}/overview`)
+ expect(expectedLink).toEqual(`/organisations/${params.organisation.organisation}/${dataset.slug}/overview`)
}
const link = datasetCards[i].querySelector('.govuk-link')
diff --git a/test/unit/middleware/issueDetails.middleware.test.js b/test/unit/middleware/issueDetails.middleware.test.js
index befa4b24..74e9923b 100644
--- a/test/unit/middleware/issueDetails.middleware.test.js
+++ b/test/unit/middleware/issueDetails.middleware.test.js
@@ -269,7 +269,7 @@ describe('issueDetails.middleware.js', () => {
current: true,
href: '/organisations/test-lpa/test-dataset/test-issue-type/test-issue-field/1',
number: 1,
- type: 'item'
+ type: 'number'
}]
},
issueEntitiesCount: 1,
diff --git a/test/utils/mocker.js b/test/utils/mocker.js
new file mode 100644
index 00000000..a8ee79bb
--- /dev/null
+++ b/test/utils/mocker.js
@@ -0,0 +1,19 @@
+import { toJSONSchema } from '@gcornut/valibot-json-schema'
+import { JSONSchemaFaker } from 'json-schema-faker'
+import { date, number, string } from 'valibot'
+
+export default (schema) => {
+ const jsonSchema = toJSONSchema({
+ schema,
+ ignoreUnknownValidation: true,
+ customSchemaConversion: {
+ // Treat set type like an array
+ integer: (schema, converter) => converter(number(schema.value)),
+ url: (schema, converter) => converter(string(schema.value)),
+ iso_date_time: (schema, converter) => converter(date(schema.value))
+ },
+ dateStrategy: 'string'
+ })
+
+ return JSONSchemaFaker.generate(jsonSchema)
+}