Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions SAPPub.Core/Extensions/EducationPhaseFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace SAPPub.Core.Extensions;

public static class EducationPhaseFormatter
{
public static string? Format(bool isKS2, bool isKS4, bool isKS5)
{
var phaseList = new List<string>();

if (isKS2)
{
phaseList.Add("Primary");
}

if (isKS4)
{
phaseList.Add("Secondary");
}

if (isKS5)
{
phaseList.Add("16 to 18");
}

return phaseList.Count switch
{
0 => null,
1 => phaseList[0],
2 => $"{phaseList[0]} and {phaseList[1]}",
_ => $"{phaseList[0]}, {phaseList[1]} and {phaseList[2]}"
};
}
}
7 changes: 7 additions & 0 deletions SAPPub.Core/ServiceModels/KS4/AboutSchool/AboutSchoolModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SAPPub.Core.Enums;
using System.Runtime.InteropServices;

namespace SAPPub.Core.ServiceModels.KS4.AboutSchool;

Expand Down Expand Up @@ -56,6 +57,12 @@ public class AboutSchoolModel

public string? SenTypes { get; set; }

public bool IsKS2 { get; set; }

public bool IsKS4 { get; set; }

public bool IsKS5 { get; set; }

public IList<EstablishmentLinkModel>? Predecessors { get; set; }
public IList<EstablishmentLinkModel>? Successors { get; set; }
}
6 changes: 4 additions & 2 deletions SAPPub.Core/Services/KS4/AboutSchool/AboutSchoolService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ public async Task<AboutSchoolModel> GetAboutSchoolDetailsAsync(string urn, Cance
OpenReasonId = establishment.OpenReasonId,
SenTypes = establishment.SenTypes,
Predecessors = predecessorLinks,
Successors = sucessorLinks
Successors = sucessorLinks,
IsKS2 = establishment.IsKS2,
IsKS4 = establishment.IsKS4,
IsKS5 = establishment.IsKS5
};

}
}
5 changes: 4 additions & 1 deletion SAPPub.Web/Models/SecondarySchool/AboutSchoolViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public record School(string Name, double Lat, double Lon);
public List<SuccessorOrPredecessorDetailsModel>? Predecessors { get; set; }
public List<SuccessorOrPredecessorDetailsModel>? Successors { get; set; }

public string? EducationPhase { get; set; }

public static AboutSchoolViewModel Map(AboutSchoolModel schoolDetails)
{
var latLong = MappingHelper.ConvertToLatLon(schoolDetails.Easting, schoolDetails.Northing);
Expand Down Expand Up @@ -111,7 +113,8 @@ public static AboutSchoolViewModel Map(AboutSchoolModel schoolDetails)
SenTypes = schoolDetails.SenTypes.ToDisplayField(),
RecentlyOpenedSchoolMessage = GetRecentlyOpenedSchoolMessage(schoolDetails.OpenReasonId, schoolDetails.OpenDate),
Predecessors = schoolDetails.Predecessors?.Select(p => SuccessorOrPredecessorDetailsModel.Map(p)).ToList(),
Successors = schoolDetails.Successors?.Select(s => SuccessorOrPredecessorDetailsModel.Map(s)).ToList()
Successors = schoolDetails.Successors?.Select(s => SuccessorOrPredecessorDetailsModel.Map(s)).ToList(),
EducationPhase = EducationPhaseFormatter.Format(schoolDetails.IsKS2, schoolDetails.IsKS4, schoolDetails.IsKS5)
};
}

Expand Down
7 changes: 7 additions & 0 deletions SAPPub.Web/Views/SecondarySchool/AboutSchool.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@
</a>
</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Education Phase</govuk-summary-list-row-key>
<govuk-summary-list-row-value>
@Model.EducationPhase
</govuk-summary-list-row-value>
</govuk-summary-list-row>

<govuk-summary-list-row>
<govuk-summary-list-row-key>Type of school</govuk-summary-list-row-key>
<govuk-summary-list-row-value>
Expand Down
26 changes: 26 additions & 0 deletions Tests/SAPPub.Core.Tests/Helpers/EducationalPhaseFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using SAPPub.Core.Extensions;

namespace SAPPub.Core.Tests.Helpers
{
public class EducationalPhaseFormatterTests
{
[Theory]
[InlineData(false, false, false, null)]
[InlineData(true, false, false, "Primary")]
[InlineData(true, true, false, "Primary and Secondary")]
[InlineData(true, true, true, "Primary, Secondary and 16 to 18")]
[InlineData(false, true, true, "Secondary and 16 to 18")]
[InlineData(false, false, true, "16 to 18")]
[InlineData(false, true, false, "Secondary")]
[InlineData(true, false, true, "Primary and 16 to 18")]
public void CleanForUrl_RemovesNonAlphaChars(bool isKS2, bool isKS4, bool isKS5, string? output)
{
// Arrange
// Act
var result = EducationPhaseFormatter.Format(isKS2, isKS4, isKS5);

// Assert
Assert.Equal(output, result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ public EstablishmentTestBuilder WithSenTypes(string senTypes)
return this;
}

public EstablishmentTestBuilder WithIsKeyStage2(bool isKS2)
{
_establishment.IsKS2 = isKS2;
return this;
}

public EstablishmentTestBuilder WithIsKeyStage4(bool isKS4)
{
_establishment.IsKS4 = isKS4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ private AboutSchoolModel SchoolDetails()
Status = _fakeEstablishment.StatusCode.ToStatus(),
ClosedDate = _fakeEstablishment.ClosedDate.ToDateOnly(),
OpenReasonId = _fakeEstablishment.OpenReasonId,
OpenDate = _fakeEstablishment.OpenDate.ToDateOnly()
OpenDate = _fakeEstablishment.OpenDate.ToDateOnly(),
IsKS2 = true,
IsKS4 = true
};
}

Expand Down Expand Up @@ -189,6 +191,8 @@ public SecondarySchoolControllerTests()
.WithOpenReasonId(10)
.WithOpenDate()
.WithSenTypes("VI - Visual Impairment, HI - Hearing Impairment")
.WithIsKeyStage2(true)
.WithIsKeyStage4(true)
.Build();

_mockLogger = new Mock<ILogger<SecondarySchoolController>>();
Expand Down Expand Up @@ -254,6 +258,7 @@ public async Task Get_AboutSchool_Info_ReturnsExpected()
Assert.Equal(TextHelpers.CleanForUrl(expectedResult.SchoolName), model.RouteAttributes[RouteConstants.SchoolName]);
Assert.Equal(expectedResult.OpenReasonId, model.OpenReasonId);
Assert.Equal(expectedResult.SenTypes, model.SenTypes.Value);
Assert.Equal("Primary and Secondary", model.EducationPhase);
}

[Fact]
Expand Down
Loading