Skip to content

Commit

Permalink
Updated the content models to add additional information section (#281)
Browse files Browse the repository at this point in the history
* Updated the content models so that questions have the optional additional information section

* Changed set to init
  • Loading branch information
sam-c-dfe authored Aug 1, 2024
1 parent 22fcee5 commit d55b7fb
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Contentful.Core.Models;

namespace Dfe.EarlyYearsQualification.Content.Entities;

public class DateQuestionPage
Expand All @@ -19,4 +21,8 @@ public class DateQuestionPage
public string ErrorBannerHeading { get; init; } = string.Empty;

public string ErrorBannerLinkText { get; init; } = string.Empty;

public string AdditionalInformationHeader { get; init; } = string.Empty;

public Document? AdditionalInformationBody { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Contentful.Core.Models;

namespace Dfe.EarlyYearsQualification.Content.Entities;

public class DropdownQuestionPage
Expand All @@ -19,4 +21,8 @@ public class DropdownQuestionPage
public string ErrorBannerHeading { get; init; } = string.Empty;

public string ErrorBannerLinkText { get; init; } = string.Empty;

public string AdditionalInformationHeader { get; init; } = string.Empty;

public Document? AdditionalInformationBody { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,9 @@ private static RadioQuestionPage CreateRadioQuestionPage(string question, List<O
OpenInNewTab = false
},
ErrorBannerHeading = "There is a problem",
ErrorBannerLinkText = "Test error banner link text"
ErrorBannerLinkText = "Test error banner link text",
AdditionalInformationBody = ContentfulContentHelper.Paragraph("This is the additional information body"),
AdditionalInformationHeader = "This is the additional information header"
};
}

Expand All @@ -498,7 +500,9 @@ private static DateQuestionPage CreateDateQuestionPage()
OpenInNewTab = false
},
ErrorBannerHeading = "There is a problem",
ErrorBannerLinkText = "Test error banner link text"
ErrorBannerLinkText = "Test error banner link text",
AdditionalInformationBody = ContentfulContentHelper.Paragraph("This is the additional information body"),
AdditionalInformationHeader = "This is the additional information header"
};
}

Expand All @@ -519,7 +523,9 @@ private static DropdownQuestionPage CreateDropdownPage()
OpenInNewTab = false
},
ErrorBannerHeading = "There is a problem",
ErrorBannerLinkText = "Test error banner link text"
ErrorBannerLinkText = "Test error banner link text",
AdditionalInformationBody = ContentfulContentHelper.Paragraph("This is the additional information body"),
AdditionalInformationHeader = "This is the additional information header"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<IActionResult> WhenWasTheQualificationStarted()
return RedirectToAction("Index", "Error");
}

