Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d3eb901
HEEDLS-532 Initial no javascript filtering
AlexJacksonDS Jun 25, 2021
90d9800
HEEDLS-532 Add some styling to filters
AlexJacksonDS Jun 25, 2021
9c154af
HEEDLS-532 Working filter and basic applied filter display
AlexJacksonDS Jun 28, 2021
9081857
HEEDLS-532 Add applied filter display and clear filters
AlexJacksonDS Jun 29, 2021
963f7b5
HEEDLS-532 Populate categories filter from database
AlexJacksonDS Jun 29, 2021
7afc867
HEEDLS-532 Add unit tests for new code
AlexJacksonDS Jun 29, 2021
69618f6
HEEDLS-532 Fix layout for mobile
AlexJacksonDS Jun 29, 2021
d7071af
HEEDLS-532 Improve screen reader reading
AlexJacksonDS Jun 29, 2021
3d40a9b
HEEDLS-532 Break up large linq statement
AlexJacksonDS Jun 30, 2021
270b15c
Merge branch 'master' into HEEDLS-532-admins-no-js-filtering
AlexJacksonDS Jun 30, 2021
32d984b
HEEDLS-532 Fix naming of IConfiguration
AlexJacksonDS Jun 30, 2021
a9baaf7
HEEDLS-416 Increase spacing after number of admins view component
AlexJacksonDS Jun 30, 2021
1c20c0e
HEEDLS-532 Change filters IEnumerable to a model
AlexJacksonDS Jul 1, 2021
99c8fe3
HEEDLS-532 Improve mobile layout and css refactoring
AlexJacksonDS Jul 1, 2021
34079fc
HEEDLS-532 Fix broken scss include
AlexJacksonDS Jul 1, 2021
e120cd7
Merge branch 'master' into HEEDLS-532-admins-no-js-filtering
AlexJacksonDS Jul 2, 2021
97bb3fe
HEEDLS-532 Add coloured NHS tags
AlexJacksonDS Jul 5, 2021
c819b3d
HEEDLS-532 Review markups
AlexJacksonDS Jul 5, 2021
d8ef99d
HEEDLS-532 Revert changes to pagination covered by another ticket
AlexJacksonDS Jul 5, 2021
6d60283
HEEDLS-532 Check whether user is a CMS manager properly
AlexJacksonDS Jul 6, 2021
510a970
HEEDLS-532 Add an extra Other filter status for the default blue tag
AlexJacksonDS Jul 6, 2021
284acc0
HEEDLS-532 Fix unit test
AlexJacksonDS Jul 6, 2021
501946f
HEEDLS-532 Move SearchablePage view models into folder
AlexJacksonDS Jul 6, 2021
1c2b179
HEEDLS-532 Move view component models into folder
AlexJacksonDS Jul 6, 2021
03fa1f1
HEEDLS-532 Rename filter value
AlexJacksonDS Jul 6, 2021
ff80603
HEEDLS-532 Refactor filter/queryable unit tests
AlexJacksonDS Jul 6, 2021
56b351f
Merge branch 'master' into HEEDLS-532-admins-no-js-filtering
AlexJacksonDS Jul 6, 2021
270d50e
HEEDLS-532 Refactor css into multiple files
AlexJacksonDS Jul 6, 2021
ce28323
HEEDLS-532 Remove Other FilterStatus
AlexJacksonDS Jul 7, 2021
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
1 change: 1 addition & 0 deletions DigitalLearningSolutions.Data/Models/User/AdminUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class AdminUser : User

public bool IsLocked => FailedLoginCount >= FailedLoginThreshold;
public bool IsCmsAdministrator => ImportOnly && IsContentManager;
public bool IsCmsManager => IsContentManager && !ImportOnly;

