diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs index c60bd27b..b6aae883 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Threading.Tasks; using Childrens_Social_Care_CPD; using Childrens_Social_Care_CPD.Contentful; @@ -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 () { @@ -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 () { + + // setup + var trainingPageId = "TRAINING_PAGE_ID"; + var page = new Content () + { + PageType = PageType.PathwaysContentsPage, + PathwaysModule = new PathwaysModule() + { + Sections = new List() + { + new PathwaysModuleSection + { + Pages = new List() + { + 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 () { + + // setup + var page = new Content () + { + PageType = PageType.PathwaysContentsPage, + PathwaysModule = new PathwaysModule() + { + Sections = new List() + { + 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 () { + + // 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 () { + + // setup + var page = new Content () + { + PageType = PageType.PathwaysContentsPage + }; + + // act + var sut = new PathwaysNavigationHelper(page); + + // assert + sut.Next.Url.Should().Be("/"); + } +} \ No newline at end of file diff --git a/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs b/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs index a4803c57..ef0e2527 100644 --- a/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs +++ b/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs @@ -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() - .Pages + .Pages? .First() .Id; diff --git a/Childrens-Social-Care-CPD/Views/Shared/_PathwaysModuleIndex.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_PathwaysModuleIndex.cshtml index 3677c53d..f7a11061 100644 --- a/Childrens-Social-Care-CPD/Views/Shared/_PathwaysModuleIndex.cshtml +++ b/Childrens-Social-Care-CPD/Views/Shared/_PathwaysModuleIndex.cshtml @@ -23,32 +23,50 @@ int sectionCount=0; - foreach (var moduleSection in Model.PathwaysModule.Sections) - { - sectionCount++; -
-
- - @sectionCount - -
-
-
-
-

- @if (moduleSection.Pages == null) { -
- Configuration problem in Module Section: No pages defined
- Add content item(s) to this Module Section to resolve this. -
- } - @moduleSection.Name (@moduleSection.Pages?.Count pages) -

- Go to this section -
-

@moduleSection.Summary

-
+ @if (Model.PathwaysModule == null) { +
+ Configuration problem in Page: No Pathways Module defined
+ Add Pathways Module item to this Content item to resolve this. +
+ } + else { + + @if (Model.PathwaysModule.Sections == null) { +
+ Configuration problem in Pathways Module: No sections defined
+ Add Pathways Module Section item(s) to this Pathways Module to resolve this.
-
+ } + else { + + foreach (var moduleSection in Model.PathwaysModule?.Sections) + { + sectionCount++; +
+
+ + @sectionCount + +
+
+
+
+

+ @if (moduleSection.Pages == null) { +
+ Configuration problem in Module Section: No pages defined
+ Add Content item(s) to this Pathways Module Section to resolve this. +
+ } + @moduleSection.Name (@moduleSection.Pages?.Count pages) +

+ Go to this section +
+

@moduleSection.Summary

+
+
+
+ } + } } } \ No newline at end of file