Skip to content

Commit

Permalink
Merge pull request #12 from hmrc/product-volume-p-hint-fix
Browse files Browse the repository at this point in the history
Product Volume: Replace <p> with Hint + Remove "Question"
  • Loading branch information
yasaracar authored Dec 11, 2023
2 parents 75c3bdd + 8f1b6d7 commit 71f2296
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,36 @@ package controllers

import connectors.CacheConnector
import controllers.actions._
import forms.ProductVolumeQuestionFormProvider
import forms.ProductVolumeFormProvider
import javax.inject.Inject
import models.Mode
import navigation.Navigator
import pages.ProductVolumeQuestionPage
import pages.ProductVolumePage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.ProductVolumeQuestionView
import views.html.ProductVolumeView

import scala.concurrent.{ExecutionContext, Future}

class ProductVolumeQuestionController @Inject() (
class ProductVolumeController @Inject() (
override val messagesApi: MessagesApi,
cacheConnector: CacheConnector,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: ProductVolumeQuestionFormProvider,
formProvider: ProductVolumeFormProvider,
val controllerComponents: MessagesControllerComponents,
view: ProductVolumeQuestionView
view: ProductVolumeView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { implicit request =>
val preparedForm = request.userAnswers.get(ProductVolumeQuestionPage) match {
val preparedForm = request.userAnswers.get(ProductVolumePage) match {
case None => form
case Some(value) => form.fill(value)
}
Expand All @@ -63,9 +63,9 @@ class ProductVolumeQuestionController @Inject() (
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(ProductVolumeQuestionPage, value))
updatedAnswers <- Future.fromTry(request.userAnswers.set(ProductVolumePage, value))
_ <- cacheConnector.set(updatedAnswers)
} yield Redirect(navigator.nextPage(ProductVolumeQuestionPage, mode, updatedAnswers))
} yield Redirect(navigator.nextPage(ProductVolumePage, mode, updatedAnswers))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import forms.mappings.Mappings
import javax.inject.Inject
import play.api.data.Form

class ProductVolumeQuestionFormProvider @Inject() extends Mappings {
class ProductVolumeFormProvider @Inject() extends Mappings {

def apply(): Form[BigDecimal] =
Form(
"product-volume-input" -> bigDecimal(
"productVolumeQuestion.error.required",
"productVolumeQuestion.error.nonNumeric",
"productVolumeQuestion.error.twoDecimalPlaces"
"productVolume.error.required",
"productVolume.error.nonNumeric",
"productVolume.error.twoDecimalPlaces"
)
.verifying(minimumValue(BigDecimal(0.01), "productVolumeQuestion.error.minimumRequired"))
.verifying(maximumValue(BigDecimal(999999999.99), "productVolumeQuestion.error.maximumRequired"))
.verifying(minimumValue(BigDecimal(0.01), "productVolume.error.minimumRequired"))
.verifying(maximumValue(BigDecimal(999999999.99), "productVolume.error.maximumRequired"))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package pages

import play.api.libs.json.JsPath

case object ProductVolumeQuestionPage extends QuestionPage[BigDecimal] {
case object ProductVolumePage extends QuestionPage[BigDecimal] {

override def path: JsPath = JsPath \ toString

override def toString: String = "productVolumeQuestion"
override def toString: String = "productVolume"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ package viewmodels.checkAnswers

import controllers.routes
import models.{CheckMode, UserAnswers}
import pages.ProductVolumeQuestionPage
import pages.ProductVolumePage
import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

object ProductVolumeQuestionSummary {
object ProductVolumeSummary {

def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] =
answers.get(ProductVolumeQuestionPage).map { answer =>
answers.get(ProductVolumePage).map { answer =>
SummaryListRowViewModel(
key = "productVolumeQuestion.checkYourAnswersLabel",
key = "productVolume.checkYourAnswersLabel",
value = ValueViewModel(answer.toString),
actions = Seq(
ActionItemViewModel("site.change", routes.ProductVolumeQuestionController.onPageLoad(CheckMode).url)
.withVisuallyHiddenText(messages("productVolumeQuestion.change.hidden"))
ActionItemViewModel("site.change", routes.ProductVolumeController.onPageLoad(CheckMode).url)
.withVisuallyHiddenText(messages("productVolume.change.hidden"))
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages)

@layout(pageTitle = title(form, messages("productVolumeQuestion.title"))) {
@layout(pageTitle = title(form, messages("productVolume.title"))) {

@formHelper(action = routes.ProductVolumeQuestionController.onSubmit(mode), Symbol("autoComplete") -> "off") {
@formHelper(action = routes.ProductVolumeController.onSubmit(mode), Symbol("autoComplete") -> "off") {

@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
Expand All @@ -43,19 +43,15 @@
text = messages("section.alcoholDutyReturn"),
)

@pageHeading(messages("productVolumeQuestion.heading"))

<p class="govuk-body">@messages("productVolumeQuestion.p1")</p>

@govukInput(
InputViewModel(
field = form("product-volume-input"),
label = LabelViewModel(messages("productVolumeQuestion.heading")).asVisuallyHidden(),
label = LabelViewModel(messages("productVolume.heading")).asPageHeading(),
)
.asNumeric()
.withWidth(Fixed10)
.withSuffix(PrefixOrSuffix(content = messages("productVolumeQuestion.inputSuffix")))

.withSuffix(PrefixOrSuffix(content = messages("productVolume.inputSuffix")))
.withHint(Hint(content = HtmlContent(messages("productVolume.hint"))))
)

@govukButton(
Expand Down
8 changes: 4 additions & 4 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ POST /alcoholByVolumeQuestion controllers.AlcoholByVolume
GET /changeAlcoholByVolumeQuestion controllers.AlcoholByVolumeQuestionController.onPageLoad(mode: Mode = CheckMode)
POST /changeAlcoholByVolumeQuestion controllers.AlcoholByVolumeQuestionController.onSubmit(mode: Mode = CheckMode)

GET /productVolumeQuestion controllers.ProductVolumeQuestionController.onPageLoad(mode: Mode = NormalMode)
POST /productVolumeQuestion controllers.ProductVolumeQuestionController.onSubmit(mode: Mode = NormalMode)
GET /changeProductVolumeQuestion controllers.ProductVolumeQuestionController.onPageLoad(mode: Mode = CheckMode)
POST /changeProductVolumeQuestion controllers.ProductVolumeQuestionController.onSubmit(mode: Mode = CheckMode)
GET /productVolume controllers.ProductVolumeController.onPageLoad(mode: Mode = NormalMode)
POST /productVolume controllers.ProductVolumeController.onSubmit(mode: Mode = NormalMode)
GET /changeProductVolume controllers.ProductVolumeController.onPageLoad(mode: Mode = CheckMode)
POST /changeProductVolume controllers.ProductVolumeController.onSubmit(mode: Mode = CheckMode)

GET /declareDutySuspendedDeliveriesQuestion controllers.DeclareDutySuspendedDeliveriesQuestionController.onPageLoad(mode: Mode = NormalMode)
POST /declareDutySuspendedDeliveriesQuestion controllers.DeclareDutySuspendedDeliveriesQuestionController.onSubmit(mode: Mode = NormalMode)
Expand Down
22 changes: 11 additions & 11 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ alcoholByVolumeQuestion.error.maximumRequired = This product’s Alcohol by Volu
alcoholByVolumeQuestion.error.twoDecimalPlaces = This product’s Alcohol by Volume (ABV) must be a number to two decimal places
alcoholByVolumeQuestion.change.hidden = Alcohol by Volume (ABV) strength

productVolumeQuestion.title = How much of this product do you need to declare?
productVolumeQuestion.heading = How much of this product do you need to declare?
productVolumeQuestion.p1 = Give your answers in litres, to 2 decimal places. For example, 500.50
productVolumeQuestion.inputSuffix = litres
productVolumeQuestion.checkYourAnswersLabel = ProductVolumeQuestion
productVolumeQuestion.error.nonNumeric = This product’s volume must be a number
productVolumeQuestion.error.required = Enter how much of this product you need to declare
productVolumeQuestion.error.minimumRequired = This product’s volume must be 0.01 or more
productVolumeQuestion.error.maximumRequired = This product’s volume must be 999999999.99 or less
productVolumeQuestion.error.twoDecimalPlaces = This product’s volume must be a number to 2 decimal places
productVolumeQuestion.change.hidden = Product volume
productVolume.title = How much of this product do you need to declare?
productVolume.heading = How much of this product do you need to declare?
productVolume.hint = Give your answers in litres, to 2 decimal places. For example, 500.50
productVolume.inputSuffix = litres
productVolume.checkYourAnswersLabel = ProductVolume
productVolume.error.nonNumeric = This product’s volume must be a number
productVolume.error.required = Enter how much of this product you need to declare
productVolume.error.minimumRequired = This product’s volume must be 0.01 or more
productVolume.error.maximumRequired = This product’s volume must be 999999999.99 or less
productVolume.error.twoDecimalPlaces = This product’s volume must be a number to 2 decimal places
productVolume.change.hidden = Product volume

declareDutySuspendedDeliveriesQuestion.title = Do you need to declare alcohol you delivered or received duty suspended?
declareDutySuspendedDeliveriesQuestion.heading = Do you need to declare alcohol you delivered or received duty suspended?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,45 @@ package controllers

import base.SpecBase
import connectors.CacheConnector
import forms.ProductVolumeQuestionFormProvider
import forms.ProductVolumeFormProvider
import models.{NormalMode, UserAnswers}
import navigation.{FakeNavigator, Navigator}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatestplus.mockito.MockitoSugar
import pages.ProductVolumeQuestionPage
import pages.ProductVolumePage
import play.api.inject.bind
import play.api.mvc.Call
import play.api.test.FakeRequest
import play.api.test.Helpers._
import uk.gov.hmrc.http.HttpResponse
import views.html.ProductVolumeQuestionView
import views.html.ProductVolumeView

import scala.concurrent.Future

class ProductVolumeQuestionControllerSpec extends SpecBase with MockitoSugar {
class ProductVolumeControllerSpec extends SpecBase with MockitoSugar {

val formProvider = new ProductVolumeQuestionFormProvider()
val formProvider = new ProductVolumeFormProvider()
val form = formProvider()

def onwardRoute = Call("GET", "/foo")

val validAnswer = BigDecimal(10.23)

lazy val productVolumeQuestionRoute = routes.ProductVolumeQuestionController.onPageLoad(NormalMode).url
lazy val productVolumeRoute = routes.ProductVolumeController.onPageLoad(NormalMode).url

"ProductVolumeQuestion Controller" - {
"ProductVolume Controller" - {

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

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

running(application) {
val request = FakeRequest(GET, productVolumeQuestionRoute)
val request = FakeRequest(GET, productVolumeRoute)

val result = route(application, request).value

val view = application.injector.instanceOf[ProductVolumeQuestionView]
val view = application.injector.instanceOf[ProductVolumeView]

status(result) mustEqual OK
contentAsString(result) mustEqual view(form, NormalMode)(request, messages(application)).toString
Expand All @@ -65,14 +65,14 @@ class ProductVolumeQuestionControllerSpec extends SpecBase with MockitoSugar {

"must populate the view correctly on a GET when the question has previously been answered" in {

val userAnswers = UserAnswers(userAnswersId).set(ProductVolumeQuestionPage, validAnswer).success.value
val userAnswers = UserAnswers(userAnswersId).set(ProductVolumePage, validAnswer).success.value

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

running(application) {
val request = FakeRequest(GET, productVolumeQuestionRoute)
val request = FakeRequest(GET, productVolumeRoute)

val view = application.injector.instanceOf[ProductVolumeQuestionView]
val view = application.injector.instanceOf[ProductVolumeView]

val result = route(application, request).value

Expand Down Expand Up @@ -100,7 +100,7 @@ class ProductVolumeQuestionControllerSpec extends SpecBase with MockitoSugar {

running(application) {
val request =
FakeRequest(POST, productVolumeQuestionRoute)
FakeRequest(POST, productVolumeRoute)
.withFormUrlEncodedBody(("product-volume-input", validAnswer.toString))

val result = route(application, request).value
Expand All @@ -116,12 +116,12 @@ class ProductVolumeQuestionControllerSpec extends SpecBase with MockitoSugar {

running(application) {
val request =
FakeRequest(POST, productVolumeQuestionRoute)
FakeRequest(POST, productVolumeRoute)
.withFormUrlEncodedBody(("value", "invalid value"))

val boundForm = form.bind(Map("value" -> "invalid value"))

val view = application.injector.instanceOf[ProductVolumeQuestionView]
val view = application.injector.instanceOf[ProductVolumeView]

val result = route(application, request).value

Expand All @@ -135,7 +135,7 @@ class ProductVolumeQuestionControllerSpec extends SpecBase with MockitoSugar {
val application = applicationBuilder(userAnswers = None).build()

running(application) {
val request = FakeRequest(GET, productVolumeQuestionRoute)
val request = FakeRequest(GET, productVolumeRoute)

val result = route(application, request).value

Expand All @@ -150,7 +150,7 @@ class ProductVolumeQuestionControllerSpec extends SpecBase with MockitoSugar {

running(application) {
val request =
FakeRequest(POST, productVolumeQuestionRoute)
FakeRequest(POST, productVolumeRoute)
.withFormUrlEncodedBody(("value", validAnswer.toString))

val result = route(application, request).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package forms
import forms.behaviours.BigDecimalFieldBehaviours
import play.api.data.FormError
import scala.collection.immutable.ArraySeq
class ProductVolumeQuestionFormProviderSpec extends BigDecimalFieldBehaviours {
class ProductVolumeFormProviderSpec extends BigDecimalFieldBehaviours {

val form = new ProductVolumeQuestionFormProvider()()
val form = new ProductVolumeFormProvider()()

".value" - {

Expand All @@ -41,28 +41,28 @@ class ProductVolumeQuestionFormProviderSpec extends BigDecimalFieldBehaviours {
behave like bigDecimalField(
form,
fieldName,
nonNumericError = FormError(fieldName, "productVolumeQuestion.error.nonNumeric"),
twoDecimalPlacesError = FormError(fieldName, "productVolumeQuestion.error.twoDecimalPlaces")
nonNumericError = FormError(fieldName, "productVolume.error.nonNumeric"),
twoDecimalPlacesError = FormError(fieldName, "productVolume.error.twoDecimalPlaces")
)

behave like bigDecimalFieldWithMinimum(
form,
fieldName,
minimum = minimum,
expectedError = FormError(fieldName, "productVolumeQuestion.error.minimumRequired", ArraySeq(minimum))
expectedError = FormError(fieldName, "productVolume.error.minimumRequired", ArraySeq(minimum))
)

behave like bigDecimalFieldWithMaximum(
form,
fieldName,
maximum = maximum,
expectedError = FormError(fieldName, "productVolumeQuestion.error.maximumRequired", ArraySeq(999999999.99))
expectedError = FormError(fieldName, "productVolume.error.maximumRequired", ArraySeq(999999999.99))
)

behave like mandatoryField(
form,
fieldName,
requiredError = FormError(fieldName, "productVolumeQuestion.error.required")
requiredError = FormError(fieldName, "productVolume.error.required")
)
}
}

0 comments on commit 71f2296

Please sign in to comment.