Skip to content

Commit 0395325

Browse files
committed
Merge branch 'DLS-Release-v1.2.3' into UAT
2 parents e80d7ac + b4e18e6 commit 0395325

File tree

10 files changed

+49
-123
lines changed

10 files changed

+49
-123
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/Register/RegisterDelegateByCentreControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void LearnerInformationPost_updates_tempdata_correctly()
176176
const string answer4 = "answer4";
177177
const string answer5 = "answer5";
178178
const string answer6 = "answer6";
179-
const string professionalRegistrationNumber = "PR123456";
179+
const string professionalRegistrationNumber = "PRN1234";
180180
var model = new LearnerInformationViewModel
181181
{
182182
JobGroup = jobGroupId,

DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/EditDelegateControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void Index_post_returns_view_with_model_error_with_invalid_prn()
175175
result.As<ViewResult>().Model.Should().BeOfType<EditDelegateViewModel>();
176176
AssertModelStateErrorIsExpected(
177177
result,
178-
ErrorMessagesTestHelper.InvalidFormatError
178+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
179179
);
180180
A.CallTo(() => userService.GetDelegateById(A<int>._)).MustNotHaveHappened();
181181
}

DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
namespace DigitalLearningSolutions.Web.Tests.Helpers
22
{
3+
using System.Linq;
34
using DigitalLearningSolutions.Web.Helpers;
4-
using DigitalLearningSolutions.Web.Tests.TestHelpers;
55
using FluentAssertions;
66
using FluentAssertions.Execution;
77
using Microsoft.AspNetCore.Mvc.ModelBinding;
88
using NUnit.Framework;
9-
using System.Linq;
109

1110
public class ProfessionalRegistrationNumberHelperTests
1211
{
@@ -71,7 +70,7 @@ public void ValidateProfessionalRegistrationNumber_does_not_set_errors_when_vali
7170
{
7271
// Given
7372
var state = new ModelStateDictionary();
74-
const string validPrn = "AB123456";
73+
const string validPrn = "abc-123";
7574

7675
// When
7776
ProfessionalRegistrationNumberHelper.ValidateProfessionalRegistrationNumber(
@@ -105,11 +104,22 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not
105104
}
106105
}
107106

108-
[TestCase(null, ErrorMessagesTestHelper.MissingNumberError)]
109-
[TestCase("", ErrorMessagesTestHelper.MissingNumberError)]
110-
[TestCase("01234_", ErrorMessagesTestHelper.InvalidFormatError)]
111-
[TestCase("01234 ", ErrorMessagesTestHelper.InvalidFormatError)]
112-
[TestCase("01234$", ErrorMessagesTestHelper.InvalidFormatError)]
107+
[TestCase(null, "Enter a professional registration number")]
108+
[TestCase("", "Enter a professional registration number")]
109+
[TestCase("123", "Professional registration number must be between 5 and 20 characters")]
110+
[TestCase("0123456789-0123456789", "Professional registration number must be between 5 and 20 characters")]
111+
[TestCase(
112+
"01234_",
113+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
114+
)]
115+
[TestCase(
116+
"01234 ",
117+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
118+
)]
119+
[TestCase(
120+
"01234$",
121+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
122+
)]
113123
public void ValidateProfessionalRegistrationNumber_sets_error_when_prn_is_invalid(
114124
string prn,
115125
string expectedError

DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
namespace DigitalLearningSolutions.Web.Helpers
22
{
3-
4-
using Microsoft.AspNetCore.Mvc.ModelBinding;
5-
using System.Text;
63
using System.Text.RegularExpressions;
4+
using Microsoft.AspNetCore.Mvc.ModelBinding;
75

86
public class ProfessionalRegistrationNumberHelper
97
{
@@ -41,29 +39,24 @@ public static void ValidateProfessionalRegistrationNumber(
4139
modelState.AddModelError("ProfessionalRegistrationNumber", "Enter a professional registration number");
4240
return;
4341
}
44-
const string pattern = @"^(\d{7}|[A-Za-z]{1,2}\d{6}|\d{4,8}|P?\d{5,6}|[C|P]\d{6}|[A-Za-z]?\d{5,6}|L\d{4,6}|\d{2}-[A-Za-z\d]{4,5})$";
42+
43+
if (prn.Length < 5 || prn.Length > 20)
44+
{
45+
modelState.AddModelError(
46+
"ProfessionalRegistrationNumber",
47+
"Professional registration number must be between 5 and 20 characters"
48+
);
49+
}
50+
51+
const string pattern = @"^[a-z\d-]+$";
4552
var rg = new Regex(pattern, RegexOptions.IgnoreCase);
4653
if (!rg.Match(prn).Success)
4754
{
4855
modelState.AddModelError(
4956
"ProfessionalRegistrationNumber",
50-
GetProfessionalRegistrationNumberErrorMessage()
57+
"Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed"
5158
);
5259
}
5360
}
54-
public static string GetProfessionalRegistrationNumberErrorMessage()
55-
{
56-
return @"The format you entered isn’t recognised. Please check and try again.
57-
<br>Valid formats include:
58-
<ul>
59-
<li>7 digits - example, 1234567</li>
60-
<li>1–2 letters followed by 6 digits - example, AB123456</li>
61-
<li>‘P’ followed by 5–6 digits - example, P12345, P123456</li>
62-
<li>‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456</li>
63-
<li>Optional letter followed by 5–6 digits - example, A12345, B123456</li>
64-
<li>‘L’ followed by 4–6 digits - example, L1234, L123456</li>
65-
<li>2 digits, hyphen, then 4–5 alphanumeric characters - example, 12-AB123</li>
66-
</ul>";
67-
}
6861
}
6962
}

DigitalLearningSolutions.Web/Views/MyAccount/EditDetails.cshtml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,8 @@
3232
nameof(Model.Answer5),
3333
nameof(Model.Answer6),
3434
};
35-
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault();
36-
if (professionalRegistrationNumberError == null)
37-
{
35+
3836
<vc:error-summary order-of-property-names="@orderOfPropertyNames" />
39-
}
40-
if (professionalRegistrationNumberError != null)
41-
{
42-
<partial name="_ProfessionalRegistrationNumberError" model=@(professionalRegistrationNumberError.ErrorMessage) />
43-
}
4437
}
4538

