Skip to content

Commit

Permalink
Update the resources menu item and feature control the whole of resou…
Browse files Browse the repository at this point in the history
…rces
  • Loading branch information
killij committed Oct 31, 2023
1 parent fb68caa commit 71f5f5c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Childrens_Social_Care_CPD.Controllers;
using Childrens_Social_Care_CPD.Configuration;
using Childrens_Social_Care_CPD.Controllers;
using Childrens_Social_Care_CPD.Core.Resources;
using Childrens_Social_Care_CPD.Models;
using FluentAssertions;
Expand All @@ -14,6 +15,7 @@ namespace Childrens_Social_Care_CPD_Tests.Controllers;

public class ResourcesControllerTests
{
private IFeaturesConfig _featuresConfig;
private IResourcesSearchStrategy _searchStrategy;
private ResourcesController _resourcesController;
private IRequestCookieCollection _cookies;
Expand All @@ -32,8 +34,10 @@ public void SetUp()
_httpContext.Request.Returns(_httpRequest);
controllerContext.HttpContext = _httpContext;

_featuresConfig = Substitute.For<IFeaturesConfig>();
_featuresConfig.IsEnabled(Features.ResourcesAndLearning).Returns(true);
_searchStrategy = Substitute.For<IResourcesSearchStrategy>();
_resourcesController = new ResourcesController(_searchStrategy)
_resourcesController = new ResourcesController(_featuresConfig, _searchStrategy)
{
ControllerContext = controllerContext,
TempData = Substitute.For<ITempDataDictionary>()
Expand All @@ -53,4 +57,19 @@ public async Task Search_Returns_Strategy_Model()
// assert
actual.Model.Should().Be(model);
}

[Test]
public async Task Disabling_Resources_Feature_Returns_NotFoundResult()
{
// arrange
_featuresConfig.IsEnabled(Features.ResourcesAndLearning).Returns(false);
var model = new ResourcesListViewModel(null, null, null, null);
_searchStrategy.SearchAsync(Arg.Any<ResourcesQuery>(), Arg.Any<CancellationToken>()).Returns(model);

// act
var actual = await _resourcesController.Search(query: null);

// assert
actual.Should().BeOfType<NotFoundResult>();
}
}
1 change: 1 addition & 0 deletions Childrens-Social-Care-CPD/Configuration/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public static class Features
{
public const string ResourcesAndLearning = "resources-learning";
public const string ResourcesUseDynamicTags = "resources-search-use-dynamic-tags";
}
13 changes: 10 additions & 3 deletions Childrens-Social-Care-CPD/Controllers/ResourcesController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Childrens_Social_Care_CPD.Core.Resources;
using Childrens_Social_Care_CPD.Configuration;
using Childrens_Social_Care_CPD.Core.Resources;
using Childrens_Social_Care_CPD.Models;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -17,19 +18,25 @@ public ResourcesQuery()

public class ResourcesController : Controller
{
private readonly IFeaturesConfig _featuresConfig;
private readonly IResourcesSearchStrategy _strategy;

public ResourcesController(IResourcesSearchStrategy strategy)
public ResourcesController(IFeaturesConfig featuresConfig, IResourcesSearchStrategy strategy)
{
ArgumentNullException.ThrowIfNull(strategy);

_featuresConfig = featuresConfig;
_strategy = strategy;
}

[Route("resources", Name = "Resource")]
[HttpGet]
public async Task<IActionResult> Search([FromQuery] ResourcesQuery query, bool preferencesSet = false, CancellationToken cancellationToken = default)
{
if (!_featuresConfig.IsEnabled(Features.ResourcesAndLearning))
{
return NotFound();
}

var contextModel = new ContextModel(string.Empty, "Resources", "Resources", "Resources", true, preferencesSet);
ViewData["ContextModel"] = contextModel;

Expand Down
26 changes: 16 additions & 10 deletions Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
@inject ICookieHelper _cookieHelper;
@using Childrens_Social_Care_CPD.Configuration;

@inject ICookieHelper cookieHelper;
@inject IFeaturesConfig featuresConfig;

<!DOCTYPE html>
<html lang="en" class="govuk-template">
<head>
<title>@ViewBag.Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link href="~/css/application.min.css" rel="stylesheet" />
@if (_cookieHelper.GetRequestAnalyticsCookieState(Context) == AnalyticsConsentState.Accepted)
@if (cookieHelper.GetRequestAnalyticsCookieState(Context) == AnalyticsConsentState.Accepted)
{
<partial name="_GoogleAnalyticsPartial" />
}
Expand Down Expand Up @@ -78,14 +81,17 @@
</svg>
</a>
</li>
<li class="dfe-header__navigation-item" id="mmi-resources">
<a class="dfe-header__navigation-link" href="/resources">
Resources
<svg class="dfe-icon dfe-icon__chevron-right" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" width="34" height="34">
<path d="M15.5 12a1 1 0 0 1-.29.71l-5 5a1 1 0 0 1-1.42-1.42l4.3-4.29-4.3-4.29a1 1 0 0 1 1.42-1.42l5 5a1 1 0 0 1 .29.71z"></path>
</svg>
</a>
</li>
@if (featuresConfig.IsEnabled(Features.ResourcesAndLearning))
{
<li class="dfe-header__navigation-item" id="mmi-resources">
<a class="dfe-header__navigation-link" href="/resources">
Resources and learning
<svg class="dfe-icon dfe-icon__chevron-right" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" width="34" height="34">
<path d="M15.5 12a1 1 0 0 1-.29.71l-5 5a1 1 0 0 1-1.42-1.42l4.3-4.29-4.3-4.29a1 1 0 0 1 1.42-1.42l5 5a1 1 0 0 1 .29.71z"></path>
</svg>
</a>
</li>
}
</ul>
</div>
</nav>
Expand Down
13 changes: 10 additions & 3 deletions Childrens-Social-Care-CPD/Views/Shared/_Header.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@{
@using Childrens_Social_Care_CPD.Configuration;

@inject IFeaturesConfig featuresConfig

@{
ContextModel viewModel = ViewBag.ContextModel;
var category = viewModel.Category ?? "Home";
}
Expand Down Expand Up @@ -53,8 +57,11 @@
RenderMenuItem("career", "Career stages", "career-stages", category == "Career information");
RenderMenuItem("developmentProgrammes", "Development programmes", "development-programmes", category == "Development programmes");
RenderMenuItem("exploreRoles", "Explore roles", "explore-roles", category == "Explore roles");
RenderMenuItem("resources", "Resources", "resources", category == "Resources");


if (featuresConfig.IsEnabled(Features.ResourcesAndLearning))
{
RenderMenuItem("resources", "Resources and learning", "resources", category == "Resources");
}
}
</ul>
</div>
Expand Down

0 comments on commit 71f5f5c

Please sign in to comment.