Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Aug 29, 2023
1 parent 10de331 commit 0707103
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
managePluginsPagePath,
getTemplateLink,
loadInstalledPluginsPage,
loadPluginsPage, manageInstalledPluginsPagePath
loadPluginsPage,
manageInstalledPluginsPagePath
} = require('../plugin-utils')
const { showHideAllLinkQuery, assertVisible, assertHidden } = require('../../step-by-step-utils')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Handle a plugin update', () => {

waitForApplication(pluginsPage)

cy.get('[data-plugin-group-status="available"]')
cy.get('[data-plugin-group-status="search"]')
.find(`[data-plugin-package-name="${dependencyPlugin}"]`)
.find('button')
.contains('Install')
Expand Down
10 changes: 5 additions & 5 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const syncChanges = require('./sync-changes')
const {
lookupPackageInfo,
getInstalledPackages,
getAvailablePackages,
getAllPackages,
getDependentPackages,
getDependencyPackages,
waitForPackagesCache
Expand Down Expand Up @@ -419,18 +419,18 @@ function buildPluginData (pluginData) {
}

async function prepareForPluginPage (isInstalledPage, search) {
const availablePlugins = await getAvailablePackages()
const allPlugins = await getAllPackages()
const installedPlugins = await getInstalledPackages()

const plugins = isInstalledPage
? installedPlugins
: availablePlugins.filter(plugin => {
: allPlugins.filter(plugin => {
const pluginName = plugin.packageName?.toLowerCase()
return pluginName.indexOf(search.toLowerCase()) >= 0
})

return {
status: isInstalledPage ? 'installed' : 'available',
status: isInstalledPage ? 'installed' : 'search',
plugins: plugins.map(buildPluginData),
found: plugins.length,
updates: installedPlugins.filter(plugin => plugin.installedVersion !== plugin.latestVersion).length
Expand Down Expand Up @@ -510,7 +510,7 @@ async function getPluginsHandler (req, res) {
currentSection: pageName,
links: managementLinks,
isInstalledPage,
isAvailablePage: !isInstalledPage,
isSearchPage: !isInstalledPage,
search,
plugins,
updatesMessage,
Expand Down
11 changes: 6 additions & 5 deletions lib/manage-prototype-handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const {
postPluginsStatusHandler,
postPluginsModeMiddleware,
getPluginsModeHandler,
postPluginsModeHandler, postPluginsHandler
postPluginsModeHandler,
postPluginsHandler
} = require('./manage-prototype-handlers')
const { projectDir } = require('./utils/paths')

Expand Down Expand Up @@ -108,7 +109,7 @@ jest.mock('./plugins/packages', () => {
}
}),
getInstalledPackages: jest.fn().mockResolvedValue([]),
getAvailablePackages: jest.fn().mockResolvedValue([availablePackage]),
getAllPackages: jest.fn().mockResolvedValue([availablePackage]),
getDependentPackages: jest.fn().mockResolvedValue([]),
getDependencyPackages: jest.fn().mockResolvedValue([])
}
Expand Down Expand Up @@ -442,7 +443,7 @@ describe('manage-prototype-handlers', () => {
'views/manage-prototype/plugins.njk',
expect.objectContaining({
currentSection: 'Plugins',
isAvailablePage: false,
isSearchPage: false,
isInstalledPage: true,
plugins: [],
status: 'installed'
Expand All @@ -457,10 +458,10 @@ describe('manage-prototype-handlers', () => {
'views/manage-prototype/plugins.njk',
expect.objectContaining({
currentSection: 'Plugins',
isAvailablePage: true,
isSearchPage: true,
isInstalledPage: false,
plugins: [availablePlugin],
status: 'available'
status: 'search'
})
)
})
Expand Down
42 changes: 26 additions & 16 deletions lib/nunjucks/views/manage-prototype/plugins.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-quarter">
{% if isAvailablePage %}
{% if isSearchPage %}
<div class="sub-nav govuk-!-margin-bottom-6 govuk-prototype-kit-manage-prototype-plugin-subnav--current">
<h2 class="govuk-heading-m">Find plugins</h2>
</div>
Expand All @@ -44,7 +44,7 @@
</div>

<div class="govuk-grid-column-three-quarters">
{% if isAvailablePage %}
{% if isSearchPage %}
<div class="govuk-!-margin-bottom-5">
<div id="search-container">
{{ govukLabel({
Expand Down Expand Up @@ -95,13 +95,21 @@
By {{ plugin.scope }}
</div>
{% endif %}
{% if isInstalledPage %}
{% if plugin.installedVersion %}
<div class="govuk-!-margin-top-3">
v{{ plugin.installedVersion }}
</div>
{% endif %}
</div>
<div class="govuk-grid-column-two-thirds govuk-body">
{% if isSearchPage and plugin.installedVersion %}
<p>
{{ govukTag({
text: "Installed",
classes: "govuk-tag--grey"
}) }}
</p>
{% endif %}
{% if plugin.description %}
<div class="govuk-!-margin-bottom-3">
{{ plugin.description }}
Expand All @@ -115,19 +123,21 @@
attributes: { id: "install-" + plugin.packageName, formaction: plugin.installLink }
}) }}
{% endif %}
{% if plugin.uninstallLink %}
{{ govukButton({
html: 'Uninstall <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "uninstall-" + plugin.packageName, formaction: plugin.uninstallLink }
}) }}
{% endif %}
{% if plugin.updateLink %}
{{ govukButton({
html: 'Update <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "update-" + plugin.packageName, formaction: plugin.updateLink }
}) }}
{% if isInstalledPage %}
{% if plugin.uninstallLink %}
{{ govukButton({
html: 'Uninstall <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "uninstall-" + plugin.packageName, formaction: plugin.uninstallLink }
}) }}
{% endif %}
{% if plugin.updateLink %}
{{ govukButton({
html: 'Update <span class="govuk-visually-hidden"> ' + plugin.name + '</span>',
classes: "govuk-button--secondary",
attributes: { id: "update-" + plugin.packageName, formaction: plugin.updateLink }
}) }}
{% endif %}
{% endif %}
{% if plugin.helpLink %}
<a class=""
Expand Down
5 changes: 2 additions & 3 deletions lib/plugins/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,12 @@ async function getInstalledPackages () {
.reduce(emphasizeBasePlugins, [])
}

async function getAvailablePackages () {
async function getAllPackages () {
if (!Object.keys(packagesCache).length) {
await startPackageTracker()
}
await waitForPackagesCache()
return Object.values(packagesCache)
.filter(({ available, installed }) => available && !installed)
.sort(packageNameSort)
.reduce(emphasizeBasePlugins, [])
}
Expand Down Expand Up @@ -274,7 +273,7 @@ module.exports = {
waitForPackagesCache,
lookupPackageInfo,
getInstalledPackages,
getAvailablePackages,
getAllPackages,
getDependentPackages,
getDependencyPackages
}
14 changes: 9 additions & 5 deletions lib/plugins/packages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const requestHttps = require('../utils/requestHttps')
const {
getInstalledPackages,
setPackagesCache,
getAvailablePackages,
getAllPackages,
getDependentPackages,
getDependencyPackages
} = require('./packages')
Expand Down Expand Up @@ -84,10 +84,14 @@ describe('packages', () => {
})
})

describe('getAvailablePackages', () => {
describe('getAllPackages', () => {
it('', async () => {
const availablePackages = await getAvailablePackages()
expect(availablePackages).toEqual([availableUninstalledPackage])
const allPackages = await getAllPackages()
expect(allPackages).toEqual([
availableInstalledPackage,
availableUninstalledPackage,
unavailableInstalledPackage,
unavailableUninstalledPackage])
})
})

Expand Down Expand Up @@ -239,7 +243,7 @@ describe('packages', () => {
'/dist/jquery.js'
],
meta: {
description: 'Add the jQuery JavaScript library to your prototype'
description: 'jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.'
}
},
versions: [
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/plugin-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ function getProxyPluginConfig (packageName) {
scripts: ['/dist/jquery.js'],
assets: ['/dist'],
meta: {
description: 'Add the jQuery JavaScript library to your prototype'
description: 'jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.'
}
},
'notifications-node-client': {
meta: {
description: 'Send emails and SMS from GOV.UK Notify'
description: 'GOV.UK Notify makes it easy for public sector service teams to send emails, text messages and letters.'
}
}
}
Expand Down

0 comments on commit 0707103

Please sign in to comment.