public override UserReference ToUserReference()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
namespace DigitalLearningSolutions.Web.Tests.Extensions
{
using System.Linq;
using DigitalLearningSolutions.Web.Extensions;
using DigitalLearningSolutions.Web.Tests.TestHelpers;
using FluentAssertions;
using NUnit.Framework;

public class QueryableExtensionsTests
{
private static readonly SortableItem ItemA1 = new SortableItem("a", 1);
private static readonly SortableItem ItemA3 = new SortableItem("a", 3);
private static readonly SortableItem ItemB2 = new SortableItem("b", 2);
private static readonly SortableItem ItemB3 = new SortableItem("b", 3);
private static readonly SortableItem ItemC3 = new SortableItem("c", 3);
private static readonly IQueryable<SortableItem> InputItems = new[] { ItemB2, ItemA1, ItemC3 }.AsQueryable();

private static readonly IQueryable<SortableItem> ThenByInputItems =
new[] { ItemB2, ItemA1, ItemA3 }.AsQueryable();

[Test]
public void SortAllItems_by_name_ascending_returns_item_in_expected_order()
{
// Given
var inputItems = QueryableHelper.GetListOfSortableItems("b", 2, "a", 1, "c", 3);
var expectedItems = QueryableHelper.GetListOfSortableItems("a", 1, "b", 2, "c", 3);
var expectedItems = new[] { ItemA1, ItemB2, ItemC3 }.AsQueryable();

// When
var result = inputItems.OrderBy("Name");
var result = InputItems.OrderBy("Name");

// Then
result.Should().BeEquivalentTo(expectedItems);
Expand All @@ -25,11 +35,10 @@ public void SortAllItems_by_name_ascending_returns_item_in_expected_order()
public void SortAllItems_by_name_descending_returns_item_in_expected_order()
{
// Given
var inputItems = QueryableHelper.GetListOfSortableItems("b", 2, "a", 1, "c", 3);
var expectedItems = QueryableHelper.GetListOfSortableItems("c", 3, "b", 2, "a", 1);
var expectedItems = new[] { ItemC3, ItemB2, ItemA1 }.AsQueryable();

// When
var result = inputItems.OrderByDescending("Name");
var result = InputItems.OrderByDescending("Name");

// Then
result.Should().BeEquivalentTo(expectedItems);
Expand All @@ -39,11 +48,10 @@ public void SortAllItems_by_name_descending_returns_item_in_expected_order()
public void SortAllItems_by_number_ascending_returns_item_in_expected_order()
{
// Given
var inputItems = QueryableHelper.GetListOfSortableItems("b", 2, "a", 1, "c", 3);
var expectedItems = QueryableHelper.GetListOfSortableItems("a", 1, "b", 2, "c", 3);
var expectedItems = new[] { ItemA1, ItemB2, ItemC3 }.AsQueryable();

// When
var result = inputItems.OrderBy("Number");
var result = InputItems.OrderBy("Number");

// Then
result.Should().BeEquivalentTo(expectedItems);
Expand All @@ -53,11 +61,10 @@ public void SortAllItems_by_number_ascending_returns_item_in_expected_order()
public void SortAllItems_by_number_descending_returns_item_in_expected_order()
{
// Given
var inputItems = QueryableHelper.GetListOfSortableItems("b", 2, "a", 1, "c", 3);
var expectedItems = QueryableHelper.GetListOfSortableItems("c", 3, "b", 2, "a", 1);
var expectedItems = new[] { ItemC3, ItemB2, ItemA1 }.AsQueryable();

// When
var result = inputItems.OrderByDescending("Number");
var result = InputItems.OrderByDescending("Number");

// Then
result.Should().BeEquivalentTo(expectedItems);
Expand All @@ -67,11 +74,10 @@ public void SortAllItems_by_number_descending_returns_item_in_expected_order()
public void SortAllItems_by_name_then_number_ascending_returns_item_in_expected_order()
{
// Given
var inputItems = QueryableHelper.GetListOfSortableItems("b", 2, "a", 1, "a", 3);
var expectedItems = QueryableHelper.GetListOfSortableItems("a", 1, "a", 3, "b", 2);
var expectedItems = new[] { ItemA1, ItemA3, ItemB2 }.AsQueryable();

// When
var result = inputItems.OrderBy("Name").ThenBy("Number");
var result = ThenByInputItems.OrderBy("Name").ThenBy("Number");

// Then
result.Should().BeEquivalentTo(expectedItems);
Expand All @@ -81,11 +87,37 @@ public void SortAllItems_by_name_then_number_ascending_returns_item_in_expected_
public void SortAllItems_by_name_then_number_descending_returns_item_in_expected_order()
{
// Given
var inputItems = QueryableHelper.GetListOfSortableItems("b", 2, "a", 1, "a", 3);
var expectedItems = QueryableHelper.GetListOfSortableItems("b", 2, "a", 3, "a", 1);
var expectedItems = new[] { ItemB2, ItemA3, ItemA1 }.AsQueryable();

// When
var result = ThenByInputItems.OrderByDescending("Name").ThenByDescending("Number");

// Then
result.Should().BeEquivalentTo(expectedItems);
}

[Test]
public void Where_returns_expected_items_for_string_property()
{
// Given
var expectedItems = new[] { ItemA1, ItemA3 }.AsQueryable();

// When
var result = ThenByInputItems.Where("Name", "a");

// Then
result.Should().BeEquivalentTo(expectedItems);
}

[Test]
public void Where_returns_expected_items_for_int_property()
{
// Given
var inputItems = new[] { ItemA3, ItemB3, ItemA1 }.AsQueryable();
var expectedItems = new[] { ItemA3, ItemB3 }.AsQueryable();

// When
var result = inputItems.OrderByDescending("Name").ThenByDescending("Number");
var result = inputItems.Where("Number", 3);

// Then
result.Should().BeEquivalentTo(expectedItems);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace DigitalLearningSolutions.Web.Tests.Helpers
{
using System.Collections.Generic;
using System.Linq;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Data.Tests.TestHelpers;
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;
Expand All @@ -15,21 +16,23 @@ public void GetCurrentTagsForAdminUser_should_return_correct_tags()
{
// Given
var adminUser = UserTestHelper.GetDefaultAdminUser(failedLoginCount: 5, isContentCreator: true);
var expectedTags = new List<SearchableTagViewModel>
{
new SearchableTagViewModel(AdminFilterOptions.IsLocked),
new SearchableTagViewModel(AdminFilterOptions.CentreAdministrator),
new SearchableTagViewModel(AdminFilterOptions.Supervisor),
new SearchableTagViewModel(AdminFilterOptions.Trainer),
new SearchableTagViewModel(AdminFilterOptions.CmsAdministrator),
new SearchableTagViewModel(AdminFilterOptions.ContentCreatorLicense)
};

// When
var result = FilterableTagHelper.GetCurrentTagsForAdminUser(adminUser).ToList();

// Then
using (new AssertionScope())
{
result.Count.Should().Be(7);
result.Should().Contain(("Locked", nameof(AdminUser.IsLocked) + "|true"));
result.Should().Contain(("Centre administrator", nameof(AdminUser.IsCentreAdmin) + "|true"));
result.Should().Contain(("Supervisor", nameof(AdminUser.IsSupervisor) + "|true"));
result.Should().Contain(("Trainer", nameof(AdminUser.IsTrainer) + "|true"));
result.Should().Contain(("CMS manager", nameof(AdminUser.IsContentManager) + "|true"));
result.Should().Contain(("Content Creator license", nameof(AdminUser.IsContentCreator) + "|true"));
result.Should().Contain(("CMS administrator", nameof(AdminUser.IsCmsAdministrator) + "|true"));
result.Should().BeEquivalentTo(expectedTags);
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions DigitalLearningSolutions.Web.Tests/Helpers/FilteringHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace DigitalLearningSolutions.Web.Tests.Helpers
{
using System.Linq;
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.Tests.TestHelpers;
using FluentAssertions;
using NUnit.Framework;

public class FilteringHelperTests
{
private static readonly SortableItem ItemA1 = new SortableItem("a", 1);
private static readonly SortableItem ItemA3 = new SortableItem("a", 3);
private static readonly SortableItem ItemB2 = new SortableItem("b", 2);
private static readonly IQueryable<SortableItem> InputItems = new[] { ItemA1, ItemA3, ItemB2 }.AsQueryable();

[Test]
public void FilterItems_returns_expected_items_with_single_filter()
{
// Given
var expectedItems = new[] { ItemA1, ItemA3 }.AsQueryable();
var filterBy = "Name|a";

// When
var result = FilteringHelper.FilterItems(InputItems, filterBy);

// Then
result.Should().BeEquivalentTo(expectedItems);
}

[Test]
public void FilterItems_returns_expected_items_with_multiple_filters()
{
// Given
var expectedItems = new[] { ItemA1 }.AsQueryable();
var filterBy = "Name|a\r\nNumber|1";

// When
var result = FilteringHelper.FilterItems(InputItems, filterBy);

// Then
result.Should().BeEquivalentTo(expectedItems);
}
}
}
12 changes: 0 additions & 12 deletions DigitalLearningSolutions.Web.Tests/TestHelpers/QueryableHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace DigitalLearningSolutions.Web.Tests.ViewComponents
{
using System.Collections.Generic;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.ViewComponents;
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.Administrator;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using NUnit.Framework;

public class CurrentFiltersViewComponentTests
{
private ViewComponentContext viewComponentContext = null!;

[SetUp]
public void Setup()
{
var httpContext = new DefaultHttpContext();

var viewContext = new ViewContext { HttpContext = httpContext };

viewComponentContext = new ViewComponentContext
{
ViewContext = viewContext
};
}

[Test]
public void CurrentFiltersViewComponent_selects_expected_filters_to_display()
{
// Given
var viewComponent = new CurrentFiltersViewComponent { ViewComponentContext = viewComponentContext };
var categories = new[] { "Word", "Excel" };
const string searchString = "test";
var inputViewModel = new CentreAdministratorsViewModel(
1,
new List<AdminUser>(),
categories,
searchString,
"SearchableName",
"Ascending",
$"CategoryName|Word\r\n{AdminFilterOptions.CentreAdministrator.FilterValue}",
1
);
var expectedAppliedFilters = new List<AppliedFilterViewModel>
{
new AppliedFilterViewModel(AdminFilterOptions.CentreAdministrator.DisplayText, "Role"),
new AppliedFilterViewModel("Word", "Category")
};

var expectedFilterViewModel = new CurrentFiltersViewModel(expectedAppliedFilters, searchString);

// When
var model = viewComponent.Invoke(inputViewModel).As<ViewViewComponentResult>().ViewData.Model
.As<CurrentFiltersViewModel>();

// Then
model.Should().BeEquivalentTo(expectedFilterViewModel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Data.Tests.TestHelpers;
using DigitalLearningSolutions.Web.ViewModels.Common;
using DigitalLearningSolutions.Web.ViewModels.Common.ViewComponents;
using FluentAssertions;
using NUnit.Framework;

Expand All @@ -27,8 +27,8 @@ public void AdminUsers_and_Centre_populate_expected_values()
// Then
viewModel.Admins.Should().Be("7");
viewModel.Supervisors.Should().Be("6");
viewModel.CmsAdministrators.Should().Be("4 / 12");
viewModel.CmsManagers.Should().Be("1 / 13");
viewModel.CmsAdministrators.Should().Be("3 / 12");
viewModel.CmsManagers.Should().Be("2 / 13");
viewModel.CcLicences.Should().Be("2 / 14");
viewModel.Trainers.Should().Be("1 / 15");
}
Expand All @@ -49,8 +49,8 @@ public void No_limit_should_be_displayed_when_centre_has_no_limit_on_spots_avail
var viewModel = new NumberOfAdministratorsViewModel(centre, adminUsersAtCentre);

// Then
viewModel.CmsAdministrators.Should().Be("4");
viewModel.CmsManagers.Should().Be("1");
viewModel.CmsAdministrators.Should().Be("3");
viewModel.CmsManagers.Should().Be("2");
viewModel.CcLicences.Should().Be("2");
viewModel.Trainers.Should().Be("1");
}
Expand Down
Loading