Skip to content

Commit

Permalink
Merge pull request #667 from DFE-Digital/feat/211792/recommendations-…
Browse files Browse the repository at this point in the history
…front-end

feat: self assessment changes with time and view recommendation button
katie-gardner authored Jun 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 46038e2 + 8bd3750 commit cdb1c16
Showing 16 changed files with 90 additions and 91 deletions.
18 changes: 15 additions & 3 deletions src/Dfe.PlanTech.Domain/CategorySection/CategorySectionDto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dfe.PlanTech.Domain.Constants;
using Dfe.PlanTech.Domain.Questionnaire.Models;
using Dfe.PlanTech.Domain.Submissions.Models;

namespace Dfe.PlanTech.Domain.CategorySection;

@@ -15,11 +16,14 @@ public class CategorySectionDto

public CategorySectionRecommendationDto? Recommendation { get; init; }

public CategorySectionDto(string? slug, string name, bool retrievalError, bool started, bool completed, CategorySectionRecommendationDto recommendation)
public CategorySectionDto(string? slug, string name, bool retrievalError, SectionStatusDto? sectionStatus, CategorySectionRecommendationDto recommendation)
{
Slug = slug;
Name = name;
Recommendation = recommendation;
var started = sectionStatus != null;
var completed = sectionStatus?.Completed == true;
var lastEdited = LastEditedDate(sectionStatus?.DateCreated);
if (string.IsNullOrWhiteSpace(slug))
{
ErrorMessage = $"{Name} unavailable";
@@ -28,10 +32,18 @@ public CategorySectionDto(string? slug, string name, bool retrievalError, bool s
else if (retrievalError)
Tag = new Tag("UNABLE TO RETRIEVE STATUS", TagColour.Red);
else if (completed)
Tag = new Tag("COMPLETE", TagColour.Blue);
Tag = new Tag($"COMPLETE {lastEdited}", TagColour.Grey);
else if (started)
Tag = new Tag("IN PROGRESS", TagColour.LightBlue);
Tag = new Tag($"IN PROGRESS {lastEdited}", TagColour.Grey);
else
Tag = new Tag("NOT STARTED", TagColour.Grey);
}

private static string? LastEditedDate(DateTime? date)
{
if (date == null)
return null;
var localTime = date.Value.ToLocalTime();
return localTime.Date == DateTime.Today.Date ? $"{localTime:hh:mm tt}" : localTime.ToShortDateString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Dfe.PlanTech.Domain.Constants;
using Dfe.PlanTech.Domain.Questionnaire.Models;

namespace Dfe.PlanTech.Domain.CategorySection;

public class CategorySectionRecommendationDto
@@ -12,8 +9,4 @@ public class CategorySectionRecommendationDto
public string? NoRecommendationFoundErrorMessage { get; init; }

public string? SectionSlug { get; init; }

public Tag Tag => RecommendationSlug != null
? new Tag("READY", TagColour.LightBlue)
: new Tag("NOT AVAILABLE", TagColour.Grey);
}
4 changes: 3 additions & 1 deletion src/Dfe.PlanTech.Domain/Constants/TagColour.cs
Original file line number Diff line number Diff line change
@@ -7,8 +7,10 @@ public static class TagColour
public readonly static string Grey = "grey";
public readonly static string LightBlue = "light-blue";
public readonly static string Red = "red";
public readonly static string Green = "green";
public readonly static string Yellow = "yellow";

private readonly static string[] _colours = [Blue, Grey, LightBlue, Red];
private readonly static string[] _colours = [Blue, Grey, LightBlue, Red, Green, Yellow];

public static string GetMatchingColour(string? toMatch)
=> string.IsNullOrEmpty(toMatch) ?
7 changes: 0 additions & 7 deletions src/Dfe.PlanTech.Web.Node/styles/scss/app-task-list.scss
Original file line number Diff line number Diff line change
@@ -140,13 +140,6 @@
}
}

@media (min-width: 28.125em) {
.app-task-list__tag,
.app-task-list__task-completed {
float: right;
}
}

