Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@
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()
{
courseDelegatesService = A.Fake<ICourseDelegatesService>();
courseDelegatesDownloadFileService = A.Fake<ICourseDelegatesDownloadFileService>();

controller = new CourseDelegatesController(courseDelegatesService, courseDelegatesDownloadFileService).WithDefaultContext()
controller = new CourseDelegatesController(courseDelegatesService, courseDelegatesDownloadFileService)
.WithDefaultContext()
.WithMockUser(true, UserCentreId);
}

Expand Down Expand Up @@ -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<CourseDelegate>
.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> { course }, courseDelegate));

var httpRequest = A.Fake<HttpRequest>();
var httpResponse = A.Fake<HttpResponse>();
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<IRequestCookieCollection>());

// When
var result = courseDelegatesController.Index(customisationId);

// Then
using (new AssertionScope())
{
result.As<ViewResult>().Model.As<CourseDelegatesViewModel>().CourseDetails!.FilterBy.Should()
.Be("AccountStatus|Active|true");
result.As<ViewResult>().Model.As<CourseDelegatesViewModel>().CourseDetails!.Delegates.Should()
.HaveCount(1);

A.CallTo(
() => courseDelegatesService.GetCoursesAndCourseDelegatesForCentre(
UserCentreId,
null,
customisationId
)
)
.MustHaveHappened();
}
}

[Test]
public void AllCourseDelegates_gets_courses_for_user_details_only()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +50,8 @@ public IActionResult Index(
filterBy,
filterValue,
Request,
CourseDelegatesFilterCookieName
CourseDelegatesFilterCookieName,
CourseDelegateAccountStatusFilterOptions.Active.FilterValue
);

var centreId = User.GetCentreId();
Expand Down
7 changes: 7 additions & 0 deletions DigitalLearningSolutions.Web/Helpers/GenericSortingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dt class="nhsuk-summary-list__key">
Delegate ID
</dt>
<dd class="nhsuk-summary-list__value">
<dd class="nhsuk-summary-list__value" data-name-for-sorting="delegate-id">
@Model.CandidateNumber
</dd>
</div>
Expand Down