Skip to content

Commit

Permalink
Merge pull request #489 from digital-land/483-update-tests-to-use-moc…
Browse files Browse the repository at this point in the history
…k-data-generated-from-valibot-schemas

483 update tests to use mock data generated from valibot schemas
  • Loading branch information
GeorgeGoodall-GovUk authored Oct 1, 2024
2 parents 21a0b9e + 006a39b commit 43d573b
Show file tree
Hide file tree
Showing 15 changed files with 382 additions and 404 deletions.
152 changes: 152 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@gcornut/valibot-json-schema": "^0.42.0",
"@playwright/test": "^1.39.0",
"@testcontainers/localstack": "^10.7.2",
"@types/node": "^20.8.9",
"@wiremock/wiremock-testcontainers-node": "^0.0.1",
"concurrently": "^8.2.2",
"husky": "^9.0.11",
"jsdom": "^24.1.0",
"json-schema-faker": "^0.5.6",
"nodemon": "^3.0.1",
"pluralize": "^8.0.0",
"standard": "^17.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/routes/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const StartPage = v.object({
* The values of this enum should match values of the 'status' column
* in the query in `performanceDbApi.getLpaOverview()`
*/
const datasetStatusEnum = {
export const datasetStatusEnum = {
Live: 'Live',
'Needs fixing': 'Needs fixing',
Warning: 'Warning',
Expand Down Expand Up @@ -146,14 +146,14 @@ export const OrgIssueDetails = v.strictObject({
})),
items: v.array(v.variant('type', [
v.strictObject({
type: v.literal('item'),
type: v.literal('number'),
number: v.integer(),
href: v.string(),
current: v.boolean()
}),
v.strictObject({
type: v.literal('ellipsis'),
ellipsis: v.boolean(),
ellipsis: v.literal(true),
href: v.string()
})
]))
Expand Down
4 changes: 2 additions & 2 deletions src/views/organisations/issueDetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% set serviceType = 'Submit'%}

{% if issueEntitiesCount > 1 %}
{% set pageName %}{{organisation.name}} - {{dataset.name}} - Issues (Page {{entityNumber}} of {{issueEntitiesCount}}){% endset %}
{% set pageName %}{{organisation.name}} - {{dataset.name}} - Issues (Page {{pageNumber}} of {{issueEntitiesCount}}){% endset %}
{% else %}
{% set pageName %}{{organisation.name}} - {{dataset.name}} - Issues{% endset %}
{%endif%}
Expand Down Expand Up @@ -75,7 +75,7 @@
rows: entry.fields
}) }}

{% if issueEntitiesCount > 1 %}
{% if pagination.items | length > 1 %}
{{ govukPagination(pagination) }}
{% endif %}
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/views/organisations/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ <h2 class="govuk-heading-m">Datasets</h2>
<li class="govuk-task-list__item govuk-task-list__item--with-link">
<div class="govuk-task-list__name-and-hint">
<h2 class="govuk-heading-m">
{% if dataset.endpoint %}
{% if dataset.status == 'Not submitted' %}
<a class="govuk-link govuk-task-list__link"
href="/organisations/{{ organisation.organisation }}/{{dataset.slug}}/overview">
href="/organisations/{{ organisation.organisation }}/{{dataset.slug}}/get-started">
{{dataset.slug | datasetSlugToReadableName}}
</a>
{% else %}
<a class="govuk-link govuk-task-list__link"
href="/organisations/{{ organisation.organisation }}/{{dataset.slug}}/get-started">
href="/organisations/{{ organisation.organisation }}/{{dataset.slug}}/overview">
{{dataset.slug | datasetSlugToReadableName}}
</a>
{% endif %}
</h2>
<div class="govuk-task-list__hint">
{% if dataset.endpoint is null %}
{% if dataset.status == 'Not submitted' %}
<p>Data URL not submitted</p>
{% elif dataset.error %}
{% elif dataset.status == 'Error' %}
<p>{{dataset.error}}</p>
{% elif dataset.issue_count > 0 %}
{% elif dataset.status == 'Needs fixing' > 0 %}
<p>There are {{ dataset.issue_count }} {{ "issue" | pluralise(dataset.issue_count) }} in this dataset</p>
{% else %}
<p>Data URL submitted</p>
Expand Down
31 changes: 11 additions & 20 deletions test/unit/dataset-details.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand Down Expand Up @@ -38,32 +40,21 @@ 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 seed = new Date().getTime()

describe(`dataset details View (seed: ${seed})`, () => {
const params = mock(DatasetDetails, seed)
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(
`<h1 class="govuk-heading-l".*${datasetName.toLowerCase()} details.*</h1>`,
`<h1 class="govuk-heading-l".*${datasetName} details.*</h1>`,
'g'
)

Expand Down
Loading

0 comments on commit 43d573b

Please sign in to comment.