Skip to content

Commit

Permalink
Merge pull request #2888 from TechnologyEnhancedLearning/Develop/Feat…
Browse files Browse the repository at this point in the history
…ures/TD-4790-Writeunittestsfortagsaddedonoptionalcompetenciesinthesupervisorview

TD-4790 Write unit tests for tags added on optional competencies in the supervisor view
  • Loading branch information
rshrirohit authored Nov 6, 2024
2 parents 25f0913 + 23c3b6e commit d3d98e7
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
options.Add(newItem?.Trim());
if (!string.IsNullOrWhiteSpace(newItem))
{
options.Add(newItem.Trim());
}
return JoinNewlineSeparatedList(options);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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!;
Expand All @@ -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()
Expand All @@ -57,6 +73,43 @@ public void Setup()
pdfService = A.Fake<IPdfService>();
A.CallTo(() => candidateAssessmentDownloadFileService.GetCandidateAssessmentDownloadFileForCentre(A<int>._, A<int>._, A<bool>._))
.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)]
Expand Down Expand Up @@ -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<AppliedFilterViewModel>();
var competencySummaries = new CompetencySummary();
var search = new SearchSupervisorCompetencyViewModel();
var competencies = new List<Competency>
{
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<SupervisorSignOff>();
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<ReviewSelfAssessmentViewModel>();

result.Should().BeViewResult()
.WithViewName("ReviewSelfAssessment")
.ModelAs<ReviewSelfAssessmentViewModel>()
.CompetencyGroups ?.SelectMany(group => group).FirstOrDefault(x => x.Id == 1)?.Optional.Should().Be(true);
result.Should().BeViewResult()
.WithViewName("ReviewSelfAssessment")
.ModelAs<ReviewSelfAssessmentViewModel>()
.CompetencyGroups?.SelectMany(group => group).FirstOrDefault(x => x.Id == 2)?.Optional.Should().Be(false);
}

}
}
Original file line number Diff line number Diff line change
@@ -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 protected]",
string SupervisorName = "Supervisor",
int? supervisorAdminID = 1,
int centreId = 101,
string delegateEmail = "[email protected]",
int? delegateUserID = 1,
bool addedByDelegate = false,
DateTime? removed = null,
string? firstName = null,
string? lastName = null,
string candidateNumber = "DELEGATE",
string candidateEmail = "[email protected]",
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,

};
}

}
}

0 comments on commit d3d98e7

Please sign in to comment.