#checkYourAnswers-page .spacer {
content: " " !important;
display: block !important;
17 changes: 17 additions & 0 deletions src/Dfe.PlanTech.Web.Node/styles/scss/overrides.scss
Original file line number Diff line number Diff line change
@@ -37,12 +37,29 @@ div.govuk-width-container {

strong.govuk-tag {
text-transform: lowercase;
max-width: fit-content;
vertical-align: middle;

&:first-letter {
text-transform: uppercase;
}
}

.dfe-self-assessment-list {
> .govuk-summary-list__row {
height: 4rem;
}
}

.govuk-summary-list__key,
.govuk-summary-list__value {
vertical-align: middle;

> .govuk-button {
vertical-align: middle;
}
}

//Hide GTM iframe
iframe {
display: none;
2 changes: 1 addition & 1 deletion src/Dfe.PlanTech.Web/Controllers/CheckAnswersController.cs
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public async Task<IActionResult> ConfirmCheckAnswers(string sectionSlug, int sub
return this.RedirectToCheckAnswers(sectionSlug);
}

TempData["SectionName"] = sectionName;
TempData["SectionSlug"] = sectionSlug;

return this.RedirectToSelfAssessment();
}
Original file line number Diff line number Diff line change
@@ -63,8 +63,7 @@ private async IAsyncEnumerable<CategorySectionDto> GetCategorySectionDto(Categor
slug: section.InterstitialPage.Slug,
name: section.Name,
retrievalError: category.RetrievalError,
started: sectionStatus != null,
completed: sectionStatus?.Completed == true,
sectionStatus: sectionStatus,
recommendation: await GetCategorySectionRecommendationDto(section, sectionStatus)
);
}
24 changes: 2 additions & 22 deletions src/Dfe.PlanTech.Web/Views/Pages/Page.cshtml
Original file line number Diff line number Diff line change
@@ -9,28 +9,8 @@
{
await Html.RenderPartialAsync("HomeButton", Model);
}
}
@{
if (Model.Page.Slug == "self-assessment" && TempData.ContainsKey("SectionName"))
{
var sectionName = TempData["SectionName"] as string;
<div class="govuk-notification-banner govuk-notification-banner--success" role="alert"
aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__header">
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title">
Success
</h2>
</div>
@if (!string.IsNullOrEmpty(sectionName))
{
<div class="govuk-notification-banner__content">
<h3 class="govuk-notification-banner__heading">
You have one new <a href="#recommendations-section">recommendation for @sectionName</a>
</h3>
</div>
}
</div>
}
}
@{
if (Model.Page.Slug == "self-assessment" && TempData.ContainsKey("SubtopicError"))
{
var error = TempData["SubtopicError"] as string;
Original file line number Diff line number Diff line change
@@ -20,14 +20,12 @@ else
class="govuk-visually-hidden">Error:</span>@Model.ProgressRetrievalErrorMessage</p>
}

<task-list>
<dl class="govuk-summary-list dfe-self-assessment-list">
@foreach (var categorySectionDtoItem in Model.CategorySectionDto)
{
<task-list-item>
<partial name="Components/CategorySection/Subtopic" model="@categorySectionDtoItem" />
</task-list-item>
<task-list-item>
<partial name="Components/CategorySection/SubtopicRecommendation" model="@categorySectionDtoItem.Recommendation" />
</task-list-item>
<div class="govuk-summary-list__row">
<partial name="Components/CategorySection/Subtopic" model="@categorySectionDtoItem"/>
<partial name="Components/CategorySection/SubtopicRecommendation" model="@categorySectionDtoItem.Recommendation"/>
</div>
}
</task-list>
</dl>
Original file line number Diff line number Diff line change
@@ -2,19 +2,21 @@

@if (Model.Slug != null)
{
<task-list-item-name>
<dt class="govuk-summary-list__key govuk-!-font-weight-regular">
<a asp-controller="Pages" asp-action="GetByRoute" asp-route-route="@Model.Slug"
class="govuk-link">
@Model.Name
</a>
</task-list-item-name>
<task-list-tag colour=@Model.Tag.Colour>
@Model.Tag.Text
</task-list-tag>
</dt>
<dd class="govuk-summary-list__value govuk-!-text-align-left">
<task-list-tag colour=@Model.Tag.Colour>
@Model.Tag.Text
</task-list-tag>
</dd>
}
else
{
<task-list-item-name>
<dt class="govuk-summary-list__key">
<govuk-error-message>@Model.ErrorMessage</govuk-error-message>
</task-list-item-name>
</dt>
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
@using Dfe.PlanTech.Domain.Constants
@model Dfe.PlanTech.Domain.CategorySection.CategorySectionRecommendationDto

@if (Model.NoRecommendationFoundErrorMessage == null)
{
@if (Model.RecommendationSlug != null)

<dd class="govuk-summary-list__value govuk-!-text-align-right">
@if (Model.NoRecommendationFoundErrorMessage != null)
{
<task-list-item-name>
<a class="govuk-link" asp-route="GetRecommendation" asp-route-sectionSlug="@Model.SectionSlug" asp-route-recommendationSlug="@Model.RecommendationSlug">
Recommendation
</a>
</task-list-item-name>
<govuk-error-message>@Model.NoRecommendationFoundErrorMessage</govuk-error-message>
}
else
else if (Model.RecommendationSlug != null)
{
<task-list-item-name>
Recommendation
</task-list-item-name>
if (TempData.ContainsKey("SectionSlug"))
{
var sectionSlug = TempData["SectionSlug"] as string;
@if (!string.IsNullOrEmpty(sectionSlug) && sectionSlug == Model.SectionSlug)
{
<task-list-tag colour="@TagColour.Yellow">New</task-list-tag>
}
}
<govuk-button-link
class="go"
asp-route="GetRecommendation"
asp-route-sectionSlug="@Model.SectionSlug"
asp-route-recommendationSlug="@Model.RecommendationSlug">
View Recommendation
</govuk-button-link>
}
<task-list-tag colour=@Model.Tag.Colour>
@Model.Tag.Text
</task-list-tag>
}
else
{
<task-list-item-name>
<govuk-error-message>@Model.NoRecommendationFoundErrorMessage</govuk-error-message>
</task-list-item-name>
}
</dd>

2 changes: 1 addition & 1 deletion src/Dfe.PlanTech.Web/wwwroot/css/application.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Dfe.PlanTech.Web/wwwroot/css/application.css.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* Click first section link on self-assessment page
*/
export const clickFirstSection = () => {
cy.get("ul.app-task-list__items > li a")
cy.get("div.govuk-summary-list__row > dt a")
.first()
.click();
}
Original file line number Diff line number Diff line change
@@ -16,13 +16,13 @@ describe("Self-assessment page", () => {
});

it("should contain sections", () => {
cy.get("ul.app-task-list__items > li")
cy.get("div.govuk-summary-list__row > dt")
.should("exist")
.and("have.length.greaterThan", 1);
});

it("each section should link to a page", () => {
cy.get("ul.app-task-list__items > li a").each((link) => {
cy.get("div.govuk-summary-list__row > dt a").each((link) => {
cy.wrap(link).should("have.attr", "href").and("not.be.null");
});
});
Original file line number Diff line number Diff line change
@@ -213,6 +213,7 @@ public async Task Returns_CategorySectionInfo_If_Slug_Exists_And_SectionIsComple
{
SectionId = "Section1",
Completed = true,
DateCreated = new DateTime(2015, 10, 15),
});

_getSubmissionStatusesQuery.GetSectionSubmissionStatuses(_category.Sys.Id).Returns([.. _category.SectionStatuses]);
@@ -244,8 +245,8 @@ public async Task Returns_CategorySectionInfo_If_Slug_Exists_And_SectionIsComple

Assert.Equal("section-1", categorySectionDto.Slug);
Assert.Equal("Test Section 1", categorySectionDto.Name);
Assert.Equal("blue", categorySectionDto.Tag.Colour);
Assert.Equal("COMPLETE", categorySectionDto.Tag.Text);
Assert.Equal("grey", categorySectionDto.Tag.Colour);
Assert.Equal("COMPLETE 15/10/2015", categorySectionDto.Tag.Text);

Check failure on line 249 in tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs

GitHub Actions / DotNET Tests

Dfe.PlanTech.Web.UnitTests.ViewComponents.CategorySectionViewComponentTests ► Returns_CategorySectionInfo_If_Slug_Exists_And_SectionIsCompleted

Failed test found in: tests/Dfe.PlanTech.Web.UnitTests/TestResults/test-results.trx Error: Assert.Equal() Failure: Strings differ ↓ (pos 10) Expected: "COMPLETE 15/10/2015" Actual: "COMPLETE 10/15/2015" ↑ (pos 10)
Raw output
Assert.Equal() Failure: Strings differ
                     ↓ (pos 10)
Expected: "COMPLETE 15/10/2015"
Actual:   "COMPLETE 10/15/2015"
                     ↑ (pos 10)
   at Dfe.PlanTech.Web.UnitTests.ViewComponents.CategorySectionViewComponentTests.Returns_CategorySectionInfo_If_Slug_Exists_And_SectionIsCompleted() in /home/runner/work/sts-plan-technology-for-your-school/sts-plan-technology-for-your-school/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs:line 249
--- End of stack trace from previous location ---
Assert.Null(categorySectionDto.ErrorMessage);
}

@@ -257,7 +258,8 @@ public async Task Returns_CategorySelectionInfo_If_Slug_Exists_And_SectionIsNotC
_category.SectionStatuses.Add(new SectionStatusDto()
{
SectionId = "Section1",
Completed = false
Completed = false,
DateCreated = new DateTime(2000, 01, 25)
});

_getSubmissionStatusesQuery.GetSectionSubmissionStatuses(_category.Sys.Id).Returns([.. _category.SectionStatuses]);
@@ -289,8 +291,8 @@ public async Task Returns_CategorySelectionInfo_If_Slug_Exists_And_SectionIsNotC

Assert.Equal("section-1", categorySectionDto.Slug);
Assert.Equal("Test Section 1", categorySectionDto.Name);
Assert.Equal("light-blue", categorySectionDto.Tag.Colour);
Assert.Equal("IN PROGRESS", categorySectionDto.Tag.Text);
Assert.Equal("grey", categorySectionDto.Tag.Colour);
Assert.Equal("IN PROGRESS 25/01/2000", categorySectionDto.Tag.Text);

Check failure on line 295 in tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs

GitHub Actions / DotNET Tests

Dfe.PlanTech.Web.UnitTests.ViewComponents.CategorySectionViewComponentTests ► Returns_CategorySelectionInfo_If_Slug_Exists_And_SectionIsNotCompleted

Failed test found in: tests/Dfe.PlanTech.Web.UnitTests/TestResults/test-results.trx Error: Assert.Equal() Failure: Strings differ ↓ (pos 12) Expected: "IN PROGRESS 25/01/2000" Actual: "IN PROGRESS 01/25/2000" ↑ (pos 12)
Raw output
Assert.Equal() Failure: Strings differ
                       ↓ (pos 12)
Expected: "IN PROGRESS 25/01/2000"
Actual:   "IN PROGRESS 01/25/2000"
                       ↑ (pos 12)
   at Dfe.PlanTech.Web.UnitTests.ViewComponents.CategorySectionViewComponentTests.Returns_CategorySelectionInfo_If_Slug_Exists_And_SectionIsNotCompleted() in /home/runner/work/sts-plan-technology-for-your-school/sts-plan-technology-for-your-school/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs:line 295
--- End of stack trace from previous location ---
Assert.Null(categorySectionDto.ErrorMessage);
}

0 comments on commit cdb1c16

Please sign in to comment.