Skip to content

Commit

Permalink
Merge pull request #65 from hmrc/DAC6-3060
Browse files Browse the repository at this point in the history
DAC6-3060: Navigation fixes and placeholder text resolved
  • Loading branch information
Vishakha1903 authored May 28, 2024
2 parents 250077d + 747cfcf commit 6f12d94
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import forms.addFinancialInstitution.ContactHavePhoneFormProvider
import models.Mode
import navigation.Navigator
import pages.addFinancialInstitution.{ContactHavePhonePage, ContactNamePage}
import play.api.data.Form
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
Expand All @@ -46,33 +47,36 @@ class ContactHavePhoneController @Inject() (
with I18nSupport
with ContactHelper {

val form = formProvider()
val fi = "Placeholder Financial Institution" // todo: pull in this when available
val form: Form[Boolean] = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
val ua = request.userAnswers
val preparedForm = request.userAnswers.get(ContactHavePhonePage) match {
val ua = request.userAnswers
val contactName = ua.get(ContactNamePage)
val fi = getFinancialInstitutionName(ua)

val preparedForm = ua.get(ContactHavePhonePage) match {
case None => form
case Some(value) => form.fill(value)
}
val contactName = ua.get(ContactNamePage)
contactName match {
case None => Redirect(controllers.routes.IndexController.onPageLoad)
case None => Redirect(controllers.routes.IndexController.onPageLoad())
case Some(contactName) => Ok(view(preparedForm, mode, fi, contactName))

}
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
val ua = request.userAnswers
val fi = getFinancialInstitutionName(ua)
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, fi, getFirstContactName(request.userAnswers)))),
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, fi, getFirstContactName(ua)))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(ContactHavePhonePage, value))
updatedAnswers <- Future.fromTry(ua.set(ContactHavePhonePage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(ContactHavePhonePage, mode, updatedAnswers))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import forms.addFinancialInstitution.FirstContactEmailFormProvider
import models.Mode
import navigation.Navigator
import pages.addFinancialInstitution.{ContactNamePage, FirstContactEmailPage}
import play.api.data.Form
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import utils.ContactHelper
import views.html.addFinancialInstitution.FirstContactEmailView

import javax.inject.Inject
Expand All @@ -42,32 +44,35 @@ class FirstContactEmailController @Inject() (
view: FirstContactEmailView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {
with I18nSupport
with ContactHelper {

val form = formProvider()
val fi = "Placeholder Financial Institution" // todo: pull in this when available
val form: Form[String] = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
val ua = request.userAnswers
val fi = getFinancialInstitutionName(ua)

val preparedForm = ua.get(FirstContactEmailPage) match {
case None => form
case Some(value) => form.fill(value)
}
val contactName = ua.get(ContactNamePage)
contactName match {
case None => Redirect(controllers.routes.IndexController.onPageLoad)
case None => Redirect(controllers.routes.IndexController.onPageLoad())
case Some(name) => Ok(view(preparedForm, mode, fi, name))
}
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
request.userAnswers
.get(ContactNamePage)
val ua = request.userAnswers
val fi = getFinancialInstitutionName(ua)

ua.get(ContactNamePage)
.fold {
Future.successful(Redirect(controllers.routes.IndexController.onPageLoad))
Future.successful(Redirect(controllers.routes.IndexController.onPageLoad()))
} {
name =>
form
Expand All @@ -76,7 +81,7 @@ class FirstContactEmailController @Inject() (
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, fi, name))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(FirstContactEmailPage, value))
updatedAnswers <- Future.fromTry(ua.set(FirstContactEmailPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(FirstContactEmailPage, mode, updatedAnswers))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import forms.addFinancialInstitution.SecondContactEmailFormProvider
import models.Mode
import navigation.Navigator
import pages.addFinancialInstitution.{SecondContactEmailPage, SecondContactNamePage}
import play.api.data.Form
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import utils.ContactHelper
import views.html.addFinancialInstitution.SecondContactEmailView

import javax.inject.Inject
Expand All @@ -42,32 +44,35 @@ class SecondContactEmailController @Inject() (
view: SecondContactEmailView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {
with I18nSupport
with ContactHelper {

val form = formProvider()
val fi = "Placeholder Financial Institution" // todo: pull in this when available
val form: Form[String] = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
val ua = request.userAnswers
val fi = getFinancialInstitutionName(ua)

val preparedForm = ua.get(SecondContactEmailPage) match {
case None => form
case Some(value) => form.fill(value)
}

val secondContactName = ua.get(SecondContactNamePage)
secondContactName match {
case None => Redirect(controllers.routes.IndexController.onPageLoad)
case None => Redirect(controllers.routes.IndexController.onPageLoad())
case Some(name) => Ok(view(preparedForm, mode, fi, name))
}
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
request.userAnswers
.get(SecondContactNamePage)
val ua = request.userAnswers
val fi = getFinancialInstitutionName(ua)

ua.get(SecondContactNamePage)
.fold {
Future.successful(Redirect(controllers.routes.IndexController.onPageLoad))
Future.successful(Redirect(controllers.routes.IndexController.onPageLoad()))
} {
name =>
form
Expand All @@ -76,7 +81,7 @@ class SecondContactEmailController @Inject() (
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, fi, name))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(SecondContactEmailPage, value))
updatedAnswers <- Future.fromTry(ua.set(SecondContactEmailPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(SecondContactEmailPage, mode, updatedAnswers))
)
Expand Down
11 changes: 4 additions & 7 deletions app/navigation/Navigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,15 @@ class Navigator @Inject() () {
userAnswers,
HaveGIINPage,
routes.WhatIsGIINController.onPageLoad(NormalMode),
controllers.routes.IndexController.onPageLoad
routes.WhereIsFIBasedController.onPageLoad(NormalMode)
)
case UkAddressPage => _ => routes.ContactNameController.onPageLoad(NormalMode)
case NonUkAddressPage => _ => routes.ContactNameController.onPageLoad(NormalMode)
case _ =>
_ => controllers.routes.IndexController.onPageLoad
_ => controllers.routes.IndexController.onPageLoad()
}

private val checkRouteMap: Page => UserAnswers => Call = {
case _ =>
_ => routes.CheckYourAnswersController.onPageLoad
}
private val checkRouteMap: Page => UserAnswers => Call = _ => _ => routes.CheckYourAnswersController.onPageLoad

private def addressLookupNavigation(mode: Mode)(ua: UserAnswers): Call =
ua.get(AddressLookupPage) match {
Expand All @@ -129,7 +126,7 @@ class Navigator @Inject() () {
private def yesNoPage(ua: UserAnswers, fromPage: QuestionPage[Boolean], yesCall: => Call, noCall: => Call): Call =
ua.get(fromPage)
.map(if (_) yesCall else noCall)
.getOrElse(controllers.routes.JourneyRecoveryController.onPageLoad)
.getOrElse(controllers.routes.JourneyRecoveryController.onPageLoad())

def nextPage(page: Page, mode: Mode, userAnswers: UserAnswers): Call = mode match {
case NormalMode =>
Expand Down
13 changes: 0 additions & 13 deletions conf/application-json-logger.xml

This file was deleted.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sbt.version=1.9.7
sbt.version=1.9.9
hmrc-frontend-scaffold.version=0.30.0
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import navigation.{FakeNavigator, Navigator}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatestplus.mockito.MockitoSugar
import pages.addFinancialInstitution.{ContactHavePhonePage, ContactNamePage}
import pages.addFinancialInstitution._
import play.api.inject.bind
import play.api.mvc.Call
import play.api.test.FakeRequest
Expand All @@ -43,13 +43,17 @@ class ContactHavePhoneControllerSpec extends SpecBase with MockitoSugar {
lazy val contactHavePhoneRoute = routes.ContactHavePhoneController.onPageLoad(NormalMode).url
val contactName = "Mr Test"
val financialInstitution = "Placeholder Financial Institution"
private val userAnswers = emptyUserAnswers.set(ContactNamePage, contactName).get

private val ua =
emptyUserAnswers
.withPage(ContactNamePage, contactName)
.withPage(NameOfFinancialInstitutionPage, financialInstitution)

"ContactHavePhone Controller" - {

"must return OK and the correct view for a GET" in {

val application = applicationBuilder(userAnswers = Some(userAnswers)).build()
val application = applicationBuilder(userAnswers = Some(ua)).build()

running(application) {
val request = FakeRequest(GET, contactHavePhoneRoute)
Expand All @@ -64,13 +68,7 @@ class ContactHavePhoneControllerSpec extends SpecBase with MockitoSugar {
}

"must populate the view correctly on a GET when the question has previously been answered" in {
val userAnswers = emptyUserAnswers
.set(ContactNamePage, contactName)
.success
.value
.set(ContactHavePhonePage, true)
.success
.value
val userAnswers = ua.withPage(ContactHavePhonePage, true)

val application = applicationBuilder(userAnswers = Some(userAnswers)).build()

Expand Down Expand Up @@ -114,7 +112,7 @@ class ContactHavePhoneControllerSpec extends SpecBase with MockitoSugar {

"must return a Bad Request and errors when invalid data is submitted" in {

val application = applicationBuilder(userAnswers = Some(userAnswers)).build()
val application = applicationBuilder(userAnswers = Some(ua)).build()

running(application) {
val request =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import navigation.{FakeNavigator, Navigator}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatestplus.mockito.MockitoSugar
import pages.addFinancialInstitution.{ContactNamePage, FirstContactEmailPage}
import pages.addFinancialInstitution.{ContactNamePage, FirstContactEmailPage, NameOfFinancialInstitutionPage}
import play.api.inject.bind
import play.api.mvc.Call
import play.api.test.FakeRequest
Expand All @@ -44,7 +44,10 @@ class FirstContactEmailControllerSpec extends SpecBase with MockitoSugar {

val contactName = "Mr Test"
val financialInstitution = "Placeholder Financial Institution"
private val ua = emptyUserAnswers.set(ContactNamePage, contactName).get

private val ua = emptyUserAnswers
.withPage(ContactNamePage, contactName)
.withPage(NameOfFinancialInstitutionPage, financialInstitution)

"FirstContactEmail Controller" - {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import navigation.{FakeNavigator, Navigator}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatestplus.mockito.MockitoSugar
import pages.addFinancialInstitution.{SecondContactEmailPage, SecondContactNamePage}
import pages.addFinancialInstitution._
import play.api.inject.bind
import play.api.mvc.Call
import play.api.test.FakeRequest
Expand All @@ -41,9 +41,12 @@ class SecondContactEmailControllerSpec extends SpecBase with MockitoSugar {
val form = formProvider()
val contactName = "Mr Test"
val financialInstitution = "Placeholder Financial Institution"
private val ua = emptyUserAnswers.set(SecondContactNamePage, contactName).get

lazy val secondContactEmailRoute = routes.SecondContactEmailController.onPageLoad(NormalMode).url
private val ua = emptyUserAnswers
.withPage(SecondContactNamePage, contactName)
.withPage(NameOfFinancialInstitutionPage, financialInstitution)

private lazy val secondContactEmailRoute = routes.SecondContactEmailController.onPageLoad(NormalMode).url

"SecondContactEmail Controller" - {

Expand Down
6 changes: 6 additions & 0 deletions test/navigation/NavigatorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ class NavigatorSpec extends SpecBase {
routes.WhatIsGIINController.onPageLoad(NormalMode)
}

"must go from HaveGIIN to WhereIsFIBased when user answer is no" in {
val userAnswers = emptyUserAnswers.withPage(HaveGIINPage, false)
navigator.nextPage(HaveGIINPage, NormalMode, userAnswers) mustBe
routes.WhereIsFIBasedController.onPageLoad(NormalMode)
}

"must go from WhatIsGIIN to WhereIsFIBased when user answers yes" in {
val userAnswers = emptyUserAnswers.withPage(WhatIsGIINPage, "answer")
navigator.nextPage(WhatIsGIINPage, NormalMode, userAnswers) mustBe
Expand Down

0 comments on commit 6f12d94

Please sign in to comment.