-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2120 from alphagov/view-template-with-default-layout
View templates with default layout
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
cypress/e2e/plugins/1-available-plugins-tests/view-template-with-default-layout.cypress.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// core dependencies | ||
const path = require('path') | ||
|
||
// local dependencies | ||
const { waitForApplication, installPlugin } = require('../../utils') | ||
const { manageTemplatesPagePath, getTemplateLink } = require('../plugin-utils') | ||
|
||
const plugin = '@govuk-prototype-kit/step-by-step' | ||
const pluginPageTemplate = '/templates/step-by-step-navigation.html' | ||
const pluginPageTitle = 'Step by step navigation' | ||
|
||
const defaultLayoutFilePath = path.join('app', 'views', 'layouts', 'main.html') | ||
const backupLayoutComment = '<!-- could not find layouts/main.html or layouts/main.njk in prototype, using backup default template -->' | ||
|
||
const comments = el => cy.wrap( | ||
[...el.childNodes] | ||
.filter(node => node.nodeName === '#comment') | ||
.map(commentNode => '<!--' + commentNode.data + '-->') | ||
) | ||
|
||
describe('view template with default layout', () => { | ||
before(() => { | ||
cy.task('copyFromStarterFiles', { filename: defaultLayoutFilePath }) | ||
installPlugin(plugin, 'latest') | ||
}) | ||
|
||
after(() => { | ||
cy.task('copyFromStarterFiles', { filename: defaultLayoutFilePath }) | ||
}) | ||
|
||
it('deleting default layout does not cause viewing a template to fail to render', () => { | ||
cy.task('log', 'Visit the manage prototype plugins page') | ||
|
||
waitForApplication(manageTemplatesPagePath) | ||
cy.visit(manageTemplatesPagePath) | ||
|
||
cy.task('log', `Preview the ${pluginPageTitle} template`) | ||
|
||
cy.get(`a[href="${getTemplateLink('view', '@govuk-prototype-kit/step-by-step', pluginPageTemplate)}"]`).click() | ||
|
||
cy.document().then(doc => | ||
comments(doc.head).should('not.contain', backupLayoutComment) | ||
) | ||
|
||
cy.task('deleteFile', { filename: path.join(Cypress.env('projectFolder'), defaultLayoutFilePath) }) | ||
|
||
waitForApplication(manageTemplatesPagePath) | ||
cy.visit(manageTemplatesPagePath) | ||
|
||
cy.task('log', `Preview the ${pluginPageTitle} template`) | ||
|
||
cy.get(`a[href="${getTemplateLink('view', '@govuk-prototype-kit/step-by-step', pluginPageTemplate)}"]`).click() | ||
|
||
cy.visit('/', { failOnStatusCode: false }) | ||
cy.get('body').should('not.contains.text', 'Error: template not found') | ||
|
||
cy.document().then(doc => { | ||
cy.log('head content', doc.head.innerHTML) | ||
comments(doc.head).should('contain', backupLayoutComment) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters