Skip to content

Commit d3d98e7

Browse files
authored
Merge pull request #2888 from TechnologyEnhancedLearning/Develop/Features/TD-4790-Writeunittestsfortagsaddedonoptionalcompetenciesinthesupervisorview
TD-4790 Write unit tests for tags added on optional competencies in the supervisor view
2 parents 25f0913 + 23c3b6e commit d3d98e7

File tree

3 files changed

+257
-2
lines changed

3 files changed

+257
-2
lines changed

DigitalLearningSolutions.Data/Helpers/NewlineSeparatedStringListHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public static string RemoveStringFromNewlineSeparatedList(string list, int index
1717
public static string AddStringToNewlineSeparatedList(string? list, string newItem)
1818
{
1919
var options = list != null ? SplitNewlineSeparatedList(list) : new List<string>();
20-
options.Add(newItem?.Trim());
20+
if (!string.IsNullOrWhiteSpace(newItem))
21+
{
22+
options.Add(newItem.Trim());
23+
}
2124
return JoinNewlineSeparatedList(options);
2225
}
2326

DigitalLearningSolutions.Web.Tests/Controllers/SupervisorController/SupervisorControllerTests.cs

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
namespace DigitalLearningSolutions.Web.Tests.Controllers.Support
22
{
3-
3+
using DigitalLearningSolutions.Data.Models.SelfAssessments;
44
using DigitalLearningSolutions.Data.Utilities;
55
using DigitalLearningSolutions.Web.Controllers.SupervisorController;
66
using DigitalLearningSolutions.Web.Services;
7+
using DigitalLearningSolutions.Web.Tests.ControllerHelpers;
8+
using DigitalLearningSolutions.Web.Tests.TestHelpers;
9+
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
10+
using DigitalLearningSolutions.Web.ViewModels.Supervisor;
711
using FakeItEasy;
12+
using FluentAssertions;
13+
using FluentAssertions.AspNetCore.Mvc;
814
using GDS.MultiPageFormData;
15+
using Microsoft.AspNetCore.Http;
916
using Microsoft.AspNetCore.Mvc;
1017
using Microsoft.Extensions.Configuration;
1118
using Microsoft.Extensions.Logging;
1219
using NUnit.Framework;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Security.Claims;
1323

1424
public class SupervisorControllerTests
1525
{
26+
private const int DelegateUserId = 11;
27+
private const int SelfAssessmentId = 1;
28+
private const int CentreId = 2;
29+
public const int AdminId = 7;
30+
public const string EmailAddress = "email";
1631
private ISupervisorService supervisorService = null!;
1732
private ICommonService commonService = null!;
1833
private IFrameworkNotificationService frameworkNotificationService = null!;
@@ -32,6 +47,7 @@ public class SupervisorControllerTests
3247
private IClockUtility clockUtility = null!;
3348
private ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService = null!;
3449
private IPdfService pdfService = null!;
50+
private SupervisorController controller = null!;
3551

3652
[SetUp]
3753
public void Setup()
@@ -57,6 +73,43 @@ public void Setup()
5773
pdfService = A.Fake<IPdfService>();
5874
A.CallTo(() => candidateAssessmentDownloadFileService.GetCandidateAssessmentDownloadFileForCentre(A<int>._, A<int>._, A<bool>._))
5975
.Returns(new byte[] { });
76+
77+
var user = new ClaimsPrincipal(
78+
new ClaimsIdentity(
79+
new[]
80+
{
81+
new Claim("UserCentreID", CentreId.ToString()),
82+
new Claim("UserId", DelegateUserId.ToString()),
83+
new Claim("UserAdminId", AdminId.ToString())
84+
},
85+
"mock"
86+
)
87+
);
88+
89+
controller = new SupervisorController(
90+
supervisorService,
91+
commonService,
92+
frameworkNotificationService,
93+
selfAssessmentService,
94+
frameworkService,
95+
configService,
96+
centreRegistrationPromptsService,
97+
userService,
98+
logger,
99+
config,
100+
searchSortFilterPaginateService,
101+
multiPageFormService,
102+
registrationService,
103+
centresService,
104+
emailGenerationService,
105+
emailService,
106+
candidateAssessmentDownloadFileService,
107+
clockUtility,
108+
pdfService
109+
);
110+
controller.ControllerContext = new ControllerContext
111+
{ HttpContext = new DefaultHttpContext { User = user } };
112+
controller = controller.WithMockTempData();
60113
}
61114

62115
[TestCase(1, "test", "Digital Capability Self Assessment Deprecated", 1)]
@@ -97,5 +150,63 @@ public void ExportCandidateAssessment_should_return_file_object_with_file_name_i
97150
Assert.AreEqual(expectedFileName, result!.FileDownloadName);
98151
});
99152
}
153+
154+
155+
[Test]
156+
public void ReviewDelegateSelfAssessment_Should_Return_View_With_Optional_Competency()
157+
{
158+
// Given
159+
int candidateAssessmentId = 1;
160+
int supervisorDelegateId = 2;
161+
var superviseDelegate = SupervisorTagTestHelper.CreateDefaultSupervisorDelegateDetail();
162+
var delegateSelfAssessment = SupervisorTagTestHelper.CreateDefaultDelegateSelfAssessment();
163+
var appliedFilterViewModel = new List<AppliedFilterViewModel>();
164+
var competencySummaries = new CompetencySummary();
165+
var search = new SearchSupervisorCompetencyViewModel();
166+
var competencies = new List<Competency>
167+
{
168+
new Competency { CompetencyGroup = "A", Id = 1, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = true },
169+
new Competency { CompetencyGroup = "A", Id = 2, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = false },
170+
};
171+
var expectedCompetencyGroups = competencies.GroupBy(c => c.CompetencyGroup).ToList();
172+
var supervisorSignOffs = new List<SupervisorSignOff>();
173+
var expectedModel = new ReviewSelfAssessmentViewModel()
174+
{
175+
SupervisorDelegateDetail = superviseDelegate,
176+
DelegateSelfAssessment = delegateSelfAssessment,
177+
CompetencyGroups = expectedCompetencyGroups,
178+
IsSupervisorResultsReviewed = delegateSelfAssessment.IsSupervisorResultsReviewed,
179+
SearchViewModel = search,
180+
CandidateAssessmentId = candidateAssessmentId,
181+
ExportToExcelHide = delegateSelfAssessment.SupervisorRoleTitle?.Contains("Assessor") ?? false,
182+
SupervisorSignOffs = supervisorSignOffs,
183+
CompetencySummaries = competencySummaries
184+
};
185+
var loggedInAdmin = UserTestHelper.GetDefaultAdminEntity();
186+
A.CallTo(() => userService.GetAdminById(loggedInAdmin.AdminAccount.Id)).Returns(loggedInAdmin);
187+
188+
A.CallTo(() => supervisorService.GetSupervisorDelegateDetailsById(supervisorDelegateId, AdminId, 0))
189+
.Returns(superviseDelegate);
190+
A.CallTo(() => supervisorService.GetSelfAssessmentByCandidateAssessmentId(candidateAssessmentId, AdminId))
191+
.Returns(delegateSelfAssessment);
192+
A.CallTo(() => selfAssessmentService.GetMostRecentResults(SelfAssessmentId, DelegateUserId))
193+
.Returns(competencies);
194+
195+
// When
196+
var result = controller.ReviewDelegateSelfAssessment(supervisorDelegateId, candidateAssessmentId, SelfAssessmentId);
197+
198+
// Then
199+
result.Should().BeViewResult().ModelAs<ReviewSelfAssessmentViewModel>();
200+
201+
result.Should().BeViewResult()
202+
.WithViewName("ReviewSelfAssessment")
203+
.ModelAs<ReviewSelfAssessmentViewModel>()
204+
.CompetencyGroups ?.SelectMany(group => group).FirstOrDefault(x => x.Id == 1)?.Optional.Should().Be(true);
205+
result.Should().BeViewResult()
206+
.WithViewName("ReviewSelfAssessment")
207+
.ModelAs<ReviewSelfAssessmentViewModel>()
208+
.CompetencyGroups?.SelectMany(group => group).FirstOrDefault(x => x.Id == 2)?.Optional.Should().Be(false);
209+
}
210+
100211
}
101212
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using DigitalLearningSolutions.Data.Models.Supervisor;
2+
using DigitalLearningSolutions.Data.Utilities;
3+
using System;
4+
5+
namespace DigitalLearningSolutions.Web.Tests.TestHelpers
6+
{
7+
public static class SupervisorTagTestHelper
8+
{
9+
private static readonly IClockUtility ClockUtility = new ClockUtility();
10+
11+
public static SupervisorDelegateDetail CreateDefaultSupervisorDelegateDetail(
12+
int id =1,
13+
string supervisorEmail = "[email protected]",
14+
string SupervisorName = "Supervisor",
15+
int? supervisorAdminID = 1,
16+
int centreId = 101,
17+
string delegateEmail = "[email protected]",
18+
int? delegateUserID = 1,
19+
bool addedByDelegate = false,
20+
DateTime? removed = null,
21+
string? firstName = null,
22+
string? lastName = null,
23+
string candidateNumber = "DELEGATE",
24+
string candidateEmail = "[email protected]",
25+
string? jobGroupName =null,
26+
string? customPrompt1 =null,
27+
string? answer1 = null,
28+
string? customPrompt2 = null,
29+
string? answer2 = null,
30+
string? customPrompt3 = null,
31+
string? answer3 = null,
32+
string? customPrompt4 = null,
33+
string? answer4 = null,
34+
string? customPrompt5 = null,
35+
string? answer5 = null,
36+
string? customPrompt6 = null,
37+
string? answer6 = null,
38+
string? supervisorName = null,
39+
int candidateAssessmentCount =0,
40+
Guid? InviteHash =null,
41+
bool delegateIsNominatedSupervisor = false,
42+
bool delegateIsSupervisor = false,
43+
string professionalRegistrationNumber = "string.Empty",
44+
int? delegateID = 0,
45+
bool? active =false
46+
)
47+
{
48+
return new SupervisorDelegateDetail
49+
{
50+
ID = id,
51+
Active = active,
52+
FirstName = firstName,
53+
LastName = lastName,
54+
CentreId = centreId,
55+
CandidateAssessmentCount = candidateAssessmentCount,
56+
CandidateNumber = candidateNumber,
57+
CandidateEmail = candidateEmail,
58+
Answer1 = answer1,
59+
Answer2 = answer2,
60+
Answer3 = answer3,
61+
Answer4 = answer4,
62+
Answer5 = answer5,
63+
Answer6 = answer6,
64+
JobGroupName = jobGroupName,
65+
DelegateEmail = delegateEmail,
66+
DelegateID = delegateID,
67+
DelegateIsNominatedSupervisor= delegateIsNominatedSupervisor,
68+
DelegateIsSupervisor= delegateIsSupervisor,
69+
DelegateUserID = delegateUserID,
70+
SupervisorAdminID = supervisorAdminID,
71+
SupervisorEmail= supervisorEmail,
72+
SupervisorName = supervisorName,
73+
CustomPrompt1 = customPrompt1,
74+
CustomPrompt2 = customPrompt2,
75+
CustomPrompt3 = customPrompt3,
76+
CustomPrompt4 = customPrompt4,
77+
CustomPrompt5 = customPrompt5,
78+
CustomPrompt6 = customPrompt6,
79+
Removed = removed,
80+
InviteHash = InviteHash,
81+
ProfessionalRegistrationNumber = professionalRegistrationNumber,
82+
83+
};
84+
}
85+
86+
public static DelegateSelfAssessment CreateDefaultDelegateSelfAssessment(
87+
int id = 1,
88+
int selfAssessmentID =6,
89+
int delegateUserID =1,
90+
string? roleName =null,
91+
bool supervisorSelfAssessmentReview =false,
92+
bool supervisorResultsReview = false,
93+
string? supervisorRoleTitle = "Assessor",
94+
DateTime? signedOffDate =null,
95+
bool signedOff = false,
96+
DateTime? completeByDate=null,
97+
int launchCount = 0,
98+
DateTime? completedDate =null,
99+
string? professionalGroup = null,
100+
string? questionLabel = null,
101+
string? descriptionLabel = null,
102+
string? reviewerCommentsLabel = null,
103+
string? subGroup = null,
104+
string? roleProfile = null,
105+
int signOffRequested =1,
106+
int resultsVerificationRequests =1,
107+
bool isSupervisorResultsReviewed =false,
108+
bool isAssignedToSupervisor = false,
109+
bool nonReportable = false
110+
)
111+
{
112+
return new DelegateSelfAssessment {
113+
ID = id,
114+
SelfAssessmentID = selfAssessmentID,
115+
DelegateUserID = delegateUserID,
116+
ResultsVerificationRequests = resultsVerificationRequests,
117+
ReviewerCommentsLabel = reviewerCommentsLabel,
118+
SubGroup = subGroup,
119+
RoleProfile = roleProfile,
120+
SignOffRequested = signOffRequested,
121+
SupervisorResultsReview = supervisorResultsReview,
122+
SupervisorSelfAssessmentReview= supervisorSelfAssessmentReview,
123+
SignedOff = signedOff,
124+
CompleteByDate = completeByDate,
125+
LaunchCount = launchCount,
126+
CompletedDate = completedDate,
127+
SignedOffDate = signedOffDate,
128+
ProfessionalGroup = professionalGroup,
129+
QuestionLabel = questionLabel,
130+
DescriptionLabel = descriptionLabel,
131+
IsAssignedToSupervisor = isAssignedToSupervisor,
132+
NonReportable = nonReportable,
133+
IsSupervisorResultsReviewed= isSupervisorResultsReviewed,
134+
RoleName = roleName,
135+
SupervisorRoleTitle = supervisorRoleTitle,
136+
137+
};
138+
}
139+
140+
}
141+
}

0 commit comments

Comments
 (0)