Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Oct 4, 2023
1 parent 711c13e commit 0b8b3e6
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
loadTemplatesPage,
managePluginsPagePath,
performPluginAction,
initiatePluginAction
initiatePluginAction, provePluginInstalled, provePluginTemplatesInstalled, provePluginTemplatesUninstalled
} = require('../plugin-utils')

const panelCompleteQuery = '[aria-live="polite"] #panel-complete'
Expand All @@ -21,7 +21,7 @@ describe('Install and uninstall Local Plugin via UI Test', async () => {
it(`The ${dependentPlugin} plugin will be installed`, () => {
log(`The ${dependentPlugin} plugin templates are not available`)
loadTemplatesPage()
cy.get(`[data-plugin-package-name="${dependentPlugin}"]`).should('not.exist')
provePluginTemplatesUninstalled(dependentPlugin)

// ------------------------

Expand All @@ -34,15 +34,13 @@ describe('Install and uninstall Local Plugin via UI Test', async () => {
.should('be.visible')
cy.get('a').contains('Back to plugins').click()

cy.get('#installed-plugins-link').click()

cy.get(`[data-plugin-package-name="${dependentPlugin}"] button`).contains('Uninstall')
provePluginInstalled(dependentPlugin, dependentPluginName)

// ------------------------

log(`The ${dependentPlugin} plugin templates are available`)
cy.get('a').contains('Templates').click()
cy.get(`[data-plugin-package-name="${dependentPlugin}"]`).should('exist')
provePluginTemplatesInstalled(dependentPlugin)

// ------------------------

Expand All @@ -55,13 +53,13 @@ describe('Install and uninstall Local Plugin via UI Test', async () => {

log(`The ${dependentPlugin} plugin templates are not available`)
cy.get('a').contains('Templates').click()
cy.get(`[data-plugin-package-name="${dependentPlugin}"]`).should('not.exist')
provePluginTemplatesUninstalled(dependentPlugin)
})

it(`The ${dependentPlugin} plugin and ${dependencyPlugin} will be installed`, () => {
log(`The ${dependentPlugin} plugin templates are not available`)
loadTemplatesPage()
cy.get(`[data-plugin-package-name="${dependentPlugin}"]`).should('not.exist')
provePluginTemplatesUninstalled(dependentPlugin)

// ------------------------

Expand All @@ -85,7 +83,7 @@ describe('Install and uninstall Local Plugin via UI Test', async () => {

log(`The ${dependentPlugin} plugin templates are available`)
cy.get('a').contains('Templates').click()
cy.get(`[data-plugin-package-name="${dependentPlugin}"]`).should('exist')
provePluginTemplatesInstalled(dependentPlugin)

// ------------------------

Expand All @@ -101,6 +99,6 @@ describe('Install and uninstall Local Plugin via UI Test', async () => {

log(`The ${dependentPlugin} plugin templates are not available`)
cy.get('a').contains('Templates').click()
cy.get(`[data-plugin-package-name="${dependentPlugin}"]`).should('not.exist')
provePluginTemplatesUninstalled(dependentPlugin)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const {
loadTemplatesPage,
loadPluginsPage,
manageTemplatesPagePath,
manageInstalledPluginsPagePath
provePluginInstalled,
provePluginUninstalled,
performPluginAction,
initiatePluginAction, provePluginTemplatesUninstalled, provePluginTemplatesInstalled
} = require('../plugin-utils')

const panelCompleteQuery = '[aria-live="polite"] #panel-complete'
Expand All @@ -18,7 +21,7 @@ async function installPluginTests ({ plugin, templates, version }) {
log(`The ${plugin} plugin templates are not available`)
uninstallPlugin(plugin)
loadTemplatesPage()
cy.get(`[data-plugin-package-name="${plugin}"]`).should('not.exist')
provePluginTemplatesUninstalled(plugin)

// ------------------------

Expand All @@ -30,22 +33,23 @@ async function installPluginTests ({ plugin, templates, version }) {
cy.get('#plugin-action-button').click()
} else {
loadPluginsPage()
provePluginUninstalled(plugin)
log(`Install the ${plugin} plugin`)
cy.get(`[data-plugin-package-name="${plugin}"] button`).contains('Install').click()
performPluginAction('install', plugin)
}

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

cy.get('#installed-plugins-link').click()
cy.get(`[data-plugin-package-name="${plugin}"] button`).contains('Uninstall')
provePluginInstalled(plugin)

// ------------------------

log(`The ${plugin} plugin templates are available`)
cy.get('a').contains('Templates').click()
cy.get(`[data-plugin-package-name="${plugin}"]`).should('exist')

provePluginTemplatesInstalled(plugin)

// ------------------------

Expand All @@ -59,15 +63,11 @@ async function installPluginTests ({ plugin, templates, version }) {
// ------------------------

log(`Uninstall the ${plugin} plugin`)
cy.visit(manageInstalledPluginsPagePath)

cy.get(`[data-plugin-package-name="${plugin}"] button`).contains('Uninstall').click()
cy.visit(managePluginsPagePath)

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

cy.get(`[data-plugin-package-name="${plugin}"] button`).contains('Install')
provePluginUninstalled(plugin)
})
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { waitForApplication, uninstallPlugin, restoreStarterFiles } = require('../../utils')
const { provePluginTemplatesInstalled } = require('../plugin-utils')

const manageTemplatesPagePath = '/manage-prototype/templates'
const panelCompleteQuery = '[aria-live="polite"] #panel-complete'
Expand All @@ -25,7 +26,7 @@ describe('Install common templates from templates page', () => {

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

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

cy.get('a.govuk-button').should('not.exist')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const { replaceInFile, waitForApplication, restoreStarterFiles, log } = require('../../utils')
const {
replaceInFile,
waitForApplication,
restoreStarterFiles,
log
} = require('../../utils')
const path = require('path')
const {
provePluginInstalled,
provePluginUninstalled
} = require('../plugin-utils')
const plugin = '@govuk-prototype-kit/task-list'
const pluginVersion = '1.1.1'
const originalText = '"dependencies": {'
Expand All @@ -18,11 +27,7 @@ describe('Handle a plugin installation mismatch', () => {

log(`Make sure ${plugin} is displayed as not installed`)
cy.visit(pluginsPage)

cy.get(`[data-plugin-package-name="${plugin}"]`)
.scrollIntoView()
.find('button')
.contains('Install')
provePluginUninstalled(plugin)

log('Force the plugins to be installed with an npm install')
cy.exec(`cd ${Cypress.env('projectFolder')} && npm install`)
Expand All @@ -31,10 +36,6 @@ describe('Handle a plugin installation mismatch', () => {
waitForApplication()
cy.visit(pluginsPage)

cy.get('#installed-plugins-link').click()
cy.get(`[data-plugin-package-name="${plugin}"]`)
.scrollIntoView()
.find('button')
.contains('Uninstall')
provePluginInstalled(plugin)
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { installPlugin, restoreStarterFiles, uninstallPlugin, waitForApplication } from '../../utils'
import path from 'path'
import {
initiatePluginAction,
performPluginAction,
provePluginInstalled,
provePluginUninstalled
} from '../plugin-utils'

const plugin = '@govuk-prototype-kit/common-templates'
const pluginVersion = '1.1.1'
Expand Down Expand Up @@ -30,39 +36,18 @@ describe('Handle a plugin update', () => {

waitForApplication(pluginsPage)

cy.get('[data-plugin-group-status="search"]')
.find(`[data-plugin-package-name="${dependencyPlugin}"]`)
.find('button')
.contains('Install')

cy.get('#installed-plugins-link').click()

cy.get('[data-plugin-group-status="installed"]')
.find(`[data-plugin-package-name="${plugin}"]`)
.find('button')
.contains('Update')
.click()
provePluginUninstalled(dependencyPlugin)
initiatePluginAction('update', plugin)

cy.get('#plugin-action-confirmation')
.find('ul')
.contains(dependencyPluginName)

cy.get('#plugin-action-button').click()

cy.get('#panel-complete', { timeout: 20000 })
.should('be.visible')
.contains('Update complete')

cy.get('#instructions-complete a')
.contains('Back to plugins')
.click()

cy.get('#installed-plugins-link').click()

cy.get('[data-plugin-group-status="installed"]')
.find(`[data-plugin-package-name="${dependencyPlugin}"]`)
performPluginAction('update', plugin)

cy.get('[data-plugin-group-status="installed"]')
.find(`[data-plugin-package-name="${plugin}"]`)
provePluginInstalled(plugin)
provePluginInstalled(dependencyPlugin, dependencyPluginName)
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const { managePluginsPagePath, performPluginAction } = require('../plugin-utils')
const {
managePluginsPagePath,
performPluginAction,
provePluginInstalled,
provePluginUninstalled,
initiatePluginAction
} = require('../plugin-utils')
const { uninstallPlugin, restoreStarterFiles } = require('../../utils')

const plugin = 'govuk-frontend'
Expand All @@ -21,9 +27,7 @@ describe('Manage prototype pages without govuk-frontend', () => {
performPluginAction('uninstall', plugin, pluginName)

cy.task('log', 'Make sure govuk-frontend is uninstalled')
cy.get(`[data-plugin-package-name="${plugin}"]`)
.find('button')
.contains('Install')
provePluginUninstalled(plugin)

cy.task('log', 'Test home page')
cy.get('a').contains('Home').click()
Expand All @@ -39,19 +43,12 @@ describe('Manage prototype pages without govuk-frontend', () => {

cy.task('log', `Install the ${plugin} plugin`)

cy.get(`[data-plugin-package-name="${plugin}"]`)
.scrollIntoView()
.find('button')
.contains('Install')
.click()
initiatePluginAction('install', plugin, pluginName)

performPluginAction('install', plugin, pluginName)

cy.get('#installed-plugins-link').click()

cy.task('log', 'Make sure govuk-frontend is installed')
cy.get(`[data-plugin-package-name="${plugin}"]`)
.find('button')
.contains('Uninstall')

provePluginInstalled(plugin, pluginName)
})
})
65 changes: 59 additions & 6 deletions cypress/e2e/plugins/plugin-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ async function loadTemplatesPage () {
await waitForApplication(manageTemplatesPagePath)
}

function provePluginTemplatesInstalled (plugin) {
cy.get(`[data-plugin-package-name="${plugin}"]`).should('exist')
}

function provePluginTemplatesUninstalled (plugin) {
cy.get(`[data-plugin-package-name="${plugin}"]`).should('not.exist')
}

function initiatePluginAction (action, plugin, pluginName) {
if (pluginName) {
cy.get(`[data-plugin-package-name="${plugin}"]`)
.scrollIntoView()
.find('a')
.contains(pluginName)
}

cy.get(`[data-plugin-package-name="${plugin}"]`)
.scrollIntoView()
.find('a')
.contains(pluginName)
.click()

cy.get('button')
Expand All @@ -45,18 +59,53 @@ function initiatePluginAction (action, plugin, pluginName) {
performPluginAction(action, plugin, pluginName)
}

function provePluginInstalled (plugin, pluginName) {
if (pluginName) {
cy.get(`[data-plugin-package-name="${plugin}"]`)
.scrollIntoView()
.find('a')
.contains(pluginName)
}

cy.get(`[data-plugin-package-name="${plugin}"] strong.govuk-tag`)
.contains('Installed')

cy.get('#installed-plugins-link').click()

cy.get(`[data-plugin-package-name="${plugin}"]`)
.should('exist')
}

function provePluginUninstalled (plugin, pluginName) {
if (pluginName) {
cy.get(`[data-plugin-package-name="${plugin}"]`)
.scrollIntoView()
.find('a')
.contains(pluginName)
}

cy.get(`[data-plugin-package-name="${plugin}"] strong.govuk-tag`)
.should('not.exist')

cy.get('#installed-plugins-link').click()

cy.get(`[data-plugin-package-name="${plugin}"]`)
.should('not.exist')
}

function performPluginAction (action, plugin, pluginName) {
cy.task('log', `The ${plugin} plugin should be displayed`)
cy.get('h2')
.contains(pluginName)

if (pluginName) {
cy.get('h2')
.contains(pluginName)
}

const processingText = `${action === 'update' ? 'Updat' : action}ing ...`

if (Cypress.env('skipPluginActionInterimStep') !== 'true') {
cy.get(panelCompleteQuery, { timeout: 20000 })
.should('not.be.visible')
cy.get(panelCompleteQuery)
.should('not.be.visible')
cy.get(panelErrorQuery)
.should('not.be.visible')
cy.get(panelProcessingQuery)
Expand Down Expand Up @@ -89,7 +138,7 @@ function failAction (action) {
cy.get('#plugin-action-button').click()

if (Cypress.env('skipPluginActionInterimStep') !== 'true') {
cy.get(panelCompleteQuery)
cy.get(panelCompleteQuery, { timeout: 20000 })
.should('not.be.visible')
cy.get(panelErrorQuery)
.should('not.be.visible')
Expand Down Expand Up @@ -121,5 +170,9 @@ module.exports = {
getTemplateLink,
initiatePluginAction,
performPluginAction,
provePluginInstalled,
provePluginUninstalled,
provePluginTemplatesInstalled,
provePluginTemplatesUninstalled,
failAction
}
Loading

0 comments on commit 0b8b3e6

Please sign in to comment.