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
3 changes: 3 additions & 0 deletions SAPPub.Web/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ public static class Constants
{
public const string Yes = "Yes";
public const string No = "No";

public const string LocalCouncilAverage = "Local council average";
public const string Average = "average";
}
10 changes: 10 additions & 0 deletions SAPPub.Web/Helpers/CommonHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SAPPub.Web.Helpers;
using SAPPub.Web.Constants;

public static class CommonHelper
{
public static string GetLocalAuthorityDisplayName(string? laName) =>
string.IsNullOrWhiteSpace(laName) || laName.Length > 19
? Constants.LocalCouncilAverage
: $"{laName} {Constants.Average}";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SAPPub.Core.Enums;
using SAPPub.Core.ServiceModels.KS4.Performance;
using SAPPub.Web.Helpers;
using SAPPub.Web.Models.Charts;

namespace SAPPub.Web.Models.SecondarySchool;
Expand All @@ -16,7 +17,7 @@ public class AcademicPerformanceEnglishAndMathsResultsViewModel : SecondarySchoo

public static AcademicPerformanceEnglishAndMathsResultsViewModel Map(EnglishAndMathsResultsModel englishAndMathsResultsModel, GcseGradeDataSelection selectedGrade)
{
var laAverageLabel = string.IsNullOrEmpty(englishAndMathsResultsModel.LAName) ? "Local Authority average" : $"{englishAndMathsResultsModel.LAName} average";
var laAverageLabel = CommonHelper.GetLocalAuthorityDisplayName(englishAndMathsResultsModel.LAName);

var allGcseData = new DataViewModel
{
Expand Down
12 changes: 8 additions & 4 deletions SAPPub.Web/Models/SecondarySchool/DestinationsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using SAPPub.Core.Entities.KS4.Destinations;
using SAPPub.Core.ServiceModels.KS4.Performance;
using SAPPub.Web.Helpers;
using SAPPub.Web.Models.Charts;

namespace SAPPub.Web.Models.SecondarySchool;
Expand All @@ -13,12 +15,14 @@ public class DestinationsViewModel : SecondarySchoolBaseViewModel

public static DestinationsViewModel Map(DestinationsDetails destinationsDetails)
{
var laAverageLabel = CommonHelper.GetLocalAuthorityDisplayName(destinationsDetails.LocalAuthorityName);

return new DestinationsViewModel
{
URN = destinationsDetails.Urn,
SchoolName = destinationsDetails.SchoolName,
AllDestinationsData = new DataViewModel {
Labels = ["School", $"{destinationsDetails.LocalAuthorityName} average", "England average"],
Labels = ["School", laAverageLabel, "England average"],
Data = [destinationsDetails.SchoolAll.CurrentYear ?? 0, destinationsDetails.LocalAuthorityAll.CurrentYear ?? 0, destinationsDetails.EnglandAll.CurrentYear ?? 0],
},
AllDestinationsOverTimeData = new DataOverTimeViewModel
Expand All @@ -33,7 +37,7 @@ public static DestinationsViewModel Map(DestinationsDetails destinationsDetails)
},
new DatasetViewModel
{
Label = $"{destinationsDetails.LocalAuthorityName} average",
Label = laAverageLabel,
Data = [destinationsDetails.LocalAuthorityAll.TwoYearsAgo ?? 0, destinationsDetails.LocalAuthorityAll.PreviousYear ?? 0, destinationsDetails.LocalAuthorityAll.CurrentYear ?? 0],
},
new DatasetViewModel
Expand All @@ -52,7 +56,7 @@ public static DestinationsViewModel Map(DestinationsDetails destinationsDetails)
Data = [destinationsDetails.SchoolEducation.CurrentYear ?? 0, (destinationsDetails.SchoolEmployment.CurrentYear ?? 0 + destinationsDetails.SchoolApprentice.CurrentYear ?? 0)]
},
new DataSeriesViewModel {
Label = $"{destinationsDetails.LocalAuthorityName} average",
Label = laAverageLabel,
Data = [destinationsDetails.LocalAuthorityEducation.CurrentYear ?? 0, (destinationsDetails.LocalAuthorityEmployment.CurrentYear ?? 0 + destinationsDetails.LocalAuthorityApprentice.CurrentYear ?? 0)]
},
new DataSeriesViewModel {
Expand All @@ -62,5 +66,5 @@ public static DestinationsViewModel Map(DestinationsDetails destinationsDetails)
],
},
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,49 @@ public async Task Get_AcademicPerformance_EnglishAndMathsResults_ResultsNotAvail
Assert.Equal([0, 0], model.BreakdownGcseData.Datasets[2].Data);
}


[Theory]
[InlineData("Sheffield", "Sheffield average")]
[InlineData("Poole Grammar School", "Local council average")]
public async Task Get_AcademicPerformance_EnglishAndMathsResults_LocalCouncilName(string localCouncilName, string expectedCouncilName)
{
_fakeEstablishment.LAName = localCouncilName;
var grade = GcseGradeDataSelection.Grade4AndAbove;
var expectedResult = EnglishAndMathsResults(_fakeEstablishment.URN, _fakeEstablishment.EstablishmentName, _fakeEstablishment.LAName);

_mockEnglishAndMathsResultsService
.Setup(s => s.GetEnglishAndMathsResultsAsync(_fakeEstablishment.URN, (int)grade, It.IsAny<CancellationToken>()))
.ReturnsAsync(expectedResult);

var result = await _controller.AcademicPerformanceEnglishAndMathsResults(
_mockEnglishAndMathsResultsService.Object,
_fakeEstablishment.URN,
_fakeEstablishment.EstablishmentName,
grade,
CancellationToken.None) as ViewResult;

Assert.NotNull(result);
Assert.NotNull(result.Model);

var model = result.Model as AcademicPerformanceEnglishAndMathsResultsViewModel;
Assert.NotNull(model);
Assert.Equal(_fakeEstablishment.URN, model.URN);
Assert.Equal(_fakeEstablishment.EstablishmentName, model.SchoolName);

string[] expectedAllGcseDataLabels = ["School", expectedCouncilName, "England average"];
string[] expectedAllGcseOverTimeDataLabels = ["School", expectedCouncilName, "England average"];
string[] expectedBreakdownGcseDataLabels = ["School", expectedCouncilName, "England average"];


Assert.Equal(expectedAllGcseDataLabels, model.AllGcseData.Labels);

var actualAllGcseOverTimeDataLabels = model.AllGcseOverTimeData.Datasets.Select(s => s.Label).ToArray();
Assert.Equal(expectedAllGcseOverTimeDataLabels, actualAllGcseOverTimeDataLabels);

var actualBreakdownGcseDataLabels = model.BreakdownGcseData.Datasets.Select(s => s.Label).ToArray();
Assert.Equal(actualBreakdownGcseDataLabels, expectedBreakdownGcseDataLabels);
}

[Fact]
public async Task Get_AcademicPerformance_SubjectsEntered_ReturnsOk()
{
Expand Down Expand Up @@ -1077,4 +1120,56 @@ public async Task Get_Destinations_Info_ReturnsOk()
Assert.Equal(_fakeEstablishment.URN, model.RouteAttributes[RouteConstants.URN]);
Assert.Equal(_fakeEstablishment.EstablishmentName, model.RouteAttributes[RouteConstants.SchoolName]);
}

[Theory]
[InlineData("Sheffield", "Sheffield average")]
[InlineData("Poole Grammar School", "Local council average")]
public async Task Get_Destinations_Info_LocalCouncilName(string localCouncilName, string expectedCouncilName)
{
_fakeEstablishment.LAName = localCouncilName;
var destinationsDetails = new DestinationsDetails
{
Urn = _fakeEstablishment.URN,
SchoolName = _fakeEstablishment.EstablishmentName,
LocalAuthorityName = _fakeEstablishment.LAName,
SchoolAll = new RelativeYearValues<double?> { CurrentYear = 10, PreviousYear = 20, TwoYearsAgo = 30 },
LocalAuthorityAll = new RelativeYearValues<double?> { CurrentYear = 30, PreviousYear = 40, TwoYearsAgo = 50 },
EnglandAll = new RelativeYearValues<double?> { CurrentYear = 70, PreviousYear = 80, TwoYearsAgo = 30 },
SchoolEducation = new RelativeYearValues<double?> { CurrentYear = 20, PreviousYear = 10, TwoYearsAgo = 40 },
LocalAuthorityEducation = new RelativeYearValues<double?> { CurrentYear = 40, PreviousYear = 50, TwoYearsAgo = 70 },
EnglandEducation = new RelativeYearValues<double?> { CurrentYear = 60, PreviousYear = 70, TwoYearsAgo = 20 },
SchoolEmployment = new RelativeYearValues<double?> { CurrentYear = 50, PreviousYear = 70, TwoYearsAgo = 30 },
LocalAuthorityEmployment = new RelativeYearValues<double?> { CurrentYear = 60, PreviousYear = 90, TwoYearsAgo = 50 },
EnglandEmployment = new RelativeYearValues<double?> { CurrentYear = 40, PreviousYear = 60, TwoYearsAgo = 50 },
SchoolApprentice = new RelativeYearValues<double?> { CurrentYear = 40, PreviousYear = 50, TwoYearsAgo = 70 },
LocalAuthorityApprentice = new RelativeYearValues<double?> { CurrentYear = 20, PreviousYear = 70, TwoYearsAgo = 50 },
EnglandApprentice = new RelativeYearValues<double?> { CurrentYear = 50, PreviousYear = 60, TwoYearsAgo = 40 },
};

_mockDestinationsService
.Setup(es => es.GetDestinationsDetailsAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(destinationsDetails);

var result = await _controller.Destinations(_fakeEstablishment.URN, _fakeEstablishment.EstablishmentName, CancellationToken.None) as ViewResult;

string[] expectedAllDestCurrentDataLabels = ["School", expectedCouncilName, "England average"];
string[] expectedDataOvertimeDataLabels = ["School", expectedCouncilName, "England average"];
string[] expectedBreakdownDataLabels = ["School", expectedCouncilName, "England average"];

Assert.NotNull(result);
Assert.NotNull(result.Model);

var model = result.Model as DestinationsViewModel;
Assert.NotNull(model);
Assert.Equal(_fakeEstablishment.URN, model.URN);
Assert.Equal(_fakeEstablishment.EstablishmentName, model.SchoolName);

Assert.Equal(expectedAllDestCurrentDataLabels, model.AllDestinationsData.Labels);

var actualDataOvertimeDataLabels = model.AllDestinationsOverTimeData.Datasets.Select(s => s.Label).ToArray();
Assert.Equal(expectedDataOvertimeDataLabels, actualDataOvertimeDataLabels);

var actualBreakdownDataLabels = model.BreakdownDestinationData.Datasets.Select(s => s.Label).ToArray();
Assert.Equal(expectedBreakdownDataLabels, actualBreakdownDataLabels);
}
}
Loading