From 54b14f6b1ffe8a27bb6bedad3bad4be30f59702c Mon Sep 17 00:00:00 2001 From: Martin Wilkins Date: Fri, 4 Feb 2022 16:47:40 +0000 Subject: [PATCH 1/4] HEEDLS-564 Add default active filter and sort CN --- .../TrackingSystem/Delegates/CourseDelegatesController.cs | 4 +++- .../Helpers/GenericSortingHelper.cs | 7 +++++++ .../Scripts/searchSortFilterAndPaginate/sort.ts | 2 ++ .../CourseDelegates/_SearchableCourseDelegateCard.cshtml | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) 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..ae16b8484f 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 CandidateNumber = new CourseDelegatesSortByOption( + 7, + nameof(CandidateNumber), + "Candidate number", + 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..91ac15b4a0 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, 'candidate-number').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..25ca385100 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
From 8ec24ffe596809d8225827186dd35a63f5904c7e Mon Sep 17 00:00:00 2001 From: Martin Wilkins Date: Fri, 4 Feb 2022 17:18:54 +0000 Subject: [PATCH 2/4] HEEDLS-564 Add filter test --- .../CourseDelegatesControllerTests.cs | 70 ++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) 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() { From 40d9ef386047eb92cae48547018e1f4823d11ed4 Mon Sep 17 00:00:00 2001 From: Martin Wilkins Date: Mon, 7 Feb 2022 10:40:40 +0000 Subject: [PATCH 3/4] Heedls-564 Set CN display text to Delegate ID --- DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs b/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs index ae16b8484f..1c01b1cc17 100644 --- a/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs @@ -166,7 +166,7 @@ public class CourseDelegatesSortByOption : Enumeration public static readonly CourseDelegatesSortByOption CandidateNumber = new CourseDelegatesSortByOption( 7, nameof(CandidateNumber), - "Candidate number", + "Delegate ID", nameof(CourseDelegate.CandidateNumber) ); From feaf6c7b53d3dedb5ebe61bec3f6c87cd9445ff8 Mon Sep 17 00:00:00 2001 From: Martin Wilkins Date: Tue, 8 Feb 2022 16:36:34 +0000 Subject: [PATCH 4/4] HEEDLS-564 TLR Markups --- DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs | 4 ++-- .../Scripts/searchSortFilterAndPaginate/sort.ts | 2 +- .../CourseDelegates/_SearchableCourseDelegateCard.cshtml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs b/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs index 1c01b1cc17..d93f0ba9f6 100644 --- a/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs @@ -163,9 +163,9 @@ public class CourseDelegatesSortByOption : Enumeration nameof(CourseDelegate.PassRate) ); - public static readonly CourseDelegatesSortByOption CandidateNumber = new CourseDelegatesSortByOption( + public static readonly CourseDelegatesSortByOption DelegateId = new CourseDelegatesSortByOption( 7, - nameof(CandidateNumber), + nameof(DelegateId), "Delegate ID", nameof(CourseDelegate.CandidateNumber) ); diff --git a/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts b/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts index 91ac15b4a0..07a97e0709 100644 --- a/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts +++ b/DigitalLearningSolutions.Web/Scripts/searchSortFilterAndPaginate/sort.ts @@ -73,7 +73,7 @@ export function getSortValue( case 'FaqId': return parseInt(getElementText(searchableElement, 'faq-id'), 10); case 'CandidateNumber': - return getElementText(searchableElement, 'candidate-number').toLocaleLowerCase(); + 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 25ca385100..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