From 66fc2eec572d2392f7f3a77f58093bc10e59d12c Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:38:32 +0100 Subject: [PATCH 1/5] NGR-1091 - Amended Landlord page to yes/no radio buttons --- .../controllers/LandlordController.scala | 37 +++++++----- .../models/components/NGRRadio.scala | 2 + .../models/forms/LandlordForm.scala | 12 ++-- conf/messages | 2 + .../controllers/LandlordControllerSpec.scala | 4 +- .../models/forms/LandlordFormSpec.scala | 24 ++++---- .../views/LandlordViewSpec.scala | 58 +++++++++---------- 7 files changed, 75 insertions(+), 64 deletions(-) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala index e9ed6f86..9c3e3b44 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala @@ -23,7 +23,7 @@ import uk.gov.hmrc.govukfrontend.views.Aliases.* import uk.gov.hmrc.http.NotFoundException import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction} import uk.gov.hmrc.ngrraldfrontend.config.AppConfig -import uk.gov.hmrc.ngrraldfrontend.models.components.* +import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadioButtons, *} import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios import uk.gov.hmrc.ngrraldfrontend.models.forms.LandlordForm import uk.gov.hmrc.ngrraldfrontend.models.forms.LandlordForm.form @@ -45,32 +45,39 @@ class LandlordController @Inject()(view: LandlordView, mcc: MessagesControllerComponents )(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport { - def otherRelationship(form: Form[LandlordForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons( - radioContent = "landlord.radio5", - radioValue = OtherRelationship, + + def landlordYesButton(form: Form[LandlordForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons( + radioContent = "service.yes", + radioValue = LandlordYes, conditionalHtml = Some(ngrCharacterCountComponent(form, NGRCharacterCount( - id = "landlord-radio-other", - name = "landlord-radio-other", + id = "landlord-yes", + name = "landlord-yes", maxLength = Some(250), label = Label( classes = "govuk-label govuk-label--s", - content = Text(Messages("landlord.radio5.dropdown")) + content = Text(Messages("landlord.radio.yes")) + ), + hint = Some( + Hint( + id = Some("landlord-yes-hint"), + classes = "", + attributes = Map.empty, + content = Text(messages("landlord.radio.yes.hint")) + ) ) ))) ) def ngrRadio(form: Form[LandlordForm])(implicit messages: Messages): NGRRadio = val ngrRadioButtons: Seq[NGRRadioButtons] = Seq( - NGRRadioButtons(radioContent = "landlord.radio1", radioValue = LandLordAndTenant), - NGRRadioButtons(radioContent = "landlord.radio2", radioValue = FamilyMember), - NGRRadioButtons(radioContent = "landlord.radio3", radioValue = CompanyPensionFund), - NGRRadioButtons(radioContent = "landlord.radio4", radioValue = BusinessPartnerOrSharedDirector) + landlordYesButton(form), + NGRRadioButtons(radioContent = "service.no", radioValue = LandlordNo) ) NGRRadio( NGRRadioName("landlord-radio"), ngrTitle = Some(Legend(content = Text(messages("landlord.p2")), classes = "govuk-fieldset__legend--m", isPageHeading = true)), - NGRRadioButtons = ngrRadioButtons :+ otherRelationship(form) + NGRRadioButtons = ngrRadioButtons ) def show: Action[AnyContent] = { @@ -95,9 +102,9 @@ class LandlordController @Inject()(view: LandlordView, val correctedFormErrors = formWithErrors.errors.map { formError => (formError.key, formError.messages) match case ("", messages) if messages.contains("landlord.radio.other.empty.error") => - formError.copy(key = "landlord-radio-other") + formError.copy(key = "landlord-yes") case ("", messages) if messages.contains("landlord.radio.other.tooLong.error") => - formError.copy(key = "landlord-radio-other") + formError.copy(key = "landlord-yes") case _ => formError } @@ -114,7 +121,7 @@ class LandlordController @Inject()(view: LandlordView, CredId(request.credId.getOrElse("")), landlordForm.landlordName, landlordForm.landLordType, - landlordForm.landlordOther + landlordForm.landlordYesSelected ) Future.successful(Redirect(routes.WhatTypeOfAgreementController.show.url)) ) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala index 52fc372f..4d768ae6 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala @@ -42,6 +42,8 @@ case object FamilyMember extends Landlord case object CompanyPensionFund extends Landlord case object BusinessPartnerOrSharedDirector extends Landlord case object OtherRelationship extends Landlord +case object LandlordYes extends Landlord +case object LandlordNo extends Landlord sealed trait RentBasedOn extends RadioEntry diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala index 3568b40d..9f6f08b2 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala @@ -24,7 +24,7 @@ import play.api.libs.json.{Json, OFormat} import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatIsYourRentBasedOnForm.firstError import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings -final case class LandlordForm(landlordName: String, landLordType: String, landlordOther: Option[String]) +final case class LandlordForm(landlordName: String, landLordType: String, landlordYesSelected: Option[String]) object LandlordForm extends CommonFormValidators with Mappings{ implicit val format: OFormat[LandlordForm] = Json.format[LandlordForm] @@ -37,7 +37,7 @@ object LandlordForm extends CommonFormValidators with Mappings{ private val landlord = "landlord-name-value" private val landlordRadio = "landlord-radio" - private val landlordOther = "landlord-radio-other" + private val landlordYesSelected = "landlord-yes" val messagesApi: MessagesApi = new DefaultMessagesApi() @@ -46,12 +46,12 @@ object LandlordForm extends CommonFormValidators with Mappings{ def unapply(landlordForm: LandlordForm): Option[(String, String, Option[String])] = - Some((landlordForm.landlordName, landlordForm.landLordType, landlordForm.landlordOther)) + Some((landlordForm.landlordName, landlordForm.landLordType, landlordForm.landlordYesSelected)) private def isOtherTextEmpty[A]: Constraint[A] = Constraint((input: A) => val rentBasedOnForm = input.asInstanceOf[LandlordForm] - if (rentBasedOnForm.landLordType.equals("OtherRelationship") && rentBasedOnForm.landlordOther.getOrElse("").isBlank) + if (rentBasedOnForm.landLordType.equals("LandlordYes") && rentBasedOnForm.landlordYesSelected.getOrElse("").isBlank) Invalid(otherRadioEmptyError) else Valid @@ -60,7 +60,7 @@ object LandlordForm extends CommonFormValidators with Mappings{ private def otherTextMaxLength[A]: Constraint[A] = Constraint((input: A) => val rentBasedOnForm = input.asInstanceOf[LandlordForm] - if (rentBasedOnForm.landLordType.equals("OtherRelationship") && rentBasedOnForm.landlordOther.getOrElse("").length > 250) + if (rentBasedOnForm.landLordType.equals("LandlordYes") && rentBasedOnForm.landlordYesSelected.getOrElse("").length > 250) Invalid(otherRadioTooLongError) else Valid @@ -78,7 +78,7 @@ object LandlordForm extends CommonFormValidators with Mappings{ ), landlordRadio -> radioText(radioUnselectedError), - landlordOther -> optional( + landlordYesSelected -> optional( play.api.data.Forms.text .transform[String](_.strip(), identity) ) diff --git a/conf/messages b/conf/messages index 6116235e..aeced8fa 100644 --- a/conf/messages +++ b/conf/messages @@ -67,6 +67,8 @@ landlord.name.empty.error = Enter the landlord''s full name landlord.name.empty.tooLong.error = Landlord''s full name must be 50 characters or less landlord.radio.empty.error = Select what your relationship with the landlord is landlord.radio.other.empty.error = Tell us what your relationship with the landlord is +landlord.radio.yes = Can you tell us what your relationship with the landlord is? +landlord.radio.yes.hint = For example, the landlord is a family member, business partner, shared director or company pension fund landlord.radio.other.tooLong.error = Maximum character allowed is 250 #WhatIsYourRentBasedOn diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala index 6f4b8a58..046d0efe 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala @@ -123,8 +123,8 @@ class LandlordControllerSpec extends ControllerSpecSupport { val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit) .withFormUrlEncodedBody( "landlord-name-value" -> "Bob", - "landlord-radio" -> "OtherRelationship", - "landlordOther" -> "", + "landlord-radio" -> "LandlordYes", + "landlord-yes" -> "", ) .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) result.map(result => { diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala index e49ff151..0866f450 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala @@ -56,11 +56,11 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { boundForm.errors shouldBe List(FormError("landlord-radio", List("landlord.radio.empty.error"), List())) } - it should "fail when 'OtherRelationship' is selected but no description is provided" in { + it should "fail when 'Yes' is selected but no description is provided" in { val data = Map( "landlord-name-value" -> "Jane Doe", - "landlord-radio" -> "OtherRelationship", - "landlord-radio-other" -> " " // whitespace only + "landlord-radio" -> "LandlordYes", + "landlord-yes" -> " " // whitespace only ) val boundForm = LandlordForm.form.bind(data) @@ -68,17 +68,17 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { boundForm.errors shouldBe List(FormError("", List("landlord.radio.other.empty.error"), List())) } - it should "pass when 'OtherRelationship' is selected and description is provided" in { + it should "pass when 'Yes' is selected and description is provided" in { val data = Map( "landlord-name-value" -> "Jane Doe", - "landlord-radio" -> "OtherRelationship", - "landlord-radio-other" -> "Friend of the family" + "landlord-radio" -> "LandlordYes", + "landlord-yes" -> "Friend of the family" ) val boundForm = LandlordForm.form.bind(data) boundForm.errors shouldBe empty - boundForm.value shouldBe Some(LandlordForm("Jane Doe", "OtherRelationship", Some("Friend of the family"))) + boundForm.value shouldBe Some(LandlordForm("Jane Doe", "LandlordYes", Some("Friend of the family"))) } "LandlordForm.unapply" should "extract fields correctly" in { @@ -96,13 +96,13 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { } "LandlordForm.format" should "serialize to JSON correctly" in { - val form = LandlordForm("John Doe", "OtherRelationship", Some("Other info")) + val form = LandlordForm("John Doe", "LandlordYes", Some("Other info")) val json = Json.toJson(form) json shouldBe Json.obj( "landlordName" -> "John Doe", - "landLordType" -> "OtherRelationship", - "landlordOther" -> "Other info" + "landLordType" -> "LandlordYes", + "landlordYesSelected" -> "Other info" ) } @@ -110,7 +110,7 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { val json = Json.obj( "landlordName" -> "Jane Smith", "landLordType" -> "LandLordAndTenant", - "landlordOther" -> JsNull + "landlordYes" -> JsNull ) val result = json.validate[LandlordForm] @@ -120,7 +120,7 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { def validate(form: LandlordForm): Boolean = { form.landLordType != "OtherRelationship" || - form.landlordOther.forall(_.length <= 250) + form.landlordYesSelected.forall(_.length <= 250) } it should "pass if landLordType is OtherRelationship and landlordOther is <= 250 characters" in { diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala index c75b72d1..7ccce790 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala @@ -37,11 +37,11 @@ class LandlordViewSpec extends ViewBaseSpec { val heading = "Landlord" val textInputLabel = "What is the landlord's full name?" val radioLabel = "What is your relationship with the landlord?" - val radio1 = "Landlord and tenant relationship only" - val radio2 = "Family member" - val radio3 = "Company pension fund" - val radio4 = "Business partner or shared director" - val radio5 = "Other relationship" + val radio1 = "Yes" + val radio2 = "No" +// val radio3 = "Company pension fund" +// val radio4 = "Business partner or shared director" +// val radio5 = "Other relationship" val continue = "Continue" @@ -51,28 +51,28 @@ class LandlordViewSpec extends ViewBaseSpec { val radioLabel = "#main-content > div > div > form > div:nth-child(5) > fieldset > legend > h1" val radio1 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(1) > label" val radio2 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(2) > label" - val radio3 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(3) > label" - val radio4 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(4) > label" - val radio5 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(5) > label" +// val radio3 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(3) > label" +// val radio4 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(4) > label" +// val radio5 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(5) > label" val continue = "#continue" } val address = "5 Brixham Marina, Berry Head Road, Brixham, Devon, TQ5 9BW" - private val landLordAndTennant: NGRRadioButtons = NGRRadioButtons("Landlord and tenant relationship only", LandLordAndTenant) - private val familyMember: NGRRadioButtons = NGRRadioButtons("Family member", FamilyMember) - private val companyPensionFund: NGRRadioButtons = NGRRadioButtons("Company pension fund", CompanyPensionFund) - private val businessPartnerOrSharedDirector: NGRRadioButtons = NGRRadioButtons("Company pension fund", BusinessPartnerOrSharedDirector) + private val landLordAndTennant: NGRRadioButtons = NGRRadioButtons("Yes", LandlordYes) + private val familyMember: NGRRadioButtons = NGRRadioButtons("No", LandlordNo) +// private val companyPensionFund: NGRRadioButtons = NGRRadioButtons("Company pension fund", CompanyPensionFund) +// private val businessPartnerOrSharedDirector: NGRRadioButtons = NGRRadioButtons("Company pension fund", BusinessPartnerOrSharedDirector) private def otherRelationship(form: Form[LandlordForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons( - radioContent = "landlord.radio5", - radioValue = OtherRelationship, + radioContent = "service.yes", + radioValue = LandlordYes, conditionalHtml = Some(ngrCharacterCountComponent(form, NGRCharacterCount( - id = "landlord-radio-other", - name = "landlord-radio-other", + id = "landlord-yes", + name = "landlord-yes", label = Label( classes = "govuk-label govuk-label--m", - content = Text(Messages("landlord.radio5.dropdown")) + content = Text(Messages("landlord.radio.yes")) ), errorMessage = Some(ErrorMessage( id = Some("radio-other-error"), @@ -82,7 +82,7 @@ class LandlordViewSpec extends ViewBaseSpec { ) ) - private val ngrRadio: NGRRadio = NGRRadio(NGRRadioName("what-type-of-agreement-radio"), Seq(landLordAndTennant, familyMember, companyPensionFund, businessPartnerOrSharedDirector, otherRelationship(form))) + private val ngrRadio: NGRRadio = NGRRadio(NGRRadioName("what-type-of-agreement-radio"), Seq(landLordAndTennant, familyMember)) val form = LandlordForm.form.fillAndValidate(LandlordForm(landlordName = "Bob", landLordType = "FamilyMember", None)) val radio: Radios = buildRadios(form, ngrRadio) @@ -125,17 +125,17 @@ class LandlordViewSpec extends ViewBaseSpec { elementText(Selectors.radio2) mustBe Strings.radio2 } - "show correct radio 3" in { - elementText(Selectors.radio3) mustBe Strings.radio3 - } - - "show correct radio 4" in { - elementText(Selectors.radio4) mustBe Strings.radio4 - } - - "show correct radio 5" in { - elementText(Selectors.radio5) mustBe Strings.radio5 - } +// "show correct radio 3" in { +// elementText(Selectors.radio3) mustBe Strings.radio3 +// } +// +// "show correct radio 4" in { +// elementText(Selectors.radio4) mustBe Strings.radio4 +// } +// +// "show correct radio 5" in { +// elementText(Selectors.radio5) mustBe Strings.radio5 +// } "show correct continue button" in { elementText(Selectors.continue) mustBe Strings.continue From df681af55c6b9f79a81a25d81324ec6b55a2ff5d Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:42:50 +0100 Subject: [PATCH 2/5] NGR-1091 - Removed commented out code --- .../uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala index 7ccce790..c40d202d 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala @@ -51,17 +51,12 @@ class LandlordViewSpec extends ViewBaseSpec { val radioLabel = "#main-content > div > div > form > div:nth-child(5) > fieldset > legend > h1" val radio1 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(1) > label" val radio2 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(2) > label" -// val radio3 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(3) > label" -// val radio4 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(4) > label" -// val radio5 = "#main-content > div > div > form > div:nth-child(5) > fieldset > div > div:nth-child(5) > label" val continue = "#continue" } val address = "5 Brixham Marina, Berry Head Road, Brixham, Devon, TQ5 9BW" private val landLordAndTennant: NGRRadioButtons = NGRRadioButtons("Yes", LandlordYes) private val familyMember: NGRRadioButtons = NGRRadioButtons("No", LandlordNo) -// private val companyPensionFund: NGRRadioButtons = NGRRadioButtons("Company pension fund", CompanyPensionFund) -// private val businessPartnerOrSharedDirector: NGRRadioButtons = NGRRadioButtons("Company pension fund", BusinessPartnerOrSharedDirector) private def otherRelationship(form: Form[LandlordForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons( radioContent = "service.yes", From 870e2f40cfc1baa7b23032d22b630a7607be70b8 Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:47:56 +0100 Subject: [PATCH 3/5] NGR-1091 - Removed commented out code --- .../ngrraldfrontend/views/LandlordViewSpec.scala | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala index c40d202d..760fe091 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala @@ -120,18 +120,6 @@ class LandlordViewSpec extends ViewBaseSpec { elementText(Selectors.radio2) mustBe Strings.radio2 } -// "show correct radio 3" in { -// elementText(Selectors.radio3) mustBe Strings.radio3 -// } -// -// "show correct radio 4" in { -// elementText(Selectors.radio4) mustBe Strings.radio4 -// } -// -// "show correct radio 5" in { -// elementText(Selectors.radio5) mustBe Strings.radio5 -// } - "show correct continue button" in { elementText(Selectors.continue) mustBe Strings.continue } From 1b76a275363c051ca5796c659098e8d111ae99e0 Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:29:06 +0100 Subject: [PATCH 4/5] NGR-1091 - Fixed failing test --- .../ngrraldfrontend/controllers/LandlordControllerSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala index 3ee41c67..1d3012af 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala @@ -60,7 +60,7 @@ class LandlordControllerSpec extends ControllerSpecSupport { val content = contentAsString(result) val document = Jsoup.parse(content) document.select("input[name=landlord-name-value]").attr("value") mustBe "Joe Bloggs" - document.select("input[name=landlord-radio]").attr("value") mustBe "LandLordAndTenant" + document.select("input[name=landlord-radio]").attr("value") mustBe "LandlordYes" } "Return NotFoundException when property is not found in the mongo" in { From 9206394d2cded0708af87072cfb6bc5dd081ae3c Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Mon, 29 Sep 2025 12:00:52 +0100 Subject: [PATCH 5/5] WIP --- .../controllers/LandlordController.scala | 10 +++---- .../ngrraldfrontend/models/Landlord.scala | 2 +- .../models/forms/LandlordForm.scala | 28 +++++++++---------- conf/messages | 6 ---- .../models/forms/LandlordFormSpec.scala | 13 ++++----- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala index bbd308ca..69dd68b3 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala @@ -53,8 +53,8 @@ class LandlordController @Inject()(view: LandlordView, radioValue = LandlordYes, conditionalHtml = Some(ngrCharacterCountComponent(form, NGRCharacterCount( - id = "landlord-yes", - name = "landlord-yes", + id = "landlord-relationship", + name = "landlord-relationship", maxLength = Some(250), label = Label( classes = "govuk-label govuk-label--s", @@ -62,7 +62,7 @@ class LandlordController @Inject()(view: LandlordView, ), hint = Some( Hint( - id = Some("landlord-yes-hint"), + id = Some("landlord-relationship-hint"), classes = "", attributes = Map.empty, content = Text(messages("landlord.radio.yes.hint")) @@ -86,7 +86,7 @@ class LandlordController @Inject()(view: LandlordView, (authenticate andThen getData).async { implicit request => val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(LandlordPage) match { case None => form - case Some(value) => form.fill(LandlordForm(value.landlordName,value.landLordType,value.landlordOtherDesc)) + case Some(value) => form.fill(LandlordForm(value.landlordName,value.landlordRelationship,value.landlordOtherDesc)) } Future.successful(Ok(view(selectedPropertyAddress = request.property.addressFull, form = preparedForm, ngrRadio = buildRadios(preparedForm, ngrRadio(preparedForm)), mode)) ) @@ -119,7 +119,7 @@ class LandlordController @Inject()(view: LandlordView, landlordForm => for { updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)) - .set(LandlordPage, Landlord(landlordForm.landlordName, landlordForm.landLordType, landlordForm.landlordYesSelected))) + .set(LandlordPage, Landlord(landlordForm.landlordName, landlordForm.landlordRelationship, landlordForm.landlordYesSelected))) _ <- sessionRepository.set(updatedAnswers) } yield Redirect(navigator.nextPage(LandlordPage, mode, updatedAnswers)) ) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/Landlord.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/Landlord.scala index e4f37980..49f150f3 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/Landlord.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/Landlord.scala @@ -19,7 +19,7 @@ package uk.gov.hmrc.ngrraldfrontend.models import play.api.libs.json.{Json, OFormat} final case class Landlord(landlordName: String, - landLordType: String, + landlordRelationship: Boolean, landlordOtherDesc: Option[String] = None) object Landlord { diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala index 9f6f08b2..505102b3 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala @@ -24,7 +24,7 @@ import play.api.libs.json.{Json, OFormat} import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatIsYourRentBasedOnForm.firstError import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings -final case class LandlordForm(landlordName: String, landLordType: String, landlordYesSelected: Option[String]) +final case class LandlordForm(landlordName: String, landlordRelationship: Boolean, landlordYesSelected: Option[String]) object LandlordForm extends CommonFormValidators with Mappings{ implicit val format: OFormat[LandlordForm] = Json.format[LandlordForm] @@ -32,12 +32,12 @@ object LandlordForm extends CommonFormValidators with Mappings{ private lazy val landlordNameEmptyError = "landlord.name.empty.error" private lazy val landlordNameTooLongError = "landlord.name.empty.tooLong.error" private lazy val radioUnselectedError = "landlord.radio.empty.error" - private lazy val otherRadioEmptyError = "landlord.radio.other.empty.error" - private lazy val otherRadioTooLongError = "landlord.radio.other.tooLong.error" + private lazy val landlordEmptyError = "landlord.radio.other.empty.error" + private lazy val landlordTooLongError = "landlord.radio.other.tooLong.error" private val landlord = "landlord-name-value" private val landlordRadio = "landlord-radio" - private val landlordYesSelected = "landlord-yes" + private val landlordYesSelected = "landlord-relationship" val messagesApi: MessagesApi = new DefaultMessagesApi() @@ -45,23 +45,23 @@ object LandlordForm extends CommonFormValidators with Mappings{ val messages: Messages = MessagesImpl(lang, messagesApi) - def unapply(landlordForm: LandlordForm): Option[(String, String, Option[String])] = - Some((landlordForm.landlordName, landlordForm.landLordType, landlordForm.landlordYesSelected)) + def unapply(landlordForm: LandlordForm): Option[(String, Boolean, Option[String])] = + Some((landlordForm.landlordName, landlordForm.landlordRelationship, landlordForm.landlordYesSelected)) private def isOtherTextEmpty[A]: Constraint[A] = Constraint((input: A) => - val rentBasedOnForm = input.asInstanceOf[LandlordForm] - if (rentBasedOnForm.landLordType.equals("LandlordYes") && rentBasedOnForm.landlordYesSelected.getOrElse("").isBlank) - Invalid(otherRadioEmptyError) + val landlordForm = input.asInstanceOf[LandlordForm] + if (landlordForm.landlordRelationship.equals("LandlordYes") && landlordForm.landlordYesSelected.getOrElse("").isBlank) + Invalid(landlordEmptyError) else Valid ) private def otherTextMaxLength[A]: Constraint[A] = Constraint((input: A) => - val rentBasedOnForm = input.asInstanceOf[LandlordForm] - if (rentBasedOnForm.landLordType.equals("LandlordYes") && rentBasedOnForm.landlordYesSelected.getOrElse("").length > 250) - Invalid(otherRadioTooLongError) + val landlordForm = input.asInstanceOf[LandlordForm] + if (landlordForm.landlordRelationship.equals("LandlordYes") && landlordForm.landlordYesSelected.getOrElse("").length > 250) + Invalid(landlordTooLongError) else Valid ) @@ -85,8 +85,8 @@ object LandlordForm extends CommonFormValidators with Mappings{ )(LandlordForm.apply)(LandlordForm.unapply) .verifying( firstError( - isOtherTextEmpty, - otherTextMaxLength + landlordEmptyError, + landlordTooLongError ) ) ) diff --git a/conf/messages b/conf/messages index 30a7bdc6..cf2d3c64 100644 --- a/conf/messages +++ b/conf/messages @@ -57,12 +57,6 @@ typeOfLeaseRenewal.required.error = Select what type of lease renewal it is landlord.title = Landlord landlord.p1 = What is the landlord''s full name? landlord.p2 = What is your relationship with the landlord? -landlord.radio1 = Landlord and tenant relationship only -landlord.radio2 = Family member -landlord.radio3 = Company pension fund -landlord.radio4 = Business partner or shared director -landlord.radio5 = Other relationship -landlord.radio5.dropdown = Can you tell us what your relationship with the landlord is? landlord.name.empty.error = Enter the landlord''s full name landlord.name.empty.tooLong.error = Landlord''s full name must be 50 characters or less landlord.radio.empty.error = Select what your relationship with the landlord is diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala index 0866f450..8a0906a3 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala @@ -92,7 +92,7 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { val form = LandlordForm("Jane Smith", "LandLordAndTenant", None) val result = LandlordForm.unapply(form) - result shouldBe Some(("Jane Smith", "LandLordAndTenant", None)) + result shouldBe Some(("Jane Smith", "LandlordYes", None)) } "LandlordForm.format" should "serialize to JSON correctly" in { @@ -109,28 +109,27 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { it should "deserialize from JSON correctly" in { val json = Json.obj( "landlordName" -> "Jane Smith", - "landLordType" -> "LandLordAndTenant", + "landLordType" -> "LandlordYes", "landlordYes" -> JsNull ) val result = json.validate[LandlordForm] result.isSuccess shouldBe true - result.get shouldBe LandlordForm("Jane Smith", "LandLordAndTenant", None) + result.get shouldBe LandlordForm("Jane Smith", "LandlordYes", None) } def validate(form: LandlordForm): Boolean = { - form.landLordType != "OtherRelationship" || - form.landlordYesSelected.forall(_.length <= 250) + form.landlordYesSelected.forall(_.length <= 250) } it should "pass if landLordType is OtherRelationship and landlordOther is <= 250 characters" in { - val form = LandlordForm("Jane Smith","OtherRelationship", Some("This is a valid description.")) + val form = LandlordForm("Jane Smith","LandlordYes", Some("This is a valid description.")) validate(form) shouldBe true } it should "fail if landLordType is OtherRelationship and landlordOther is > 250 characters" in { val longText = "x" * 251 - val form = LandlordForm("Jane Smith", "OtherRelationship", Some(longText)) + val form = LandlordForm("Jane Smith", "LandlordYes", Some(longText)) validate(form) shouldBe false }