Skip to content

Commit

Permalink
SASS-10526: Implement NormalMode navigation functionality for 'Struct…
Browse files Browse the repository at this point in the history
…ures and building allowance' journey
  • Loading branch information
tbg2003 committed Jan 2, 2025
1 parent cfaa530 commit 27bf6a7
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import controllers.actions._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import pages.foreign.structurebuildingallowance.ForeignStructureBuildingAllowancePage
import pages.foreign.structurebuildingallowance.{ForeignStructureBuildingAllowanceGroup, ForeignStructureBuildingAllowancePage}
import views.html.foreign.structurebuildingallowance.ForeignStructureBuildingAllowanceView

import javax.inject.Inject
Expand All @@ -38,6 +38,7 @@ class ForeignAddClaimStructureBuildingAllowanceController @Inject()(

def onPageLoad(taxYear: Int, countryCode: String): Action[AnyContent] =
(identify andThen getData andThen requireData) { implicit request =>
Ok(view(ForeignStructureBuildingAllowancePage(taxYear, countryCode, request.user.isAgentMessageKey)))
val nextIndex = request.userAnswers.get(ForeignStructureBuildingAllowanceGroup(countryCode)).map(_.length).getOrElse(0)
Ok(view(ForeignStructureBuildingAllowancePage(taxYear, countryCode, nextIndex, request.user.isAgentMessageKey)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ForeignStructureBuildingQualifyingDateController @Inject()(
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(
foreignNavigator.nextPage(
ForeignStructureBuildingAllowanceClaimPage(countryCode, index),
ForeignStructureBuildingQualifyingDatePage(countryCode, index),
taxYear,
mode,
request.userAnswers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package controllers.foreign.structuresbuildingallowance
import controllers.actions._
import forms.foreign.structurebuildingallowance.ForeignStructuresBuildingAllowanceAddressFormProvider
import models.Mode
import navigation.Navigator
import navigation.ForeignPropertyNavigator
import pages.foreign.structurebuildingallowance.ForeignStructuresBuildingAllowanceAddressPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
Expand All @@ -33,7 +33,7 @@ import scala.concurrent.{ExecutionContext, Future}
class ForeignStructuresBuildingAllowanceAddressController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
foreignNavigator: ForeignPropertyNavigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
Expand Down Expand Up @@ -70,11 +70,10 @@ class ForeignStructuresBuildingAllowanceAddressController @Inject() (
)
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(
navigator.sbaNextPage(
foreignNavigator.nextPage(
ForeignStructuresBuildingAllowanceAddressPage(index, countryCode),
taxYear,
mode,
index,
request.userAnswers,
updatedAnswers
)
Expand Down
28 changes: 28 additions & 0 deletions app/navigation/ForeignPropertyNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import controllers.foreign.allowances.routes._
import controllers.foreign.expenses.routes._
import controllers.foreign.income.routes._
import controllers.foreign.routes._
import controllers.foreign.structuresbuildingallowance.routes._
import controllers.routes.{IndexController, SummaryController}
import models.ForeignTotalIncome.{LessThanOneThousand, OneThousandAndMore}
import models._
import pages.Page
import pages.foreign._
import pages.foreign.allowances._
import pages.foreign.structurebuildingallowance._
import pages.foreign.expenses._
import pages.foreign.income._
import play.api.mvc.Call
Expand Down Expand Up @@ -103,6 +105,20 @@ class ForeignPropertyNavigator {
taxYear => _ => _ => ForeignOtherCapitalAllowancesController.onPageLoad(taxYear, countryCode, NormalMode)
case ForeignOtherCapitalAllowancesPage(countryCode) => // TODO route to CYA page once created
taxYear => _ => _ => ForeignAllowancesCheckYourAnswersController.onPageLoad(taxYear, countryCode)

// Allowances - SBA
case ForeignClaimStructureBuildingAllowancePage(countryCode) =>
taxYear => _ => userAnswers => foreignSbaNavigation(taxYear, userAnswers, countryCode)
case ForeignStructureBuildingQualifyingDatePage(countryCode, index) =>
taxYear => _ => _ => ForeignStructureBuildingQualifyingAmountController.onPageLoad(taxYear, countryCode, index, NormalMode)
case ForeignStructureBuildingQualifyingAmountPage(countryCode, index) =>
taxYear => _ => _ => ForeignStructureBuildingAllowanceClaimController.onPageLoad(taxYear, countryCode, index, NormalMode)
case ForeignStructureBuildingAllowanceClaimPage(countryCode, index) =>
taxYear => _ => _ => ForeignStructuresBuildingAllowanceAddressController.onPageLoad(taxYear, index, countryCode, NormalMode)
case ForeignStructuresBuildingAllowanceAddressPage(index, countryCode) =>
// TODO - CYA - route to cya once created
taxYear => _ => _ => SummaryController.show(taxYear)

case _ => _ => _ => _ => controllers.routes.IndexController.onPageLoad
}

Expand Down Expand Up @@ -309,4 +325,16 @@ class ForeignPropertyNavigator {
case _ =>
ForeignTaxCheckYourAnswersController.onSubmit(taxYear, countryCode)
}

private def foreignSbaNavigation(
taxYear: Int,
userAnswers: UserAnswers,
countryCode: String
): Call =
userAnswers.get(ForeignClaimStructureBuildingAllowancePage(countryCode)) match {
case Some(true) => ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode)
// TODO - redirect to CYA
case Some(false) => ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode)
case _ => SummaryController.show(taxYear)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ package pages.foreign.structurebuildingallowance
case class ForeignStructureBuildingAllowancePage(
taxYear: Int,
countryCode: String,
nextIndex: Int,
individualOrAgent: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="govuk-heading-l">@messages("foreignStructureBuildingAllowance.heading
<p class="govuk-body">
@govukButton(
ButtonViewModel(messages("foreignStructureBuildingAllowance.button"))
.asLink(routes.ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(page.taxYear, page.countryCode).url)
.asLink(routes.ForeignStructureBuildingQualifyingDateController.onPageLoad(page.taxYear, page.countryCode, page.nextIndex, NormalMode).url)
.withId("continue")
)
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ForeignAddClaimStructureBuildingAllowanceControllerSpec extends SpecBase {

val taxYear = 2024
val isAgent = true
val nextIndex = 0
val countryCode = "AUS"

s"must return OK and the correct view for a GET" in {
Expand Down Expand Up @@ -59,6 +60,7 @@ class ForeignAddClaimStructureBuildingAllowanceControllerSpec extends SpecBase {
ForeignStructureBuildingAllowancePage(
taxYear = taxYear,
countryCode = countryCode,
nextIndex = nextIndex,
individualOrAgent = "agent"
)
)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import controllers.foreign.structuresbuildingallowance.routes.ForeignStructuresB
import controllers.routes
import forms.foreign.structurebuildingallowance.ForeignStructuresBuildingAllowanceAddressFormProvider
import models.{ForeignStructuresBuildingAllowanceAddress, NormalMode, UserAnswers}
import navigation.{FakeNavigator, Navigator}
import navigation.{FakeForeignPropertyNavigator, ForeignPropertyNavigator}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatestplus.mockito.MockitoSugar
Expand Down Expand Up @@ -109,7 +109,7 @@ class ForeignStructuresBuildingAllowanceAddressControllerSpec extends SpecBase w
val application =
applicationBuilder(userAnswers = Some(emptyUserAnswers), isAgent = false)
.overrides(
bind[Navigator].toInstance(new FakeNavigator(onwardRoute)),
bind[ForeignPropertyNavigator].toInstance(new FakeForeignPropertyNavigator(onwardRoute)),
bind[SessionRepository].toInstance(mockSessionRepository)
)
.build()
Expand Down

0 comments on commit 27bf6a7

Please sign in to comment.