Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Common templates to the Common templates plugin #1923

Merged
merged 5 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- [#1915: Move Task list template to Task list plugin](https://github.com/alphagov/govuk-prototype-kit/pull/1915)
The Task list template has been moved to the new
[Task list plugin](https://github.com/alphagov/govuk-prototype-kit-task-list)
- [#1923: Move Common templates to Common templates plugin](https://github.com/alphagov/govuk-prototype-kit/pull/1923)
The Common templates have been moved to the new
[Common templates plugin](https://github.com/alphagov/govuk-prototype-kit-common-templates)

## 13.2.4

Expand Down
2 changes: 1 addition & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async function runCreate () {

progressLogger('Installing dependencies')

await npmInstall(installDirectory, [kitDependency, 'govuk-frontend'])
await npmInstall(installDirectory, [kitDependency, 'govuk-frontend', '@govuk-prototype-kit/common-templates'])

let runningWithinCreateScriptFlag = '--running-within-create-script'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// local dependencies
const { waitForApplication, uninstallPlugin } = require('../../utils')

const managePluginsPagePath = '/manage-prototype/plugins'
const manageTemplatesPagePath = '/manage-prototype/templates'
const panelCompleteQuery = '[aria-live="polite"] #panel-complete'

async function loadPluginsPage () {
cy.task('log', 'Visit the manage prototype plugins page')
await waitForApplication(managePluginsPagePath)
}

async function loadTemplatesPage () {
cy.task('log', 'Visit the manage prototype templates page')
await waitForApplication(manageTemplatesPagePath)
}

async function installPluginTests ({ plugin, templates }) {
describe(plugin, () => {
before(() => {
uninstallPlugin(plugin)
cy.wait(4000)
})

beforeEach(() => {
cy.wait(4000)
})

it(`The ${plugin} plugin templates are not available`, () => {
loadTemplatesPage()
cy.get(`[data-plugin-package-name="${plugin}"]`).should('not.exist')
})

it(`Install the ${plugin} plugin`, () => {
loadPluginsPage()
cy.task('log', `Install the ${plugin} plugin`)
cy.get(`button[formaction*="/install?package=${encodeURIComponent(plugin)}"]`)
.contains('Install').click()

cy.get(panelCompleteQuery, { timeout: 20000 })
.should('be.visible')
cy.get('a').contains('Back to plugins').click()

cy.get(`button[formaction*="/uninstall?package=${encodeURIComponent(plugin)}"]`)
.contains('Uninstall')
})

it(`The ${plugin} plugin templates are available`, () => {
loadTemplatesPage()
cy.get(`[data-plugin-package-name="${plugin}"]`).should('exist')
})

templates.forEach(({ name, filename }) => {
it(`View ${name} template`, () => {
loadTemplatesPage()
cy.get(`[data-plugin-package-name="${plugin}"] a`).contains(`View ${name} page`).click()
cy.url().then(url => expect(url).to.contain(filename))
})
})

it(`Uninstall the ${plugin} plugin`, () => {
loadPluginsPage()
cy.task('log', `Uninstall the ${plugin} plugin`)
cy.get(`button[formaction*="/uninstall?package=${encodeURIComponent(plugin)}"]`)
.contains('Uninstall').click()

cy.get(panelCompleteQuery, { timeout: 20000 })
.should('be.visible')
cy.get('a').contains('Back to plugins').click()

cy.get(`button[formaction*="/install?package=${encodeURIComponent(plugin)}"]`)
.contains('Install')
})
})
}

describe('Plugin tests', () => {
installPluginTests({
plugin: '@govuk-prototype-kit/common-templates',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should pin the version to avoid flaky tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

templates: [
{ name: 'Blank GOV.UK', filename: 'blank-govuk.html' },
{ name: 'Blank unbranded', filename: 'blank-unbranded.html' },
{ name: 'Check answers', filename: 'check-answers.html' },
{ name: 'Confirmation', filename: 'confirmation.html' },
{ name: 'Content', filename: 'content.html' },
{ name: 'Mainstream guide', filename: 'mainstream-guide.html' },
{ name: 'Start', filename: 'start.html' },
{ name: 'Question', filename: 'question.html' }
]
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { waitForApplication, uninstallPlugin } = require('../../utils')

const manageTemplatesPagePath = '/manage-prototype/templates'
const panelCompleteQuery = '[aria-live="polite"] #panel-complete'
const plugin = '@govuk-prototype-kit/common-templates'

async function loadTemplatesPage () {
cy.task('log', 'Visit the manage prototype templates page')
await waitForApplication(manageTemplatesPagePath)
}

describe('Install common templates from templates page', () => {
before(() => {
uninstallPlugin(plugin)
cy.wait(4000)
})

it('install', () => {
loadTemplatesPage()
cy.get('a').contains('Install common templates').click()

cy.get(panelCompleteQuery, { timeout: 20000 })
.should('be.visible')

cy.get('a').contains('Back to templates').click()

cy.get(`[data-plugin-package-name="${plugin}"]`).contains('Common Templates')

cy.get('a.govuk-button').should('not.exist')
})
})
42 changes: 0 additions & 42 deletions govuk-prototype-kit.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,5 @@
"importNunjucksMacrosInto": [
"/lib/nunjucks/govuk-prototype-kit/layouts/govuk-branded.html",
"/lib/nunjucks/govuk-prototype-kit/layouts/unbranded.html"
],
"templates": [
{
"name": "Blank GOV.UK page",
"path": "/lib/nunjucks/templates/blank-govuk.html",
"type": "nunjucks"
},
{
"name": "Blank unbranded page",
"path": "/lib/nunjucks/templates/blank-unbranded.html",
"type": "nunjucks"
},
{
"name": "Start page",
"path": "/lib/nunjucks/templates/start.html",
"type": "nunjucks"
},
{
"name": "Question page",
"path": "/lib/nunjucks/templates/question.html",
"type": "nunjucks"
},
{
"name": "Content page",
"path": "/lib/nunjucks/templates/content.html",
"type": "nunjucks"
},
{
"name": "Check answers page",
"path": "/lib/nunjucks/templates/check-answers.html",
"type": "nunjucks"
},
{
"name": "Confirmation page",
"path": "/lib/nunjucks/templates/confirmation.html",
"type": "nunjucks"
},
{
"name": "Mainstream guide page",
"path": "/lib/nunjucks/templates/mainstream-guide.html",
"type": "nunjucks"
}
]
}
1 change: 1 addition & 0 deletions known-plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"plugins": {
"available": [
"govuk-frontend",
"@govuk-prototype-kit/common-templates",
"@govuk-prototype-kit/step-by-step",
"@govuk-prototype-kit/task-list",
"hmrc-frontend",
Expand Down
27 changes: 25 additions & 2 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,22 @@ function getPluginTemplates () {

function getTemplatesHandler (req, res) {
const pageName = 'Templates'
const availableTemplates = getPluginTemplates()

const commonTemplatesPackageName = '@govuk-prototype-kit/common-templates'
let commonTemplatesDetails
if (!availableTemplates.some(plugin => plugin.packageName === commonTemplatesPackageName)) {
commonTemplatesDetails = {
pluginDisplayName: plugins.preparePackageNameForDisplay(commonTemplatesPackageName),
installLink: `${contextPath}/plugins/install?package=${encodeURIComponent(commonTemplatesPackageName)}&returnTo=templates`
}
}

res.render(getManagementView('templates.njk'), {
currentPage: pageName,
links: managementLinks,
availableTemplates: getPluginTemplates()
availableTemplates,
commonTemplatesDetails
})
}

Expand Down Expand Up @@ -506,6 +518,16 @@ async function getPluginsModeHandler (req, res) {

const pageName = `${verb.title} ${chosenPlugin.name}`

const returnLink = req.query.returnTo === 'templates'
? {
href: '/manage-prototype/templates',
text: 'Back to templates'
}
: {
href: '/manage-prototype/plugins',
text: 'Back to plugins'
}

res.render(getManagementView('plugin-install-or-uninstall.njk'), {
currentPage: pageName,
currentUrl: req.originalUrl,
Expand All @@ -514,7 +536,8 @@ async function getPluginsModeHandler (req, res) {
command: getCommand(mode, chosenPlugin),
verb,
isSameOrigin,
csrfToken: req.csrfToken()
csrfToken: req.csrfToken(),
returnLink
})
}

Expand Down
6 changes: 5 additions & 1 deletion lib/manage-prototype-handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ describe('manage-prototype-handlers', () => {
csrfToken,
currentPage: `Install ${pluginDisplayName.name}`,
currentUrl: req.originalUrl,
isSameOrigin: false
isSameOrigin: false,
returnLink: {
href: '/manage-prototype/plugins',
text: 'Back to plugins'
}
})
)
})
Expand Down
10 changes: 0 additions & 10 deletions lib/nunjucks/templates/blank-govuk.html

This file was deleted.

16 changes: 0 additions & 16 deletions lib/nunjucks/templates/blank-unbranded.html

This file was deleted.

Loading