diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs index caf8f3aa..d4a53af5 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/Navigation/PathwaysNavigationHelperTests.cs @@ -71,6 +71,38 @@ public void Page_Of_Type_Pathways_Overview_Page_Associated_With_Pathways_Module_ sut.Next.Url.Should().Be("/" + contentsPageId); } + [Test] + public void Page_Of_Type_Pathways_Overview_Page_Associated_With_Pathways_Module_With_No_Contents_Page_Configured_Should_Have_First_Training_Content_Page_Id_As_Next_Url() + { + // setup + var page = new Content() + { + PageType = PageType.PathwaysOverviewPage, + PathwaysModule = new PathwaysModule() + { + Sections = new List + { + new PathwaysModuleSection + { + Pages = new List + { + new Content + { + Id = "TRAINING_CONTENT_PAGE_ID" + } + } + } + } + } + }; + + // act + var sut = new PathwaysNavigationHelper(page); + + // assert + sut.Next.Url.Should().Be("/" + "TRAINING_CONTENT_PAGE_ID"); + } + #endregion #region Contents Page @@ -212,6 +244,48 @@ public void First_Page_In_First_Section_Of_Module_Should_Have_Second_Page_Of_Fir sut.Previous.Url.Should().Be("/contents page"); } + [Test] + public void First_Page_In_First_Section_Of_Module_When_There_Is_No_Contents_Page_Specified_Should_Have_Module_Overview_Page_As_Previous_Url() + { + // setup + var page = new Content() + { + PageType = PageType.PathwaysTrainingContent, + Id = "section 1 page 1", + PathwaysModule = new PathwaysModule() + { + OverviewPage = new Content + { + Id = "overview_page" + }, + Sections = new List() + { + new PathwaysModuleSection + { + Pages = new List() + { + new Content() + { + Id = "section 1 page 1" + }, + new Content() + { + Id = "section 1 page 2" + } + } + } + } + } + }; + + // act + var sut = new PathwaysNavigationHelper(page); + + // assert + sut.Previous.Name.Should().Be("Previous"); + sut.Previous.Url.Should().Be("/overview_page"); + } + [Test] public void Middle_Page_In_First_Section_Of_Module_Should_Have_Next_Page_Of_Same_Section_As_Next_Url_And_Previous_Page_Of_Same_Section_As_Previous_Url() { diff --git a/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs b/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs index c6c79a9b..cada8d5c 100644 --- a/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs +++ b/Childrens-Social-Care-CPD/Contentful/Navigation/PathwaysNavigationHelper.cs @@ -57,19 +57,17 @@ public PathwaysNavigationHelper(Content page) case PageType.PathwaysOverviewPage: this._next = new NavigationLocation { - Url = "/" + page.PathwaysModule?.ContentsPage?.Id + Url = "/" + (page.PathwaysModule?.ContentsPage == null + ? GetFirstSectionFirstPageId(page) + : page.PathwaysModule.ContentsPage.Id) }; break; case PageType.PathwaysContentsPage: - var url = page.PathwaysModule? - .Sections?[0] - .Pages?[0] - .Id; this._next = new NavigationLocation { - Url = "/" + url + Url = "/" + GetFirstSectionFirstPageId(page) }; break; @@ -168,10 +166,13 @@ private void SetTrainingPagePreviousNavigation(int pageCounter, int sectionCount else { // first page in first section, previous should navigate back to contents page + // or overview page if there is no contents page this._previous = new NavigationLocation { Name = "Previous", - Url = "/" + page.PathwaysModule.ContentsPage.Id + Url = "/" + (page.PathwaysModule?.ContentsPage != null + ? page.PathwaysModule.ContentsPage.Id + : page.PathwaysModule.OverviewPage?.Id) }; } } @@ -186,4 +187,13 @@ private void SetTrainingPageCurrentLocation(int currentSectionIdx, Content page, TotalSections = page.PathwaysModule.Sections.Count }; } + + private string GetFirstSectionFirstPageId (Content page) + { + return page + .PathwaysModule? + .Sections?[0] + .Pages?[0] + .Id; + } }