Skip to content

Commit

Permalink
feat: Pathways Contents Page
Browse files Browse the repository at this point in the history
  • Loading branch information
mattb-hippo committed Dec 12, 2024
1 parent e65d625 commit d854d51
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Childrens_Social_Care_CPD;
using Childrens_Social_Care_CPD.Contentful;
Expand Down Expand Up @@ -44,7 +45,6 @@ public async Task Page_Of_Type_Pathways_Overview_Page_Associated_With_Pathways_M
sut.Next.Url.Should().Be("/");
}


[Test]
public async Task Page_Of_Type_Pathways_Overview_Page_Associated_With_Pathways_Module_With_Contents_Page_Configured_Should_Have_ContentsPage_Id_As_Next_Url () {

Check failure on line 49 in Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs

View workflow job for this annotation

GitHub Actions / .NET Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 49 in Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs

View workflow job for this annotation

GitHub Actions / .NET Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Expand All @@ -67,4 +67,94 @@ public async Task Page_Of_Type_Pathways_Overview_Page_Associated_With_Pathways_M

// assert
sut.Next.Url.Should().Be("/" + contentsPageId);
}}
}

[Test]
public async Task Page_Of_Type_Pathways_Contents_Page_Should_Have_First_Page_Of_First_Section_Id_As_Next_Url () {

Check failure on line 73 in Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs

View workflow job for this annotation

GitHub Actions / .NET Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

// setup
var trainingPageId = "TRAINING_PAGE_ID";
var page = new Content ()
{
PageType = PageType.PathwaysContentsPage,
PathwaysModule = new PathwaysModule()
{
Sections = new List<PathwaysModuleSection>()
{
new PathwaysModuleSection
{
Pages = new List<Content>()
{
new Content()
{
Id = trainingPageId
}
}
}
}
}
};

// act
var sut = new PathwaysNavigationHelper(page);

// assert
sut.Next.Url.Should().Be("/" + trainingPageId);
}

[Test]
public async Task Page_Of_Type_Pathways_Contents_Page_Should_Have_Default_Next_Url_If_First_Section_Has_No_Pages () {

Check failure on line 106 in Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs

View workflow job for this annotation

GitHub Actions / .NET Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

// setup
var page = new Content ()
{
PageType = PageType.PathwaysContentsPage,
PathwaysModule = new PathwaysModule()
{
Sections = new List<PathwaysModuleSection>()
{
new PathwaysModuleSection ()
}
}
};

// act
var sut = new PathwaysNavigationHelper(page);

// assert
sut.Next.Url.Should().Be("/");
}

[Test]
public async Task Page_Of_Type_Pathways_Contents_Page_Should_Have_Default_Next_Url_If_Pathway_Has_No_Sections () {

Check failure on line 129 in Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs

View workflow job for this annotation

GitHub Actions / .NET Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

// setup
var page = new Content ()
{
PageType = PageType.PathwaysContentsPage,
PathwaysModule = new PathwaysModule ()
};

// act
var sut = new PathwaysNavigationHelper(page);

// assert
sut.Next.Url.Should().Be("/");
}

[Test]
public async Task Page_Of_Type_Pathways_Contents_Page_Should_Have_Default_Next_Url_If_Page_Has_No_Pathway_Modules () {

Check failure on line 146 in Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs

View workflow job for this annotation

GitHub Actions / .NET Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

// setup
var page = new Content ()
{
PageType = PageType.PathwaysContentsPage
};

// act
var sut = new PathwaysNavigationHelper(page);

// assert
sut.Next.Url.Should().Be("/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ public PathwaysNavigationHelper (Content page)
break;

case PageType.PathwaysContentsPage:
/*
TODO: this line needs a lot of hardening. It will fall over if the pathways
module doesn't have sections, or if the first module section doesn't have pages.
If it falls over in circumstances like that, the user ought to see a
fairly anodyne "misconfiguration' error
*/
var url = page.PathwaysModule
.Sections
var url = page.PathwaysModule?
.Sections?
.First<PathwaysModuleSection>()
.Pages
.Pages?
.First<Content>()
.Id;

Expand Down
70 changes: 44 additions & 26 deletions Childrens-Social-Care-CPD/Views/Shared/_PathwaysModuleIndex.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,50 @@

int sectionCount=0;

foreach (var moduleSection in Model.PathwaysModule.Sections)
{
sectionCount++;
<section class="module-overview--section">
<div class="progress-bar">
<span class="icon not_started">
<span class="number">@sectionCount</span>
</span>
<div class="line"></div>
</div>
<div class="module-section--content">
<div class="module-section--header">
<h4 class="govuk-heading-s">
@if (moduleSection.Pages == null) {
<div class="contentful-configuration-error">
Configuration problem in Module Section: <span class="highlight">No pages defined</span><br />
Add content item(s) to this Module Section to resolve this.
</div>
}
@moduleSection.Name <span class="module-section--pages">(@moduleSection.Pages?.Count pages)</span>
</h4>
<a href="/@moduleSection.Pages?[0].Id" class="section-nav-link govuk-link" data-track-label="">Go to this section</a>
</div>
<p class="govuk-body">@moduleSection.Summary</p>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">
@if (Model.PathwaysModule == null) {
<div class="contentful-configuration-error">
Configuration problem in Page: <span class="highlight">No Pathways Module defined</span><br />
Add Pathways Module item to this Content item to resolve this.
</div>
}
else {

@if (Model.PathwaysModule.Sections == null) {
<div class="contentful-configuration-error">
Configuration problem in Pathways Module: <span class="highlight">No sections defined</span><br />
Add Pathways Module Section item(s) to this Pathways Module to resolve this.
</div>
</section>
}
else {

foreach (var moduleSection in Model.PathwaysModule?.Sections)
{
sectionCount++;
<section class="module-overview--section">
<div class="progress-bar">
<span class="icon not_started">
<span class="number">@sectionCount</span>
</span>
<div class="line"></div>
</div>
<div class="module-section--content">
<div class="module-section--header">
<h4 class="govuk-heading-s">
@if (moduleSection.Pages == null) {
<div class="contentful-configuration-error">
Configuration problem in Module Section: <span class="highlight">No pages defined</span><br />
Add Content item(s) to this Pathways Module Section to resolve this.
</div>
}
@moduleSection.Name <span class="module-section--pages">(@moduleSection.Pages?.Count pages)</span>
</h4>
<a href="/@moduleSection.Pages?[0].Id" class="section-nav-link govuk-link" data-track-label="">Go to this section</a>
</div>
<p class="govuk-body">@moduleSection.Summary</p>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">
</div>
</section>
}
}
}
}

0 comments on commit d854d51

Please sign in to comment.