var model = MapDateModel(new DateQuestionModel(), questionPage, nameof(this.WhenWasTheQualificationStarted),
var model = await MapDateModel(new DateQuestionModel(), questionPage, nameof(this.WhenWasTheQualificationStarted),
Questions);
return View("Date", model);
}
Expand All @@ -94,7 +94,7 @@ public async Task<IActionResult> WhenWasTheQualificationStarted(DateQuestionMode
// ReSharper disable once InvertIf
if (questionPage is not null)
{
model = MapDateModel(model, questionPage, nameof(this.WhenWasTheQualificationStarted), Questions);
model = await MapDateModel(model, questionPage, nameof(this.WhenWasTheQualificationStarted), Questions);
model.HasErrors = true;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public async Task<IActionResult> WhatIsTheAwardingOrganisation()

var qualifications = await GetFilteredQualifications();

var model = MapDropdownModel(new DropdownQuestionModel(), questionPage, qualifications,
var model = await MapDropdownModel(new DropdownQuestionModel(), questionPage, qualifications,
nameof(this.WhatIsTheAwardingOrganisation),
Questions);

Expand All @@ -173,7 +173,7 @@ public async Task<IActionResult> WhatIsTheAwardingOrganisation(DropdownQuestionM
{
var qualifications = await GetFilteredQualifications();

model = MapDropdownModel(model, questionPage, qualifications,
model = await MapDropdownModel(model, questionPage, qualifications,
nameof(this.WhatIsTheAwardingOrganisation),
Questions);
model.HasErrors = true;
Expand Down Expand Up @@ -239,7 +239,7 @@ private async Task<RadioQuestionModel> MapRadioModel(RadioQuestionModel model, R
return model;
}

private static DateQuestionModel MapDateModel(DateQuestionModel model, DateQuestionPage question, string actionName,
private async Task<DateQuestionModel> MapDateModel(DateQuestionModel model, DateQuestionPage question, string actionName,
string controllerName)
{
model.Question = question.Question;
Expand All @@ -253,10 +253,12 @@ private static DateQuestionModel MapDateModel(DateQuestionModel model, DateQuest
model.BackButton = question.BackButton;
model.ErrorBannerHeading = question.ErrorBannerHeading;
model.ErrorBannerLinkText = question.ErrorBannerLinkText;
model.AdditionalInformationHeader = question.AdditionalInformationHeader;
model.AdditionalInformationBody = await renderer.ToHtml(question.AdditionalInformationBody);
return model;
}

private static DropdownQuestionModel MapDropdownModel(DropdownQuestionModel model, DropdownQuestionPage question,
private async Task<DropdownQuestionModel> MapDropdownModel(DropdownQuestionModel model, DropdownQuestionPage question,
List<Qualification> qualifications, string actionName,
string controllerName)
{
Expand Down Expand Up @@ -295,6 +297,8 @@ var uniqueAwardingOrganisations

model.ErrorBannerHeading = question.ErrorBannerHeading;
model.ErrorBannerLinkText = question.ErrorBannerLinkText;
model.AdditionalInformationHeader = question.AdditionalInformationHeader;
model.AdditionalInformationBody = await renderer.ToHtml(question.AdditionalInformationBody);
return model;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dfe.EarlyYearsQualification.Web.Models;

public class AdditionalInformationModel
{
public string AdditionalInformationHeader { get; init; } = string.Empty;

public string AdditionalInformationBody { get; init; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public abstract class BaseQuestionModel
public string ErrorBannerHeading { get; set; } = string.Empty;

public string ErrorBannerLinkText { get; set; } = string.Empty;

public string AdditionalInformationHeader { get; set; } = string.Empty;

public string AdditionalInformationBody { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ public class RadioQuestionModel : BaseQuestionModel
public List<OptionModel> Options { get; set; } = [];

[Required] public string? Option { get; init; } = string.Empty;

public string AdditionalInformationHeader { get; set; } = string.Empty;

public string AdditionalInformationBody { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
</h1>
</legend>

@if (!string.IsNullOrEmpty(Model.AdditionalInformationHeader) && !string.IsNullOrEmpty(Model.AdditionalInformationBody))
{
await Html.RenderPartialAsync("Partials/AdditionalInformation", new AdditionalInformationModel
{
AdditionalInformationHeader = Model.AdditionalInformationHeader,
AdditionalInformationBody = Model.AdditionalInformationBody
});
}

<div id="date-format-hint" class="govuk-hint">@Model.QuestionHint</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
</h1>
</legend>

@if (!string.IsNullOrEmpty(Model.AdditionalInformationHeader) && !string.IsNullOrEmpty(Model.AdditionalInformationBody))
{
await Html.RenderPartialAsync("Partials/AdditionalInformation", new AdditionalInformationModel
{
AdditionalInformationHeader = Model.AdditionalInformationHeader,
AdditionalInformationBody = Model.AdditionalInformationBody
});
}

<h1 class="govuk-label-wrapper">
@Html.Label(Model.DropdownId, Model.DropdownHeading, new { @class = "govuk-label govuk-fieldset__legend--m" })
Expand Down
16 changes: 6 additions & 10 deletions src/Dfe.EarlyYearsQualification.Web/Views/Questions/Radio.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@

@if (!string.IsNullOrEmpty(Model.AdditionalInformationHeader) && !string.IsNullOrEmpty(Model.AdditionalInformationBody))
{
<details class="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
@Model.AdditionalInformationHeader
</span>
</summary>
<div class="govuk-details__text">
@Html.Raw(Model.AdditionalInformationBody)
</div>
</details>
await Html.RenderPartialAsync("Partials/AdditionalInformation", new AdditionalInformationModel
{
AdditionalInformationHeader = Model.AdditionalInformationHeader,
AdditionalInformationBody = Model.AdditionalInformationBody
});
}

@if (Model.HasErrors)
{
<p id="option-error" class="govuk-error-message">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@model Dfe.EarlyYearsQualification.Web.Models.AdditionalInformationModel

<details class="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
@Model.AdditionalInformationHeader
</span>
</summary>
<div class="govuk-details__text">
@Html.Raw(Model.AdditionalInformationBody)
</div>
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ describe("A spec that tests question pages", () => {
cy.get("#outside-uk").should("exist");
})

it("Checks additional information on the where-was-the-qualification-awarded page", () => {
cy.visit("/questions/where-was-the-qualification-awarded");

cy.get(".govuk-details").should("not.have.attr", "open");
cy.get(".govuk-details__summary-text").should("contain.text", "This is the additional information header");
cy.get(".govuk-details__text").should("contain.text", "This is the additional information body");

cy.get(".govuk-details__summary-text").click();
cy.get(".govuk-details").should("have.attr", "open");
})

it("shows an error message when a user doesnt select an option on the where-was-the-qualification-awarded page", () => {
cy.visit("/questions/where-was-the-qualification-awarded");

Expand Down Expand Up @@ -45,6 +56,17 @@ describe("A spec that tests question pages", () => {
cy.get("#date-started-year").should("exist");
})

it("Checks additional information on the when-was-the-qualification-started page", () => {
cy.visit("/questions/when-was-the-qualification-started");

cy.get(".govuk-details").should("not.have.attr", "open");
cy.get(".govuk-details__summary-text").should("contain.text", "This is the additional information header");
cy.get(".govuk-details__text").should("contain.text", "This is the additional information body");

cy.get(".govuk-details__summary-text").click();
cy.get(".govuk-details").should("have.attr", "open");
})

it("shows an error message when a user doesnt type a date on the when-was-the-qualification-started page", () => {
cy.visit("/questions/when-was-the-qualification-started");

Expand Down Expand Up @@ -75,6 +97,17 @@ describe("A spec that tests question pages", () => {
cy.get("#3").should("exist");
})

it("Checks additional information on the what-level-is-the-qualification page", () => {
cy.visit("/questions/what-level-is-the-qualification");

cy.get(".govuk-details").should("not.have.attr", "open");
cy.get(".govuk-details__summary-text").should("contain.text", "This is the additional information header");
cy.get(".govuk-details__text").should("contain.text", "This is the additional information body");

cy.get(".govuk-details__summary-text").click();
cy.get(".govuk-details").should("have.attr", "open");
})

it("shows an error message when a user doesnt select an option on the what-level-is-the-qualification page", () => {
cy.visit("/questions/what-level-is-the-qualification");

Expand Down Expand Up @@ -106,6 +139,17 @@ describe("A spec that tests question pages", () => {
cy.get('button[id="question-submit"]').should("exist");
})

it("Checks additional information on the what-is-the-awarding-organisation page", () => {
cy.visit("/questions/what-is-the-awarding-organisation");

cy.get(".govuk-details").should("not.have.attr", "open");
cy.get(".govuk-details__summary-text").should("contain.text", "This is the additional information header");
cy.get(".govuk-details__text").should("contain.text", "This is the additional information body");

cy.get(".govuk-details__summary-text").click();
cy.get(".govuk-details").should("have.attr", "open");
})

it("shows an error message when a user doesnt select an option from the dropdown list" +
"and also does not check 'not in the list' on the what-is-the-awarding-organisation", () => {
cy.visit("/questions/what-is-the-awarding-organisation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ public async Task GetRadioQuestionPage_PassInWhatLevelIsTheQualification_Returns
result.ErrorMessage.Should().NotBeNullOrEmpty();
result.ErrorBannerHeading.Should().NotBeNull();
result.ErrorBannerLinkText.Should().NotBeNull();
result.AdditionalInformationHeader.Should().Be("This is the additional information header");
result.AdditionalInformationBody!.Content[0].Should().BeAssignableTo<Paragraph>()
.Which.Content.Should().ContainSingle(x => ((Text)x).Value == "This is the additional information body");
result.Options.Should().NotBeNullOrEmpty();
result.Options.Count.Should().Be(2);
result.Options[0].Label.Should().Be("Level 2");
Expand Down Expand Up @@ -306,6 +309,9 @@ public async Task GetDateQuestionPage_PassWhenWasQualificationStartedId_ReturnsE
result.ErrorMessage.Should().Be("Test Error Message");
result.ErrorBannerHeading.Should().Be("There is a problem");
result.ErrorBannerLinkText.Should().Be("Test error banner link text");
result.AdditionalInformationHeader.Should().Be("This is the additional information header");
result.AdditionalInformationBody!.Content[0].Should().BeAssignableTo<Paragraph>()
.Which.Content.Should().ContainSingle(x => ((Text)x).Value == "This is the additional information body");
result.MonthLabel.Should().Be("Test Month Label");
result.YearLabel.Should().Be("Test Year Label");
result.QuestionHint.Should().Be("Test Question Hint");
Expand Down Expand Up @@ -334,6 +340,9 @@ public async Task GetDropdownQuestionPage_PassWhenWasQualificationStartedId_Retu
result.ErrorMessage.Should().Be("Test Error Message");
result.ErrorBannerHeading.Should().Be("There is a problem");
result.ErrorBannerLinkText.Should().Be("Test error banner link text");
result.AdditionalInformationHeader.Should().Be("This is the additional information header");
result.AdditionalInformationBody!.Content[0].Should().BeAssignableTo<Paragraph>()
.Which.Content.Should().ContainSingle(x => ((Text)x).Value == "This is the additional information body");
result.Question.Should().Be("Test Dropdown Question");
result.DefaultText.Should().Be("Test Default Dropdown Text");
result.DropdownHeading.Should().Be("Test Dropdown Heading");
Expand Down

0 comments on commit d55b7fb

Please sign in to comment.