From e742dabe048a5e2df5f1a51b7e8e457b3e79c503 Mon Sep 17 00:00:00 2001 From: Nicholas Tsim Date: Wed, 24 Apr 2024 17:10:11 +0100 Subject: [PATCH 1/2] EES-5085 Fix too many dashes appearing in updated publication slugs --- .../NamingUtilTests.cs | 45 +++++++++---------- .../utils/__tests__/slugFromTitle.test.tsx | 6 +++ .../src/utils/slugFromTitle.ts | 6 +-- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/GovUk.Education.ExploreEducationStatistics.Content.Model.Tests/NamingUtilTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Content.Model.Tests/NamingUtilTests.cs index ef0b6782640..d14d8a736c8 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Content.Model.Tests/NamingUtilTests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Content.Model.Tests/NamingUtilTests.cs @@ -1,37 +1,36 @@ using Xunit; using static GovUk.Education.ExploreEducationStatistics.Content.Model.NamingUtils; -namespace GovUk.Education.ExploreEducationStatistics.Content.Model.Tests +namespace GovUk.Education.ExploreEducationStatistics.Content.Model.Tests; + +public abstract class NamingUtilTests { - public class NamingUtilTests + public class SlugFromTitleTests { - [Fact] - public void ReleaseSlugFromTitle_CalendarYear() + public void CalendarYearTitle() { - var slug = SlugFromTitle("calendar year 2019"); - Assert.Equal("calendar-year-2019", slug); + Assert.Equal("calendar-year-2019", SlugFromTitle("calendar year 2019")); } - + [Fact] - public void ReleaseSlugFromTitle_NonCalendarYear() + public void NonCalendarYearTitle() { - var slug = SlugFromTitle("tax year 2019/20"); - Assert.Equal("tax-year-2019-20", slug); + Assert.Equal("tax-year-2019-20", SlugFromTitle("tax year 2019/20")); } - - - [Fact] - public void GenerateSlugFromTitle() + + [Theory] + [InlineData("title", "title")] + [InlineData("TITLE", "title")] + [InlineData("A sentence with spaces", "a-sentence-with-spaces")] + [InlineData("A - sentence - with - - dashes - and -- spaces", "a-sentence-with-dashes-and-spaces")] + [InlineData("A sentence with !@£('\\) non alpha numeric characters", "a-sentence-with-non-alpha-numeric-characters")] + [InlineData("A sentence with non alpha numeric characters at the end !@£('\\)", "a-sentence-with-non-alpha-numeric-characters-at-the-end")] + [InlineData("a sentence with big spaces ", "a-sentence-with-big-spaces")] + [InlineData("a sentence with numbers 1 2 3 and 4", "a-sentence-with-numbers-1-2-3-and-4")] + public void EdgeCaseTitles(string title, string expectedSlug) { - Assert.Equal("title", SlugFromTitle("title")); - Assert.Equal("title", SlugFromTitle("TITLE")); - Assert.Equal("a-sentence-with-spaces",SlugFromTitle("A sentence with spaces")); - Assert.Equal("a-sentence-with-non-alpha-numeric-characters",SlugFromTitle("A sentence with !@£('\\) non alpha numeric characters")); - Assert.Equal("a-sentence-with-non-alpha-numeric-characters-at-the-end", SlugFromTitle("A sentence with non alpha numeric characters at the end !@£('\\)")); - Assert.Equal("a-sentence-with-big-spaces", SlugFromTitle("a sentence with big spaces ")); - Assert.Equal("a-sentence-with-numbers-1-2-3-and-4", SlugFromTitle("a sentence with numbers 1 2 3 and 4")); + Assert.Equal(expectedSlug, SlugFromTitle(title)); } - } -} \ No newline at end of file +} diff --git a/src/explore-education-statistics-common/src/utils/__tests__/slugFromTitle.test.tsx b/src/explore-education-statistics-common/src/utils/__tests__/slugFromTitle.test.tsx index e5f7dcdf074..e068aeab298 100644 --- a/src/explore-education-statistics-common/src/utils/__tests__/slugFromTitle.test.tsx +++ b/src/explore-education-statistics-common/src/utils/__tests__/slugFromTitle.test.tsx @@ -23,6 +23,12 @@ describe('slugFromTitle', () => { ); }); + test('converts a sentence with dashes and spaces', () => { + expect( + slugFromTitle('A - sentence - with - - dashes - and -- spaces'), + ).toEqual('a-sentence-with-dashes-and-spaces'); + }); + test('converts a sentence with non alphanumeric characters', () => { expect( slugFromTitle("A sentence with !@£('\\) non alpha numeric characters"), diff --git a/src/explore-education-statistics-common/src/utils/slugFromTitle.ts b/src/explore-education-statistics-common/src/utils/slugFromTitle.ts index c07c6d457a3..f34e9c57b29 100644 --- a/src/explore-education-statistics-common/src/utils/slugFromTitle.ts +++ b/src/explore-education-statistics-common/src/utils/slugFromTitle.ts @@ -4,9 +4,5 @@ * Duplicates NamingUtils#SlugFromTitle in the backend */ export default function slugFromTitle(title: string) { - return title - .replace(/[^\w-]+/g, ' ') - .trim() - .toLowerCase() - .replace(/\s+/g, '-'); + return title.replace(/\W+/g, ' ').trim().toLowerCase().replace(/\s+/g, '-'); } From 58f77e1571ab976094007bdfea13baccfc7cbd1c Mon Sep 17 00:00:00 2001 From: Nicholas Tsim Date: Wed, 24 Apr 2024 17:12:32 +0100 Subject: [PATCH 2/2] EES-5085 Fix UI test failures due to duplicated publication titles This failure only occurs when there are duplicated publication titles in the same test run, which typically only occurs when running all the tests in parallel. --- .../bau/publish_methodology_publication_update.robot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/robot-tests/tests/admin_and_public_2/bau/publish_methodology_publication_update.robot b/tests/robot-tests/tests/admin_and_public_2/bau/publish_methodology_publication_update.robot index 57cafa5c36e..d96abed9a40 100644 --- a/tests/robot-tests/tests/admin_and_public_2/bau/publish_methodology_publication_update.robot +++ b/tests/robot-tests/tests/admin_and_public_2/bau/publish_methodology_publication_update.robot @@ -12,10 +12,10 @@ Force Tags Admin Local Dev AltersData *** Variables *** -${PUBLICATION_NAME}= UI tests-publish publication update %{RUN_IDENTIFIER} -${PUBLIC_METHODOLOGY_URL_ENDING}= /methodology/ui-tests-publish-publication-update-%{RUN_IDENTIFIER} +${PUBLICATION_NAME}= UI tests - publish methodology publication update %{RUN_IDENTIFIER} +${PUBLIC_METHODOLOGY_URL_ENDING}= /methodology/ui-tests-publish-methodology-publication-update-%{RUN_IDENTIFIER} ${PUBLICATION_NAME_UPDATED}= ${PUBLICATION_NAME} updated -${PUBLIC_PUBLICATION_URL_ENDING}= /find-statistics/ui-tests-publish-publication-update-%{RUN_IDENTIFIER} +${PUBLIC_PUBLICATION_URL_ENDING}= /find-statistics/ui-tests-publish-methodology-publication-update-%{RUN_IDENTIFIER} ${EXPECTED_PUBLIC_PUBLICATION_URL_ENDING}= %{PUBLIC_URL}${PUBLIC_PUBLICATION_URL_ENDING} ${RELEASE_NAME}= Academic year Q1 ${ACADEMIC_YEAR}= /2046-47