4639
<h1 class="nhsuk-heading-xl" id="app-page-heading">Edit details</h1>

DigitalLearningSolutions.Web/Views/Register/LearnerInformation.cshtml

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,18 @@
1111
<div class="nhsuk-grid-row">
1212
<div class="nhsuk-grid-column-full">
1313
@if (errorHasOccurred)
14-
{
15-
16-
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault();
17-
if (professionalRegistrationNumberError == null)
18-
{
19-
<vc:error-summary order-of-property-names="@(new[] {
20-
nameof(Model.JobGroup),
21-
nameof(Model.HasProfessionalRegistrationNumber),
22-
nameof(Model.ProfessionalRegistrationNumber),
23-
nameof(Model.Answer1),
24-
nameof(Model.Answer2),
25-
nameof(Model.Answer3),
26-
nameof(Model.Answer4),
27-
nameof(Model.Answer5),
28-
nameof(Model.Answer6) })" />
29-
}
30-
if (professionalRegistrationNumberError != null)
31-
{
32-
<partial name="_ProfessionalRegistrationNumberError" model=@(professionalRegistrationNumberError.ErrorMessage) />
33-
34-
}
35-
}
14+
{
15+
<vc:error-summary order-of-property-names="@(new[] {
16+
nameof(Model.JobGroup),
17+
nameof(Model.HasProfessionalRegistrationNumber),
18+
nameof(Model.ProfessionalRegistrationNumber),
19+
nameof(Model.Answer1),
20+
nameof(Model.Answer2),
21+
nameof(Model.Answer3),
22+
nameof(Model.Answer4),
23+
nameof(Model.Answer5),
24+
nameof(Model.Answer6) })" />
25+
}
3626

3727
<h1 class="nhsuk-heading-xl">Learner information</h1>
3828

DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
var subject = Model.IsSelfRegistrationOrEdit ? "you" : "they";
1919
var capitalisedSubject = Model.IsSelfRegistrationOrEdit ? "You" : "They";
20-
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault()?.ErrorMessage;
21-
if (ViewData.ModelState.ContainsKey("ProfessionalRegistrationNumber"))
22-
{
23-
ViewData.ModelState["ProfessionalRegistrationNumber"].Errors.Clear();
24-
}
2520
}
2621

2722
<input type="hidden" asp-for="IsSelfRegistrationOrEdit" />
@@ -58,7 +53,7 @@
5853
No
5954
</label>
6055
</div>
61-
56+
6257
<div class="nhsuk-radios__item">
6358
<input name="@nameof(Model.HasProfessionalRegistrationNumber)"
6459
class="nhsuk-radios__input"
@@ -71,16 +66,9 @@
7166
Yes
7267
</label>
7368
</div>
74-
<div class="nhsuk-radios__conditional"
69+
<div class="nhsuk-radios__conditional @(optionYesSelected ? " " : " nhsuk-radios__conditional--hidden") @(professionalRegNumberErrorHasOccurred ? "form-group-wrapper--error" : "" )"
7570
id="@professionalRegConditionalId">
76-
@if (professionalRegistrationNumberError != null)
77-
{
78-
<span class="nhsuk-error-message" id="ProfessionalRegistrationNumber-error">
79-
<span class="nhsuk-u-visually-hidden">Error:</span>
80-
@Html.Raw(professionalRegistrationNumberError)
81-
</span>
82-
}
83-
<vc:text-input asp-for="@nameof(Model.ProfessionalRegistrationNumber)"
71+
<vc:text-input asp-for="@nameof(Model.ProfessionalRegistrationNumber)"
8472
label="Professional Registration Number"
8573
populate-with-current-value="true"
8674
type="text"

DigitalLearningSolutions.Web/Views/Shared/_ProfessionalRegistrationNumberError.cshtml

Lines changed: 0 additions & 17 deletions
This file was deleted.

DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/EditDelegate/Index.cshtml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
<div class="nhsuk-grid-column-full">
1616
@if (errorHasOccurred)
1717
{
18-
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault();
19-
if (professionalRegistrationNumberError == null)
20-
{
21-
<vc:error-summary order-of-property-names="@(new[] {
18+
<vc:error-summary order-of-property-names="@(new[] {
2219
nameof(Model.FirstName),
2320
nameof(Model.LastName),
2421
nameof(Model.CentreSpecificEmail),
@@ -31,11 +28,6 @@
3128
nameof(Model.Answer4),
3229
nameof(Model.Answer5),
3330
nameof(Model.Answer6) })" />
34-
}
35-
if (professionalRegistrationNumberError != null)
36-
{
37-
<partial name="_ProfessionalRegistrationNumberError" model=@(professionalRegistrationNumberError.ErrorMessage) />
38-
}
3931
}
4032

4133
<h1 class="nhsuk-heading-xl">Edit delegate details</h1>

0 commit comments

Comments
 (0)