From 382520ff49b2ea1603d7b8fb8e6a9e35a51a80fc Mon Sep 17 00:00:00 2001 From: Sam Biram <63285990+sambiramairelogic@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:08:54 +0100 Subject: [PATCH] EES-5003 - Minor fixes (#4993) --- .../.env | 1 + .../.env.production | 1 - .../next-sitemap.config.js | 4 +-- .../src/services/sitemapService.ts | 34 +++++++++---------- .../tests/public/seoMetadataFiles.spec.ts | 5 ++- .../general_public/prod_only/redirects.robot | 2 +- .../tests/general_public/redirects_www.robot | 2 +- 7 files changed, 26 insertions(+), 23 deletions(-) delete mode 100644 src/explore-education-statistics-frontend/.env.production diff --git a/src/explore-education-statistics-frontend/.env b/src/explore-education-statistics-frontend/.env index e97acc35c5b..c952c8c8636 100644 --- a/src/explore-education-statistics-frontend/.env +++ b/src/explore-education-statistics-frontend/.env @@ -5,4 +5,5 @@ PUBLIC_API_DOCS_URL=TODO-GUIDANCE-URL NOTIFICATION_API_BASE_URL=http://localhost:7073/api GA_TRACKING_ID= PUBLIC_URL=http://localhost:3000/ +PROD_PUBLIC_URL=https://explore-education-statistics.service.gov.uk APP_ENV=Local diff --git a/src/explore-education-statistics-frontend/.env.production b/src/explore-education-statistics-frontend/.env.production deleted file mode 100644 index 7b981a86798..00000000000 --- a/src/explore-education-statistics-frontend/.env.production +++ /dev/null @@ -1 +0,0 @@ -PUBLIC_URL=https://explore-education-statistics.service.gov.uk/ diff --git a/src/explore-education-statistics-frontend/next-sitemap.config.js b/src/explore-education-statistics-frontend/next-sitemap.config.js index 697249efc6e..2497341321d 100644 --- a/src/explore-education-statistics-frontend/next-sitemap.config.js +++ b/src/explore-education-statistics-frontend/next-sitemap.config.js @@ -1,6 +1,6 @@ /** @type {import('next-sitemap').IConfig} */ module.exports = { - siteUrl: process.env.PUBLIC_URL, + siteUrl: process.env.PROD_PUBLIC_URL, sitemapSize: 5000, exclude: ['/server-sitemap.xml'], generateRobotsTxt: true, @@ -16,7 +16,7 @@ module.exports = { ], }, ], - additionalSitemaps: [`${process.env.PUBLIC_URL}server-sitemap.xml`], + additionalSitemaps: [`${process.env.PROD_PUBLIC_URL}/server-sitemap.xml`], }, transform: async (config, path) => { if (path === '/') { diff --git a/src/explore-education-statistics-frontend/src/services/sitemapService.ts b/src/explore-education-statistics-frontend/src/services/sitemapService.ts index 077c361d1f8..51385b0af4c 100644 --- a/src/explore-education-statistics-frontend/src/services/sitemapService.ts +++ b/src/explore-education-statistics-frontend/src/services/sitemapService.ts @@ -33,7 +33,7 @@ function buildMethodologyRoutes( methodologies: MethodologySitemapItem[], ): ISitemapField[] { return methodologies.map(methodology => ({ - loc: `${process.env.PUBLIC_URL}methodology/${methodology.slug}`, + loc: `${process.env.PROD_PUBLIC_URL}/methodology/${methodology.slug}`, lastmod: methodology.lastModified, })); } @@ -47,28 +47,28 @@ function buildPublicationRoutes( fields.push( ...[ { - loc: `${process.env.PUBLIC_URL}data-catalogue/${publication.slug}`, + loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/${publication.slug}`, lastmod: publication.lastModified, }, // TODO: Check if data-tables should be included in the sitemap // Add to the data-tables page if not // Add to robots.txt if not // { - // loc: `${process.env.PUBLIC_URL}data-tables/${publication.slug}`, + // loc: `${process.env.PROD_PUBLIC_URL}/data-tables/${publication.slug}`, // lastmod: publication.lastModified, // }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}`, lastmod: publication.lastModified, priority: 0.7, }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}/data-guidance`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}/data-guidance`, lastmod: publication.lastModified, priority: 0.4, }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}/prerelease-access-list`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}/prerelease-access-list`, lastmod: publication.lastModified, priority: 0.2, }, @@ -78,28 +78,28 @@ function buildPublicationRoutes( fields.push( ...[ { - loc: `${process.env.PUBLIC_URL}data-catalogue/${publication.slug}`, + loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/${publication.slug}`, lastmod: publication.lastModified, }, // TODO: Check if data-tables should be included in the sitemap // Add to the data-tables page if not // Add to robots.txt if not // { - // loc: `${process.env.PUBLIC_URL}data-tables/${publication.slug}`, + // loc: `${process.env.PROD_PUBLIC_URL}/data-tables/${publication.slug}`, // lastmod: publication.lastModified, // }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}`, lastmod: publication.lastModified, priority: 0.7, }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}/data-guidance`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}/data-guidance`, lastmod: publication.lastModified, priority: 0.4, }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}/prerelease-access-list`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}/prerelease-access-list`, lastmod: publication.lastModified, priority: 0.2, }, @@ -110,28 +110,28 @@ function buildPublicationRoutes( fields.push( ...[ { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}/${release.slug}`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}/${release.slug}`, lastmod: release.lastModified, }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}/${release.slug}/data-guidance`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}/${release.slug}/data-guidance`, lastmod: release.lastModified, priority: 0.4, }, { - loc: `${process.env.PUBLIC_URL}find-statistics/${publication.slug}/${release.slug}/prerelease-access-list`, + loc: `${process.env.PROD_PUBLIC_URL}/find-statistics/${publication.slug}/${release.slug}/prerelease-access-list`, lastmod: release.lastModified, priority: 0.2, }, { - loc: `${process.env.PUBLIC_URL}data-catalogue/${publication.slug}/${release.slug}`, + loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/${publication.slug}/${release.slug}`, lastmod: release.lastModified, }, // TODO: Check if data-tables should be included in the sitemap // Add to the data-tables page if not // Add to robots.txt if not // { - // loc: `${process.env.PUBLIC_URL}data-tables/${publication.slug}/${release.slug}`, + // loc: `${process.env.PROD_PUBLIC_URL}/data-tables/${publication.slug}/${release.slug}`, // lastmod: release.lastModified, // }, ], @@ -147,7 +147,7 @@ function buildPublicationRoutes( // dataSets: DataSetSitemapItem[], // ): ISitemapField[] { // return dataSets.map(dataSet => ({ -// loc: `${process.env.PUBLIC_URL}data-catalogue/data-set/${dataSet.id}`, +// loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/data-set/${dataSet.id}`, // lastmod: dataSet.lastModified, // })); // } diff --git a/tests/playwright-tests/tests/public/seoMetadataFiles.spec.ts b/tests/playwright-tests/tests/public/seoMetadataFiles.spec.ts index 2ebba525eb8..b9638600c03 100644 --- a/tests/playwright-tests/tests/public/seoMetadataFiles.spec.ts +++ b/tests/playwright-tests/tests/public/seoMetadataFiles.spec.ts @@ -3,7 +3,10 @@ import environment from '@util/env'; const { PUBLIC_URL, PROD_PUBLIC_URL } = environment; -test.describe('SEO Metadata Files', () => { +// Playwright finds two elements with getByText('...sitemal.xml') because the html span they're displayed +// in contains the xml tag, which playwright then treats as another html element. +// TODO: Either resolve this, or re-create these tests in robot if the team prefers +test.describe.skip('SEO Metadata Files', () => { test('An xml sitemap index file can be found at the expected route', async ({ page, }) => { diff --git a/tests/robot-tests/tests/general_public/prod_only/redirects.robot b/tests/robot-tests/tests/general_public/prod_only/redirects.robot index 9b4bcb2e0a0..8dee8e8bd71 100644 --- a/tests/robot-tests/tests/general_public/prod_only/redirects.robot +++ b/tests/robot-tests/tests/general_public/prod_only/redirects.robot @@ -46,7 +46,7 @@ Verify that routes with www are redirected without them user waits until page contains Explore education statistics user checks url equals %{PUBLIC_URL}/ - user navigates to public frontend %{PUBLIC_URL_WITH}/data-catalogue/ + user navigates to public frontend with www %{PUBLIC_URL}/data-catalogue/ user waits until page contains Browse our open data user checks url equals %{PUBLIC_URL}/data-catalogue diff --git a/tests/robot-tests/tests/general_public/redirects_www.robot b/tests/robot-tests/tests/general_public/redirects_www.robot index da5fd74a5ed..5fad5d4334b 100644 --- a/tests/robot-tests/tests/general_public/redirects_www.robot +++ b/tests/robot-tests/tests/general_public/redirects_www.robot @@ -14,6 +14,6 @@ Verify that routes with www are redirected without them user waits until page contains Explore education statistics user checks url equals %{PUBLIC_URL}/ - user navigates to public frontend %{PUBLIC_URL_WITH}/data-catalogue/ + user navigates to public frontend with www %{PUBLIC_URL}/data-catalogue/ user waits until page contains Browse our open data user checks url equals %{PUBLIC_URL}/data-catalogue