diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/CourseDelegatesControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/CourseDelegatesControllerTests.cs index 3aaa74999e..d5b11a1ad3 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/CourseDelegatesControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/CourseDelegatesControllerTests.cs @@ -7,16 +7,22 @@ using DigitalLearningSolutions.Data.Services; using DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates; using DigitalLearningSolutions.Web.Tests.ControllerHelpers; + using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates.CourseDelegates; using FakeItEasy; + using FizzWare.NBuilder; + using FluentAssertions; using FluentAssertions.AspNetCore.Mvc; + using FluentAssertions.Execution; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; using NUnit.Framework; public class CourseDelegatesControllerTests { private const int UserCentreId = 3; private CourseDelegatesController controller = null!; - private ICourseDelegatesService courseDelegatesService = null!; private ICourseDelegatesDownloadFileService courseDelegatesDownloadFileService = null!; + private ICourseDelegatesService courseDelegatesService = null!; [SetUp] public void SetUp() @@ -24,7 +30,8 @@ public void SetUp() courseDelegatesService = A.Fake(); courseDelegatesDownloadFileService = A.Fake(); - controller = new CourseDelegatesController(courseDelegatesService, courseDelegatesDownloadFileService).WithDefaultContext() + controller = new CourseDelegatesController(courseDelegatesService, courseDelegatesDownloadFileService) + .WithDefaultContext() .WithMockUser(true, UserCentreId); } @@ -57,6 +64,65 @@ public void Index_returns_Not_Found_when_service_returns_null() result.Should().BeNotFoundResult(); } + [Test] + public void Index_should_default_to_Active_filter_and_return_active_course_delegates() + { + // Given + const int customisationId = 2; + var course = new Course { CustomisationId = customisationId, Active = true }; + var courseDelegate = Builder + .CreateListOfSize(2) + .TheFirst(1) + .With(c => c.Active = false) + .TheLast(1) + .With(c => c.Active = true) + .Build(); + A.CallTo( + () => courseDelegatesService.GetCoursesAndCourseDelegatesForCentre( + UserCentreId, + null, + customisationId + ) + ) + .Returns(new CourseDelegatesData(customisationId, new List { course }, courseDelegate)); + + var httpRequest = A.Fake(); + var httpResponse = A.Fake(); + const string cookieName = "CourseDelegatesFilter"; + const string cookieValue = "AccountStatus|Active|true"; + + var courseDelegatesController = new CourseDelegatesController( + courseDelegatesService, + courseDelegatesDownloadFileService + ) + .WithMockHttpContext(httpRequest, cookieName, cookieValue, httpResponse) + .WithMockUser(true, UserCentreId) + .WithMockTempData(); + + A.CallTo(() => httpRequest.Cookies).Returns(A.Fake()); + + // When + var result = courseDelegatesController.Index(customisationId); + + // Then + using (new AssertionScope()) + { + result.As().Model.As().CourseDetails!.FilterBy.Should() + .Be("AccountStatus|Active|true"); + result.As().Model.As().CourseDetails!.Delegates.Should() + .HaveCount(1); + + A.CallTo( + () => courseDelegatesService.GetCoursesAndCourseDelegatesForCentre( + UserCentreId, + null, + customisationId + ) + ) + .MustHaveHappened(); + } + } + [Test] public void AllCourseDelegates_gets_courses_for_user_details_only() { diff --git a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/CourseDelegatesController.cs b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/CourseDelegatesController.cs index 90831f7ac8..7dba22c8df 100644 --- a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/CourseDelegatesController.cs +++ b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/CourseDelegatesController.cs @@ -6,6 +6,7 @@ using DigitalLearningSolutions.Data.Services; using DigitalLearningSolutions.Web.Attributes; using DigitalLearningSolutions.Web.Helpers; + using DigitalLearningSolutions.Web.Helpers.FilterOptions; using DigitalLearningSolutions.Web.Models.Enums; using DigitalLearningSolutions.Web.ServiceFilter; using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage; @@ -49,7 +50,8 @@ public IActionResult Index( filterBy, filterValue, Request, - CourseDelegatesFilterCookieName + CourseDelegatesFilterCookieName, + CourseDelegateAccountStatusFilterOptions.Active.FilterValue ); var centreId = User.GetCentreId(); diff --git a/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs b/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs index fce4ba4702..d93f0ba9f6 100644 --- a/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs @@ -163,6 +163,13 @@ public class CourseDelegatesSortByOption : Enumeration nameof(CourseDelegate.PassRate) ); + public static readonly CourseDelegatesSortByOption DelegateId = new CourseDelegatesSortByOption( + 7, + nameof(DelegateId), + "Delegate ID", + nameof(CourseDelegate.CandidateNumber) + ); + public readonly string DisplayText; public readonly string PropertyName; diff --git a/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts b/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts index 094f5a6244..07a97e0709 100644 --- a/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts +++ b/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts @@ -72,6 +72,8 @@ export function getSortValue( return parseInt(getElementText(searchableElement, 'faq-weighting'), 10); case 'FaqId': return parseInt(getElementText(searchableElement, 'faq-id'), 10); + case 'CandidateNumber': + return getElementText(searchableElement, 'delegate-id').toLocaleLowerCase(); default: return ''; } diff --git a/DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/CourseDelegates/_SearchableCourseDelegateCard.cshtml b/DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/CourseDelegates/_SearchableCourseDelegateCard.cshtml index 01110240d9..09630c95cc 100644 --- a/DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/CourseDelegates/_SearchableCourseDelegateCard.cshtml +++ b/DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/CourseDelegates/_SearchableCourseDelegateCard.cshtml @@ -18,7 +18,7 @@
Delegate ID
-
+
@Model.CandidateNumber