From 049c8fd59b3ff4432a6c7881c144f609f7aa532a Mon Sep 17 00:00:00 2001 From: Sam C <156680559+sam-c-dfe@users.noreply.github.com> Date: Wed, 7 Aug 2024 09:45:25 +0100 Subject: [PATCH] EYQB-485: Updated to add in the new advice pages for L6 (#294) * EYQB-485: Updated to add in the new advice pages for L6 * Fixed config * Added additional e2e tests * Updated the urls to check * Fixed broken unit test --- .../Constants/AdvicePages.cs | 10 +++ .../Renderers/GovUk/Heading4Renderer.cs | 2 +- .../Content/MockContentfulService.cs | 12 +++ .../Controllers/AdviceController.cs | 12 +++ .../Controllers/QuestionsController.cs | 17 +++- .../Views/Shared/Partials/RatioRow.cshtml | 2 +- .../.pa11yci-ubuntu.js | 4 +- .../cypress/e2e/journey/journey-spec.cy.js | 82 +++++++++++++++++++ .../cypress/e2e/pages/advice-spec.cy.js | 14 ++++ .../cypress/e2e/shared/urls-to-check.js | 18 +++- .../Controllers/QuestionsControllerTests.cs | 60 ++++++++++++++ .../Mocks/MockContentfulServiceTests.cs | 34 +++++++- .../Renderers/Heading4RendererTests.cs | 2 +- 13 files changed, 257 insertions(+), 12 deletions(-) diff --git a/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs b/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs index 41b42d45..b00e7b1c 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs @@ -36,4 +36,14 @@ public static class AdvicePages /// Entry ID for the "Qualification Level 7" advice page /// public const string QualificationLevel7 = "1bGiyvwsJZPd14dwrVtWCM"; + + /// + /// Entry ID for the "Level 6 qualification pre-2014" advice page. + /// + public const string Level6QualificationPre2014 = "2TT7k2J5KUNmUQ3f8A56tw"; + + /// + /// Entry ID for the "Level 6 qualification post-2014" advice page. + /// + public const string Level6QualificationPost2014 = "5aoy3C3jIEKdMo8fauvyvk"; } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Renderers/GovUk/Heading4Renderer.cs b/src/Dfe.EarlyYearsQualification.Content/Renderers/GovUk/Heading4Renderer.cs index 60dd6769..b50bb130 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Renderers/GovUk/Heading4Renderer.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Renderers/GovUk/Heading4Renderer.cs @@ -10,7 +10,7 @@ public Task RenderAsync(IContent content) { var heading = content as Heading4; var headingText = heading!.Content[0] as Text; - return Task.FromResult($"

{headingText!.Value}

"); + return Task.FromResult($"

{headingText!.Value}

"); } public bool SupportsContent(IContent content) diff --git a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs index 5b545fc6..931adb1e 100644 --- a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs +++ b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs @@ -63,6 +63,14 @@ await Task.FromResult(CreateAdvicePage("Qualification at Level 7", body, WhatLevelIsTheQualificationPath)), + + AdvicePages.Level6QualificationPre2014 => + await Task.FromResult(CreateAdvicePage("Level 6 qualification pre 2014", + body, WhatLevelIsTheQualificationPath)), + + AdvicePages.Level6QualificationPost2014 => + await Task.FromResult(CreateAdvicePage("Level 6 qualification post 2014", + body, WhatLevelIsTheQualificationPath)), _ => null }; } @@ -497,6 +505,10 @@ private static RadioQuestionPage CreateWhatLevelIsTheQualificationPage() Label = "Level 3", Value = "3" }, new() + { + Label = "Level 6", Value = "6" + }, + new() { Label = "Level 7", Value = "7" } diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs index 2fe3fef0..0c417338 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs @@ -47,6 +47,18 @@ public async Task QualificationNotOnTheList() { return await GetView(AdvicePages.QualificationNotOnTheList); } + + [HttpGet("level-6-qualification-pre-2014")] + public async Task Level6QualificationPre2014() + { + return await GetView(AdvicePages.Level6QualificationPre2014); + } + + [HttpGet("level-6-qualification-post-2014")] + public async Task Level6QualificationPost2014() + { + return await GetView(AdvicePages.Level6QualificationPost2014); + } [HttpGet("qualification-level-7")] public async Task QualificationLevel7() diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs index 76625408..86d2d477 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs @@ -133,11 +133,13 @@ public async Task WhatLevelIsTheQualification(RadioQuestionModel } userJourneyCookieService.SetLevelOfQualification(model.Option!); - + return model.Option switch { "2" when WasAwardedBetweenSeptember2014AndAugust2019() => RedirectToAction("QualificationsStartedBetweenSept2014AndAug2019", "Advice"), + "6" => + RedirectToAction(WasStartedBeforeSeptember2014() ? "Level6QualificationPre2014" : "Level6QualificationPost2014", "Advice"), "7" => RedirectToAction(nameof(AdviceController.QualificationLevel7), "Advice"), _ => RedirectToAction(nameof(this.WhatIsTheAwardingOrganisation)) }; @@ -189,6 +191,19 @@ public async Task WhatIsTheAwardingOrganisation(DropdownQuestionM return RedirectToAction("Get", "QualificationDetails"); } + private bool WasStartedBeforeSeptember2014() + { + var (startDateMonth, startDateYear) = userJourneyCookieService.GetWhenWasQualificationAwarded(); + + if (startDateMonth is null || startDateYear is null) + { + return false; + } + + var date = new DateOnly(startDateYear.Value, startDateMonth.Value, 1); + return date < new DateOnly(2014, 9, 1); + } + private bool WasAwardedBetweenSeptember2014AndAugust2019() { var (startDateMonth, startDateYear) = userJourneyCookieService.GetWhenWasQualificationAwarded(); diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/Shared/Partials/RatioRow.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/Shared/Partials/RatioRow.cshtml index 014fc672..61f3c099 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/Shared/Partials/RatioRow.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/Shared/Partials/RatioRow.cshtml @@ -3,7 +3,7 @@
- @Model.LevelText +

@Model.LevelText

diff --git a/tests/Dfe.EarlyYearsQualification.AccessibilityTests/.pa11yci-ubuntu.js b/tests/Dfe.EarlyYearsQualification.AccessibilityTests/.pa11yci-ubuntu.js index 10acca09..8b93ccf8 100644 --- a/tests/Dfe.EarlyYearsQualification.AccessibilityTests/.pa11yci-ubuntu.js +++ b/tests/Dfe.EarlyYearsQualification.AccessibilityTests/.pa11yci-ubuntu.js @@ -26,7 +26,9 @@ var config = { "http://localhost:5000/advice/qualifications-achieved-in-wales", "http://localhost:5000/advice/qualifications-achieved-in-northern-ireland", "http://localhost:5000/advice/qualification-not-on-the-list", - "http://localhost:5000/advice/qualification-level-7" + "http://localhost:5000/advice/qualification-level-7", + "http://localhost:5000/advice/level-6-qualification-pre-2014", + "http://localhost:5000/advice/level-6-qualification-post-2014" ] }; diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/journey/journey-spec.cy.js b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/journey/journey-spec.cy.js index 2739094f..6fba4e8b 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/journey/journey-spec.cy.js +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/journey/journey-spec.cy.js @@ -203,6 +203,88 @@ describe('A spec used to test the various routes through the journey', () => { }) }) + it("Selecting qualification level 6 started before 1 Sept 2014 should navigate to the level 6 pre 2014 advice page", () => { + // home page + cy.get('.govuk-button--start').click(); + + // where-was-the-qualification-awarded page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/where-was-the-qualification-awarded'); + }) + + cy.get('#england').click(); + cy.get('button[id="question-submit"]').click(); + + // when-was-the-qualification-started page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/when-was-the-qualification-started'); + }) + + cy.get('#date-started-month').type("8"); + cy.get('#date-started-year').type("2014"); + cy.get('button[id="question-submit"]').click(); + + // what-level-is-the-qualification page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/what-level-is-the-qualification'); + }) + cy.get('#6').click(); + cy.get('button[id="question-submit"]').click(); + + // level 6 pre 2014 advice page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/advice/level-6-qualification-pre-2014'); + }) + + // check back button goes back to the what level is the qualification page + cy.get('#back-button').click(); + + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/what-level-is-the-qualification'); + }) + }) + + it("Selecting qualification level 6 started after 1 Sept 2014 should navigate to the level 6 post 2014 advice page", () => { + // home page + cy.get('.govuk-button--start').click(); + + // where-was-the-qualification-awarded page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/where-was-the-qualification-awarded'); + }) + + cy.get('#england').click(); + cy.get('button[id="question-submit"]').click(); + + // when-was-the-qualification-started page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/when-was-the-qualification-started'); + }) + + cy.get('#date-started-month').type("8"); + cy.get('#date-started-year').type("2015"); + cy.get('button[id="question-submit"]').click(); + + // what-level-is-the-qualification page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/what-level-is-the-qualification'); + }) + cy.get('#6').click(); + cy.get('button[id="question-submit"]').click(); + + // level 6 post 2014 advice page + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/advice/level-6-qualification-post-2014'); + }) + + // check back button goes back to the what level is the qualification page + cy.get('#back-button').click(); + + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/questions/what-level-is-the-qualification'); + }) + }) + it("Selecting qualification level 7 should navigate to the level 7 advice page", () => { // home page cy.get('.govuk-button--start').click(); diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js index cb0a6164..e19e882c 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js @@ -38,6 +38,20 @@ describe("A spec that tests advice pages", () => { cy.get("#advice-page-heading").should("contain.text", "Qualifications achieved in Northern Ireland"); cy.get("#advice-page-body").should("contain.text", "Test Advice Page Body"); }) + + it("Checks the Level 6 qualification pre 2014 details are on the page", () => { + cy.visit("/advice/level-6-qualification-pre-2014"); + + cy.get("#advice-page-heading").should("contain.text", "Level 6 qualification pre 2014"); + cy.get("#advice-page-body").should("contain.text", "Test Advice Page Body"); + }) + + it("Checks the Level 6 qualification post 2014 details are on the page", () => { + cy.visit("/advice/level-6-qualification-post-2014"); + + cy.get("#advice-page-heading").should("contain.text", "Level 6 qualification post 2014"); + cy.get("#advice-page-body").should("contain.text", "Test Advice Page Body"); + }) it("Checks the Qualifications level 7 details are on the page", () => { cy.visit("/advice/qualification-level-7"); diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/shared/urls-to-check.js b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/shared/urls-to-check.js index c9c96207..ce51a27c 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/shared/urls-to-check.js +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/shared/urls-to-check.js @@ -1,8 +1,6 @@ export const pages = [ "/", "/accessibility-statement", - "/advice/qualification-outside-the-united-kingdom", - "/advice/level-2-qualifications-started-between-1-sept-2014-and-31-aug-2019", "/cookies", "/questions/where-was-the-qualification-awarded", "/questions/when-was-the-qualification-started", @@ -11,7 +9,16 @@ export const pages = [ "/qualifications", "/confirm-qualification/EYQ-240", "/qualifications/qualification-details/EYQ-240", - "/qualifications/check-additional-questions/EYQ-240" + "/qualifications/check-additional-questions/EYQ-240", + "/advice/qualification-outside-the-united-kingdom", + "/advice/level-2-qualifications-started-between-1-sept-2014-and-31-aug-2019", + "/advice/qualifications-achieved-in-scotland", + "/advice/qualifications-achieved-in-wales", + "/advice/qualifications-achieved-in-northern-ireland", + "/advice/qualification-not-on-the-list", + "/advice/qualification-level-7", + "/advice/level-6-qualification-pre-2014", + "/advice/level-6-qualification-post-2014" ]; export const pagesWithForms = [ @@ -28,11 +35,14 @@ export const pagesWithForms = [ export const pagesWithoutForms = [ "/", "/accessibility-statement", + "/qualifications/qualification-details/EYQ-240", "/advice/qualification-outside-the-united-kingdom", "/advice/level-2-qualifications-started-between-1-sept-2014-and-31-aug-2019", - "/qualifications/qualification-details/EYQ-240", "/advice/qualifications-achieved-in-scotland", "/advice/qualifications-achieved-in-wales", "/advice/qualifications-achieved-in-northern-ireland", "/advice/qualification-not-on-the-list", + "/advice/qualification-level-7", + "/advice/level-6-qualification-pre-2014", + "/advice/level-6-qualification-post-2014" ] \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs index 3bfaf0a7..288e6184 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs @@ -679,6 +679,66 @@ public async Task Post_WhatLevelIsTheQualification_Level2WithInDate_ReturnsRedir resultType!.ActionName.Should().Be("QualificationsStartedBetweenSept2014AndAug2019"); resultType.ControllerName.Should().Be("Advice"); } + + [TestMethod] + public async Task Post_WhatLevelIsTheQualification_Level6Pre2014_ReturnsRedirectResponse() + { + var mockLogger = new Mock>(); + var mockContentService = new Mock(); + var mockRenderer = new Mock(); + var mockUserJourneyCookieService = new Mock(); + var mockContentFilterService = new Mock(); + var mockQuestionModelValidator = new Mock(); + + mockUserJourneyCookieService.Setup(x => x.GetWhenWasQualificationAwarded()) + .Returns((7, 2014)); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object, + mockQuestionModelValidator.Object); + + var result = await controller.WhatLevelIsTheQualification(new RadioQuestionModel + { + Option = "6" + }); + + result.Should().NotBeNull(); + + var resultType = result as RedirectToActionResult; + resultType.Should().NotBeNull(); + + resultType!.ActionName.Should().Be("Level6QualificationPre2014"); + resultType.ControllerName.Should().Be("Advice"); + } + + [TestMethod] + public async Task Post_WhatLevelIsTheQualification_Level6Post2014_ReturnsRedirectResponse() + { + var mockLogger = new Mock>(); + var mockContentService = new Mock(); + var mockRenderer = new Mock(); + var mockUserJourneyCookieService = new Mock(); + var mockContentFilterService = new Mock(); + var mockQuestionModelValidator = new Mock(); + + mockUserJourneyCookieService.Setup(x => x.GetWhenWasQualificationAwarded()) + .Returns((7, 2015)); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object, + mockQuestionModelValidator.Object); + + var result = await controller.WhatLevelIsTheQualification(new RadioQuestionModel + { + Option = "6" + }); + + result.Should().NotBeNull(); + + var resultType = result as RedirectToActionResult; + resultType.Should().NotBeNull(); + + resultType!.ActionName.Should().Be("Level6QualificationPost2014"); + resultType.ControllerName.Should().Be("Advice"); + } [TestMethod] public async Task Post_WhatLevelIsTheQualification_Level7_ReturnsRedirectResponse() diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs index 64ab761e..123fbe0a 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs @@ -110,6 +110,32 @@ public async Task GetAdvicePage_QualificationLevel7_ReturnsExpectedDetails() result.Body!.Content[0].Should().BeAssignableTo() .Which.Content.Should().ContainSingle(x => ((Text)x).Value == "Test Advice Page Body"); } + + [TestMethod] + public async Task GetAdvicePage_Level6QualificationPre2014_ReturnsExpectedDetails() + { + var contentfulService = new MockContentfulService(); + + var result = await contentfulService.GetAdvicePage(AdvicePages.Level6QualificationPre2014); + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result!.Heading.Should().NotBeNullOrEmpty(); + result.Body!.Content[0].Should().BeAssignableTo() + .Which.Content.Should().ContainSingle(x => ((Text)x).Value == "Test Advice Page Body"); + } + + [TestMethod] + public async Task GetAdvicePage_Level6QualificationPost2014_ReturnsExpectedDetails() + { + var contentfulService = new MockContentfulService(); + + var result = await contentfulService.GetAdvicePage(AdvicePages.Level6QualificationPost2014); + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result!.Heading.Should().NotBeNullOrEmpty(); + result.Body!.Content[0].Should().BeAssignableTo() + .Which.Content.Should().ContainSingle(x => ((Text)x).Value == "Test Advice Page Body"); + } [TestMethod] public async Task GetAdvicePage_UnknownEntryId_ReturnsException() @@ -292,13 +318,15 @@ public async Task GetRadioQuestionPage_PassInWhatLevelIsTheQualification_Returns result.AdditionalInformationBody!.Content[0].Should().BeAssignableTo() .Which.Content.Should().ContainSingle(x => ((Text)x).Value == "This is the additional information body"); result.Options.Should().NotBeNullOrEmpty(); - result.Options.Count.Should().Be(3); + result.Options.Count.Should().Be(4); result.Options[0].Label.Should().Be("Level 2"); result.Options[0].Value.Should().Be("2"); result.Options[1].Label.Should().Be("Level 3"); result.Options[1].Value.Should().Be("3"); - result.Options[2].Label.Should().Be("Level 7"); - result.Options[2].Value.Should().Be("7"); + result.Options[2].Label.Should().Be("Level 6"); + result.Options[2].Value.Should().Be("6"); + result.Options[3].Label.Should().Be("Level 7"); + result.Options[3].Value.Should().Be("7"); } [TestMethod] diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/Heading4RendererTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/Heading4RendererTests.cs index f171f65c..fd2ce0a0 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/Heading4RendererTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/Heading4RendererTests.cs @@ -42,6 +42,6 @@ public void Heading4Renderer_RendersHeading() var result = new Heading4Renderer().RenderAsync(heading).Result; - result.Should().Be("

Heading text

"); + result.Should().Be("

Heading text

"); } } \ No newline at end of file