diff --git a/DigitalLearningSolutions.Data/Helpers/NewlineSeparatedStringListHelper.cs b/DigitalLearningSolutions.Data/Helpers/NewlineSeparatedStringListHelper.cs index 12dd4ff09d..69e16bf10f 100644 --- a/DigitalLearningSolutions.Data/Helpers/NewlineSeparatedStringListHelper.cs +++ b/DigitalLearningSolutions.Data/Helpers/NewlineSeparatedStringListHelper.cs @@ -17,7 +17,10 @@ public static string RemoveStringFromNewlineSeparatedList(string list, int index public static string AddStringToNewlineSeparatedList(string? list, string newItem) { var options = list != null ? SplitNewlineSeparatedList(list) : new List(); - options.Add(newItem?.Trim()); + if (!string.IsNullOrWhiteSpace(newItem)) + { + options.Add(newItem.Trim()); + } return JoinNewlineSeparatedList(options); } diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/SupervisorController/SupervisorControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/SupervisorController/SupervisorControllerTests.cs index 4b7163e7b9..67e873633b 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/SupervisorController/SupervisorControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/SupervisorController/SupervisorControllerTests.cs @@ -1,18 +1,33 @@ namespace DigitalLearningSolutions.Web.Tests.Controllers.Support { - + using DigitalLearningSolutions.Data.Models.SelfAssessments; using DigitalLearningSolutions.Data.Utilities; using DigitalLearningSolutions.Web.Controllers.SupervisorController; using DigitalLearningSolutions.Web.Services; + using DigitalLearningSolutions.Web.Tests.ControllerHelpers; + using DigitalLearningSolutions.Web.Tests.TestHelpers; + using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage; + using DigitalLearningSolutions.Web.ViewModels.Supervisor; using FakeItEasy; + using FluentAssertions; + using FluentAssertions.AspNetCore.Mvc; using GDS.MultiPageFormData; + using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using NUnit.Framework; + using System.Collections.Generic; + using System.Linq; + using System.Security.Claims; public class SupervisorControllerTests { + private const int DelegateUserId = 11; + private const int SelfAssessmentId = 1; + private const int CentreId = 2; + public const int AdminId = 7; + public const string EmailAddress = "email"; private ISupervisorService supervisorService = null!; private ICommonService commonService = null!; private IFrameworkNotificationService frameworkNotificationService = null!; @@ -32,6 +47,7 @@ public class SupervisorControllerTests private IClockUtility clockUtility = null!; private ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService = null!; private IPdfService pdfService = null!; + private SupervisorController controller = null!; [SetUp] public void Setup() @@ -57,6 +73,43 @@ public void Setup() pdfService = A.Fake(); A.CallTo(() => candidateAssessmentDownloadFileService.GetCandidateAssessmentDownloadFileForCentre(A._, A._, A._)) .Returns(new byte[] { }); + + var user = new ClaimsPrincipal( + new ClaimsIdentity( + new[] + { + new Claim("UserCentreID", CentreId.ToString()), + new Claim("UserId", DelegateUserId.ToString()), + new Claim("UserAdminId", AdminId.ToString()) + }, + "mock" + ) + ); + + controller = new SupervisorController( + supervisorService, + commonService, + frameworkNotificationService, + selfAssessmentService, + frameworkService, + configService, + centreRegistrationPromptsService, + userService, + logger, + config, + searchSortFilterPaginateService, + multiPageFormService, + registrationService, + centresService, + emailGenerationService, + emailService, + candidateAssessmentDownloadFileService, + clockUtility, + pdfService + ); + controller.ControllerContext = new ControllerContext + { HttpContext = new DefaultHttpContext { User = user } }; + controller = controller.WithMockTempData(); } [TestCase(1, "test", "Digital Capability Self Assessment Deprecated", 1)] @@ -97,5 +150,63 @@ public void ExportCandidateAssessment_should_return_file_object_with_file_name_i Assert.AreEqual(expectedFileName, result!.FileDownloadName); }); } + + + [Test] + public void ReviewDelegateSelfAssessment_Should_Return_View_With_Optional_Competency() + { + // Given + int candidateAssessmentId = 1; + int supervisorDelegateId = 2; + var superviseDelegate = SupervisorTagTestHelper.CreateDefaultSupervisorDelegateDetail(); + var delegateSelfAssessment = SupervisorTagTestHelper.CreateDefaultDelegateSelfAssessment(); + var appliedFilterViewModel = new List(); + var competencySummaries = new CompetencySummary(); + var search = new SearchSupervisorCompetencyViewModel(); + var competencies = new List + { + new Competency { CompetencyGroup = "A", Id = 1, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = true }, + new Competency { CompetencyGroup = "A", Id = 2, CompetencyGroupID = 1,SelfAssessmentStructureId=1, Optional = false }, + }; + var expectedCompetencyGroups = competencies.GroupBy(c => c.CompetencyGroup).ToList(); + var supervisorSignOffs = new List(); + var expectedModel = new ReviewSelfAssessmentViewModel() + { + SupervisorDelegateDetail = superviseDelegate, + DelegateSelfAssessment = delegateSelfAssessment, + CompetencyGroups = expectedCompetencyGroups, + IsSupervisorResultsReviewed = delegateSelfAssessment.IsSupervisorResultsReviewed, + SearchViewModel = search, + CandidateAssessmentId = candidateAssessmentId, + ExportToExcelHide = delegateSelfAssessment.SupervisorRoleTitle?.Contains("Assessor") ?? false, + SupervisorSignOffs = supervisorSignOffs, + CompetencySummaries = competencySummaries + }; + var loggedInAdmin = UserTestHelper.GetDefaultAdminEntity(); + A.CallTo(() => userService.GetAdminById(loggedInAdmin.AdminAccount.Id)).Returns(loggedInAdmin); + + A.CallTo(() => supervisorService.GetSupervisorDelegateDetailsById(supervisorDelegateId, AdminId, 0)) + .Returns(superviseDelegate); + A.CallTo(() => supervisorService.GetSelfAssessmentByCandidateAssessmentId(candidateAssessmentId, AdminId)) + .Returns(delegateSelfAssessment); + A.CallTo(() => selfAssessmentService.GetMostRecentResults(SelfAssessmentId, DelegateUserId)) + .Returns(competencies); + + // When + var result = controller.ReviewDelegateSelfAssessment(supervisorDelegateId, candidateAssessmentId, SelfAssessmentId); + + // Then + result.Should().BeViewResult().ModelAs(); + + result.Should().BeViewResult() + .WithViewName("ReviewSelfAssessment") + .ModelAs() + .CompetencyGroups ?.SelectMany(group => group).FirstOrDefault(x => x.Id == 1)?.Optional.Should().Be(true); + result.Should().BeViewResult() + .WithViewName("ReviewSelfAssessment") + .ModelAs() + .CompetencyGroups?.SelectMany(group => group).FirstOrDefault(x => x.Id == 2)?.Optional.Should().Be(false); + } + } } diff --git a/DigitalLearningSolutions.Web.Tests/TestHelpers/SupervisorTagTestHelper.cs b/DigitalLearningSolutions.Web.Tests/TestHelpers/SupervisorTagTestHelper.cs new file mode 100644 index 0000000000..e55cc5fe1a --- /dev/null +++ b/DigitalLearningSolutions.Web.Tests/TestHelpers/SupervisorTagTestHelper.cs @@ -0,0 +1,141 @@ +using DigitalLearningSolutions.Data.Models.Supervisor; +using DigitalLearningSolutions.Data.Utilities; +using System; + +namespace DigitalLearningSolutions.Web.Tests.TestHelpers +{ + public static class SupervisorTagTestHelper + { + private static readonly IClockUtility ClockUtility = new ClockUtility(); + + public static SupervisorDelegateDetail CreateDefaultSupervisorDelegateDetail( + int id =1, + string supervisorEmail = "email@test.com", + string SupervisorName = "Supervisor", + int? supervisorAdminID = 1, + int centreId = 101, + string delegateEmail = "email@test.com", + int? delegateUserID = 1, + bool addedByDelegate = false, + DateTime? removed = null, + string? firstName = null, + string? lastName = null, + string candidateNumber = "DELEGATE", + string candidateEmail = "email@test.com", + string? jobGroupName =null, + string? customPrompt1 =null, + string? answer1 = null, + string? customPrompt2 = null, + string? answer2 = null, + string? customPrompt3 = null, + string? answer3 = null, + string? customPrompt4 = null, + string? answer4 = null, + string? customPrompt5 = null, + string? answer5 = null, + string? customPrompt6 = null, + string? answer6 = null, + string? supervisorName = null, + int candidateAssessmentCount =0, + Guid? InviteHash =null, + bool delegateIsNominatedSupervisor = false, + bool delegateIsSupervisor = false, + string professionalRegistrationNumber = "string.Empty", + int? delegateID = 0, + bool? active =false + ) + { + return new SupervisorDelegateDetail + { + ID = id, + Active = active, + FirstName = firstName, + LastName = lastName, + CentreId = centreId, + CandidateAssessmentCount = candidateAssessmentCount, + CandidateNumber = candidateNumber, + CandidateEmail = candidateEmail, + Answer1 = answer1, + Answer2 = answer2, + Answer3 = answer3, + Answer4 = answer4, + Answer5 = answer5, + Answer6 = answer6, + JobGroupName = jobGroupName, + DelegateEmail = delegateEmail, + DelegateID = delegateID, + DelegateIsNominatedSupervisor= delegateIsNominatedSupervisor, + DelegateIsSupervisor= delegateIsSupervisor, + DelegateUserID = delegateUserID, + SupervisorAdminID = supervisorAdminID, + SupervisorEmail= supervisorEmail, + SupervisorName = supervisorName, + CustomPrompt1 = customPrompt1, + CustomPrompt2 = customPrompt2, + CustomPrompt3 = customPrompt3, + CustomPrompt4 = customPrompt4, + CustomPrompt5 = customPrompt5, + CustomPrompt6 = customPrompt6, + Removed = removed, + InviteHash = InviteHash, + ProfessionalRegistrationNumber = professionalRegistrationNumber, + + }; + } + + public static DelegateSelfAssessment CreateDefaultDelegateSelfAssessment( + int id = 1, + int selfAssessmentID =6, + int delegateUserID =1, + string? roleName =null, + bool supervisorSelfAssessmentReview =false, + bool supervisorResultsReview = false, + string? supervisorRoleTitle = "Assessor", + DateTime? signedOffDate =null, + bool signedOff = false, + DateTime? completeByDate=null, + int launchCount = 0, + DateTime? completedDate =null, + string? professionalGroup = null, + string? questionLabel = null, + string? descriptionLabel = null, + string? reviewerCommentsLabel = null, + string? subGroup = null, + string? roleProfile = null, + int signOffRequested =1, + int resultsVerificationRequests =1, + bool isSupervisorResultsReviewed =false, + bool isAssignedToSupervisor = false, + bool nonReportable = false + ) + { + return new DelegateSelfAssessment { + ID = id, + SelfAssessmentID = selfAssessmentID, + DelegateUserID = delegateUserID, + ResultsVerificationRequests = resultsVerificationRequests, + ReviewerCommentsLabel = reviewerCommentsLabel, + SubGroup = subGroup, + RoleProfile = roleProfile, + SignOffRequested = signOffRequested, + SupervisorResultsReview = supervisorResultsReview, + SupervisorSelfAssessmentReview= supervisorSelfAssessmentReview, + SignedOff = signedOff, + CompleteByDate = completeByDate, + LaunchCount = launchCount, + CompletedDate = completedDate, + SignedOffDate = signedOffDate, + ProfessionalGroup = professionalGroup, + QuestionLabel = questionLabel, + DescriptionLabel = descriptionLabel, + IsAssignedToSupervisor = isAssignedToSupervisor, + NonReportable = nonReportable, + IsSupervisorResultsReviewed= isSupervisorResultsReviewed, + RoleName = roleName, + SupervisorRoleTitle = supervisorRoleTitle, + + }; + } + + } +}