Skip to content

Commit

Permalink
Merge pull request #11 from hmrc/hipp-200
Browse files Browse the repository at this point in the history
HIPP-200: Add Application Name to Check Your Answers
  • Loading branch information
PaulCDurham authored Jan 10, 2023
2 parents d14189b + 036f213 commit 0b9ca5c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/controllers/CheckYourAnswersController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import controllers.actions.{DataRequiredAction, DataRetrievalAction, IdentifierA
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import viewmodels.checkAnswers.ApplicationNameSummary
import viewmodels.govuk.summarylist._
import views.html.CheckYourAnswersView

Expand All @@ -37,7 +38,9 @@ class CheckYourAnswersController @Inject()(
implicit request =>

val list = SummaryListViewModel(
rows = Seq.empty
rows = Seq(
ApplicationNameSummary.row(request.userAnswers)
).flatten
)

Ok(view(list))
Expand Down
45 changes: 42 additions & 3 deletions test/controllers/CheckYourAnswersControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@
package controllers

import base.SpecBase
import controllers.CheckYourAnswersControllerSpec.buildSummaryList
import generators.Generators
import models.UserAnswers
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
import play.api.i18n.Messages
import play.api.test.FakeRequest
import play.api.test.Helpers._
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryList
import viewmodels.checkAnswers.ApplicationNameSummary
import viewmodels.govuk.SummaryListFluency
import views.html.CheckYourAnswersView

class CheckYourAnswersControllerSpec extends SpecBase with SummaryListFluency {
class CheckYourAnswersControllerSpec extends SpecBase with SummaryListFluency with ScalaCheckPropertyChecks with Generators {

"Check Your Answers Controller" - {

"must return OK and the correct view for a GET" in {
"must return OK and the correct view for a GET with empty user answers" in {

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

Expand All @@ -36,13 +43,33 @@ class CheckYourAnswersControllerSpec extends SpecBase with SummaryListFluency {
val result = route(application, request).value

val view = application.injector.instanceOf[CheckYourAnswersView]
val list = SummaryListViewModel(Seq.empty)
val list = buildSummaryList(emptyUserAnswers, messages(application))

status(result) mustEqual OK
contentAsString(result) mustEqual view(list)(request, messages(application)).toString
}
}

"must return OK and the correct view for a GET with complete user answers" in {

forAll((userAnswers: UserAnswers) => {
val application = applicationBuilder(userAnswers = Some(userAnswers)).build()

running(application) {
val request = FakeRequest(GET, routes.CheckYourAnswersController.onPageLoad.url)

val result = route(application, request).value

val view = application.injector.instanceOf[CheckYourAnswersView]
val list = buildSummaryList(userAnswers, messages(application))

status(result) mustEqual OK
contentAsString(result) mustEqual view(list)(request, messages(application)).toString
}
})

}

"must redirect to Journey Recovery for a GET if no existing data is found" in {

val application = applicationBuilder(userAnswers = None).build()
Expand All @@ -58,3 +85,15 @@ class CheckYourAnswersControllerSpec extends SpecBase with SummaryListFluency {
}
}
}

object CheckYourAnswersControllerSpec extends SummaryListFluency {

def buildSummaryList(userAnswers: UserAnswers, messages: Messages): SummaryList = {
SummaryListViewModel(
Seq(
ApplicationNameSummary.row(userAnswers)(messages)
).flatten
)
}

}

0 comments on commit 0b9ca5c

Please sign in to comment.