Skip to content

Commit

Permalink
Merge pull request #604 from hmrc/jackheslop96-patch-1
Browse files Browse the repository at this point in the history
Sequential navigation when currentPage is None.
  • Loading branch information
jackheslop96 authored Feb 13, 2024
2 parents 3476828 + 3254ca5 commit 361dce4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/navigation/UserAnswersNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object UserAnswersNavigator extends Logging {
t.routeIfCompleted(_, mode, _)
}
case Left(ReaderError(unansweredPage, answeredPages, _)) =>
rec(answeredPages.toList, exit = false) {
rec(answeredPages.toList, exit = currentPage.isEmpty) {
(userAnswers, _) => unansweredPage.route(userAnswers, mode)
}
}
Expand Down
36 changes: 28 additions & 8 deletions test/navigation/UserAnswersNavigatorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ class UserAnswersNavigatorSpec extends SpecBase {
"when in normal mode" - {
val mode = NormalMode

"and no pages answered" in {
val currentPage = None
val answeredPages = Nil
val userAnswersReaderResult = Left(ReaderError(FooPage, answeredPages))
"and currentPage is None" - {
"and userAnswersReaderResult is a Left" - {
"must redirect to first answered page" in {
val currentPage = None
val answeredPages = Seq(FooPage, BarPage)
val userAnswersReaderResult = Left(ReaderError(BazPage, answeredPages))

val result = UserAnswersNavigator
.nextPage(currentPage, userAnswersReaderResult, mode)
.apply(userAnswers, stage)
val result = UserAnswersNavigator
.nextPage(currentPage, userAnswersReaderResult, mode)
.apply(userAnswers, stage)

result.value.url mustBe "/foo"
result.value.url mustBe "/foo"
}
}
}

"and on FooPage" - {
Expand Down Expand Up @@ -133,6 +137,22 @@ class UserAnswersNavigatorSpec extends SpecBase {
"when in check mode" - {
val mode = CheckMode

"and currentPage is None" - {
"and userAnswersReaderResult is a Left" - {
"must redirect to first answered page" in {
val currentPage = None
val answeredPages = Seq(FooPage, BarPage)
val userAnswersReaderResult = Left(ReaderError(BazPage, answeredPages))

val result = UserAnswersNavigator
.nextPage(currentPage, userAnswersReaderResult, mode)
.apply(userAnswers, stage)

result.value.url mustBe "/foo"
}
}
}

"and on FooPage" - {
val currentPage = Some(FooPage)

Expand Down

0 comments on commit 361dce4

Please sign in to comment.