Skip to content

Commit

Permalink
added tests for template
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Aug 9, 2024
1 parent 947aacc commit 7dfd919
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/views/organisations/issueDetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}
{% from "govuk/components/pagination/macro.njk" import govukPagination %}

{% set pageName %}{{organisation.name}} - {{dataset.name}} - Issues (Page {{page_num}} of {{num_entries}}){% endset %}
{% set serviceType = 'Submit'%}

{% if num_entries > 1 %}
{% set pageName %}{{organisation.name}} - {{dataset.name}} - Issues (Page {{page_num}} of {{num_entries}}){% endset %}
{% else %}
{% set pageName %}{{organisation.name}} - {{dataset.name}} - Issues{% endset %}
{%endif%}

{% block content %}
<div class="govuk-grid-row">
Expand Down
137 changes: 137 additions & 0 deletions test/unit/issueDetailsPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { describe, it, expect } from 'vitest'
import nunjucks from 'nunjucks';
import addFilters from '../../src/filters/filters'
import { JSDOM } from 'jsdom';
import { expect } from 'vitest';
import { runGenericPageTests } from './generic-page.js'
import config from '../../config/index.js'

const nunjucksEnv = nunjucks.configure([
'src/views',
'src/views/check',
'src/views/submit',
'node_modules/govuk-frontend/dist/',
'node_modules/@x-govuk/govuk-prototype-components/'
], {
dev: true,
noCache: true,
watch: true
})

const datasetNameMapping = new Map()
addFilters(nunjucksEnv, { datasetNameMapping })

describe('issueDetails.html', () => {
const organisation = {
name: 'Test Organisation'
};

const dataset = {
name: 'Test Dataset'
};

const error_heading = 'Example error heading';
const issue_items = [
{
html: '2 fields are missing values in entry 949',
href: 'todo'
},
{
html: '3 fields are missing values in entry 950',
href: 'todo'
}
];

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: '<p class="govuk-error-message">document-url missing</p>'
},
classes: 'dl-summary-card-list__row--error'
},
{
key: {
text: 'documentation-url'
},
value: {
html: '<p class="govuk-error-message">documentation-url missing</p>'
},
classes: 'dl-summary-card-list__row--error'
}
]
};

const params = {
organisation,
dataset,
error_heading,
issue_items,
entry
};

const html = nunjucks.render('organisations/issueDetails.html', params);
const dom = new JSDOM(html);
const document = dom.window.document;

runGenericPageTests(html, {
pageTitle: 'Test Organisation - Test Dataset - Issues - Submit planning and housing data for England',
serviceName: config.serviceName
})




const multiPageHtml = nunjucks.render('organisations/issueDetails.html', {...params, page_num: 2, num_entries: 3});
runGenericPageTests(multiPageHtml, {
pageTitle: 'Test Organisation - Test Dataset - Issues (Page 2 of 3) - Submit planning and housing data for England',
serviceName: config.serviceName
})

it('Renders the correct headings', () => {
expect(document.querySelector('span.govuk-caption-xl').textContent).toEqual(params.organisation.name)
expect(document.querySelector('h1').textContent).toContain(params.dataset.name)
})


it('should render the error heading', () => {
expect(document.querySelector('.govuk-error-summary__title').textContent).toContain(error_heading);
});

it('should render the issue items', () => {
const issueList = document.querySelector('.govuk-error-summary__list');
const issueItemElements = [...issueList.children]
expect(issueItemElements.length).toBe(issue_items.length);

issueItemElements.forEach((element, index) => {
expect(element.textContent).toContain(issue_items[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')

const cardBody = document.querySelector('.govuk-summary-list');
const entryFields = [...cardBody.children]
expect(entryFields.length).toBe(entry.fields.length);

entryFields.forEach((element, index) => {
expect(element.innerHTML).toContain(entry.fields[index].value.html);
});
});
});

0 comments on commit 7dfd919

Please sign in to comment.