Skip to content

Commit

Permalink
Merge pull request #597 from DFE-Digital/SFSW-2714-Support-pathways-m…
Browse files Browse the repository at this point in the history
…odules-without-Table-of-Contents-pages

made pathways navigation cope with contents page not being specified
  • Loading branch information
Maria-C1 authored Dec 19, 2024
2 parents 2cda048 + 346e8c5 commit 21beb33
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathwaysModuleSection>
{
new PathwaysModuleSection
{
Pages = new List<Content>
{
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
Expand Down Expand Up @@ -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<PathwaysModuleSection>()
{
new PathwaysModuleSection
{
Pages = new List<Content>()
{
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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
};
}
}
Expand All @@ -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;
}
}

0 comments on commit 21beb33

Please sign in to comment.