Skip to content

Commit

Permalink
Merge pull request #11 from hmrc/DAC6-2734
Browse files Browse the repository at this point in the history
DAC6-2734: QA issues addressed
  • Loading branch information
Vishakha1903 authored Dec 20, 2023
2 parents 43fd45c + 6186d2f commit 3ab25f5
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 18 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
.js-enabled .js-visible {
display: inline-block !important;
}
.wrappable {
display: inline-block;
word-break: break-word;
}
9 changes: 5 additions & 4 deletions app/controllers/FirstContactEmailController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class FirstContactEmailController @Inject() (
with I18nSupport {

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

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
Expand All @@ -54,10 +55,10 @@ class FirstContactEmailController @Inject() (
case None => form
case Some(value) => form.fill(value)
}

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

Expand All @@ -72,7 +73,7 @@ class FirstContactEmailController @Inject() (
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, name))),
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, fi, name))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(FirstContactEmailPage, value))
Expand Down
8 changes: 6 additions & 2 deletions app/forms/FirstContactEmailFormProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ class FirstContactEmailFormProvider @Inject() extends Mappings {
def apply(): Form[String] =
Form(
"value" -> text("firstContactEmail.error.required")
.verifying(maxLength(132, "firstContactEmail.error.length"))
.verifying(Constraints.emailAddress(errorMessage = "firstContactEmail.error.format"))
.verifying(
firstError(
maxLength(132, "firstContactEmail.error.length"),
Constraints.emailAddress(errorMessage = "firstContactEmail.error.format")
)
)
)

}
3 changes: 3 additions & 0 deletions app/viewmodels/govuk/LabelFluency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ trait LabelFluency {
def forAttr(attr: String): Label =
label.copy(forAttr = Some(attr))

def visuallyHidden(): Label =
label.withCssClass("govuk-visually-hidden")

}

}
17 changes: 10 additions & 7 deletions app/views/FirstContactEmailView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
*@

@import viewmodels.InputWidth._
@import components._

@this(
layout: templates.Layout,
formHelper: FormWithCSRF,
govukErrorSummary: GovukErrorSummary,
govukInput: GovukInput,
govukButton: GovukButton
govukButton: GovukButton,
paragraph: Paragraph,
heading: Heading,
)

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

@paraContent = {@messages("firstContactEmail.p1", name)}
@(form: Form[_], mode: Mode, finInstitution: String, name: String)(implicit request: Request[_], messages: Messages)

@layout(pageTitle = title(form, messages("firstContactEmail.title", name))) {

Expand All @@ -36,15 +37,17 @@
@govukErrorSummary(ErrorSummaryViewModel(form))
}

@heading(messages("firstContactEmail.heading", name))

@paragraph(Html(messages("firstContactEmail.p1", finInstitution)))

@govukInput(
InputViewModel(
field = form("value"),
label = LabelViewModel(messages("firstContactEmail.heading", name)).asPageHeading()
label = LabelViewModel(messages("firstContactEmail.heading", name)).visuallyHidden()
)
.withWidth(Full)
.withHint(Hint(content = HtmlContent(paraContent)))
.asEmail()

)

@govukButton(
Expand Down
21 changes: 21 additions & 0 deletions app/views/components/Heading.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@this()

@(headingContent: String, size: String = "l")

<h1 class="govuk-heading-@size wrappable" >@headingContent</h1>
21 changes: 21 additions & 0 deletions app/views/components/Paragraph.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@this()

@(content: Html, classes: String = "govuk-body", id: Option[String] = None)

<p class="@classes wrappable" @id.map{id => id="@id"}>@content</p>
11 changes: 6 additions & 5 deletions test/controllers/FirstContactEmailControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class FirstContactEmailControllerSpec extends SpecBase with MockitoSugar {

private lazy val firstContactEmailRoute = routes.FirstContactEmailController.onPageLoad(NormalMode).url

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

"FirstContactEmail Controller" - {

Expand All @@ -59,7 +60,7 @@ class FirstContactEmailControllerSpec extends SpecBase with MockitoSugar {
val view = application.injector.instanceOf[FirstContactEmailView]

status(result) mustEqual OK
contentAsString(result) mustEqual view(form, NormalMode, contactName)(request, messages(application)).toString
contentAsString(result) mustEqual view(form, NormalMode, financialInstitution, contactName)(request, messages(application)).toString
}
}

Expand All @@ -77,7 +78,7 @@ class FirstContactEmailControllerSpec extends SpecBase with MockitoSugar {
val result = route(application, request).value

status(result) mustEqual OK
contentAsString(result) mustEqual view(form.fill("answer"), NormalMode, contactName)(request, messages(application)).toString
contentAsString(result) mustEqual view(form.fill("answer"), NormalMode, financialInstitution, contactName)(request, messages(application)).toString
}
}

Expand Down Expand Up @@ -123,7 +124,7 @@ class FirstContactEmailControllerSpec extends SpecBase with MockitoSugar {
val result = route(application, request).value

status(result) mustEqual BAD_REQUEST
contentAsString(result) mustEqual view(boundForm, NormalMode, contactName)(request, messages(application)).toString
contentAsString(result) mustEqual view(boundForm, NormalMode, financialInstitution, contactName)(request, messages(application)).toString
}
}

Expand Down

0 comments on commit 3ab25f5

Please sign in to comment.