This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #522 from DFE-Digital/120674/key-stage-4-status
Added tags to downloaded document and preview KS4
- Loading branch information
Showing
4 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
Dfe.PrepareTransfers.Web.Tests/HelpersTests/KeyStage4DataStatusHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Dfe.PrepareTransfers.Web.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Dfe.PrepareTransfers.Web.Tests.HelpersTests | ||
{ | ||
public class KeyStage4DataTagHelperTests | ||
{ | ||
[Theory, MemberData(nameof(ProvisionalDates))] | ||
public void Should_return_provisional_status_on_relevant_months(DateTime date) | ||
{ | ||
var resultingHtml = KeyStage4DataStatusHelper.KeyStageDataTag(date); | ||
var result = KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(date); | ||
resultingHtml.Should().Contain("grey").And.Contain("Provisional"); | ||
result.Should().Be("Provisional"); | ||
} | ||
|
||
[Theory, MemberData(nameof(RevisedDates))] | ||
public void Should_return_revised_status_on_relevant_months(DateTime date) | ||
{ | ||
var resultingHtml = KeyStage4DataStatusHelper.KeyStageDataTag(date); | ||
var result = KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(date); | ||
resultingHtml.Should().Contain("orange").And.Contain("Revised"); | ||
result.Should().Be("Revised"); | ||
} | ||
[Theory, MemberData(nameof(FinalDates))] | ||
public void Should_return_final_status_on_relevant_months(DateTime date) | ||
{ | ||
var resultingHtml = KeyStage4DataStatusHelper.KeyStageDataTag(date); | ||
var result = KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(date); | ||
resultingHtml.Should().Contain("green").And.Contain("Final"); | ||
result.Should().Be("Final"); | ||
} | ||
public static IEnumerable<object[]> ProvisionalDates() | ||
{ | ||
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 9, 3) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 10, 11) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 11, 21) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 12, 14) }; | ||
} | ||
public static IEnumerable<object[]> RevisedDates() | ||
{ | ||
yield return new object[] { new DateTime(DateTime.Now.Year, 1, 3) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year, 2, 11) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year, 3, 21) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year, 4, 14) }; | ||
} | ||
public static IEnumerable<object[]> FinalDates() | ||
{ | ||
yield return new object[] { new DateTime(DateTime.Now.Year - 2, 1, 3) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year - 2, 2, 11) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year, 5, 21) }; | ||
yield return new object[] { new DateTime(DateTime.Now.Year, 6, 14) }; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Dfe.PrepareTransfers.Web/Helpers/KeyStage4DataStatusHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace Dfe.PrepareTransfers.Web.Helpers | ||
{ | ||
public static class KeyStage4DataStatusHelper | ||
{ | ||
public static string KeyStageDataTag(DateTime date) | ||
{ | ||
string status = DetermineKeyStageDataStatus(date); | ||
var colour = status.ToLower() switch | ||
{ | ||
"revised" => "orange", | ||
"final" => "green", | ||
"provisional" => "grey", | ||
_ => string.Empty | ||
}; | ||
return $"<td class='govuk-table__cell'><strong class='govuk-tag govuk-tag--{colour}'>{status}</strong></td>"; | ||
} | ||
|
||
public static string DetermineKeyStageDataStatus(DateTime date) | ||
{ | ||
// Check where and which academic year the tag is in relation too | ||
bool isItCurrentAcademicYear = date.Month < 9 && date.Year == DateTime.Now.Year || | ||
date.Month >= 9 && date.Year == DateTime.Now.Year - 1; | ||
var status = isItCurrentAcademicYear switch | ||
{ | ||
// Rules - KS4 – Provisional October, Revised January; Final April | ||
true => date.Month switch | ||
{ | ||
>= 9 => "Provisional", | ||
<= 4 => "Revised", | ||
> 4 => "Final" | ||
}, | ||
false => "Final" | ||
}; | ||
return status; | ||
} | ||
|
||
public static string KeyStageDataRow() | ||
{ | ||
StringBuilder rowString = new("<tr class='govuk-table__row'>"); | ||
rowString.Append("<th scope='row' class='govuk-table__header'>Status</th>"); | ||
rowString.Append(KeyStageDataTag(DateTime.Now)); | ||
rowString.Append(KeyStageDataTag(DateTime.Now.AddYears(-1))); | ||
rowString.Append(KeyStageDataTag(DateTime.Now.AddYears(-2))); | ||
rowString.Append("</tr>"); | ||
return rowString.ToString(); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters