diff --git a/app/controllers/aboutYourLeaseOrTenure/LegalOrPlanningRestrictionsController.scala b/app/controllers/aboutYourLeaseOrTenure/LegalOrPlanningRestrictionsController.scala index 3c96a7209..2470c886a 100644 --- a/app/controllers/aboutYourLeaseOrTenure/LegalOrPlanningRestrictionsController.scala +++ b/app/controllers/aboutYourLeaseOrTenure/LegalOrPlanningRestrictionsController.scala @@ -95,6 +95,13 @@ class LegalOrPlanningRestrictionsController @Inject() ( case Some(AnswerYes) => aboutYourLeaseOrTenure.routes.CapitalSumDescriptionController.show().url case _ => aboutYourLeaseOrTenure.routes.PayACapitalSumController.show().url } + case FOR6048 => + request.sessionData.aboutLeaseOrAgreementPartTwo + .flatMap(_.payACapitalSumDetails) + .map(_.capitalSumOrPremium) match { + case Some(AnswerYes) => aboutYourLeaseOrTenure.routes.PayACapitalSumAmountDetailsController.show().url + case _ => aboutYourLeaseOrTenure.routes.PayACapitalSumController.show().url + } case _ => aboutYourLeaseOrTenure.routes.PaymentWhenLeaseIsGrantedController.show().url } diff --git a/app/controllers/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsController.scala b/app/controllers/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsController.scala new file mode 100644 index 000000000..b6342b34e --- /dev/null +++ b/app/controllers/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsController.scala @@ -0,0 +1,113 @@ +/* + * Copyright 2024 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. + */ + +/* + * 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. + */ + +package controllers.aboutYourLeaseOrTenure + +import actions.{SessionRequest, WithSessionRefiner} +import controllers.FORDataCaptureController +import form.aboutYourLeaseOrTenure.PayACapitalSumAmountDetailsForm.payACapitalSumAmountDetailsForm +import form.aboutYourLeaseOrTenure.PayACapitalSumDetailsForm.payACapitalSumDetailsForm +import models.Session +import models.submissions.aboutYourLeaseOrTenure.AboutLeaseOrAgreementPartTwo.updateAboutLeaseOrAgreementPartTwo +import models.submissions.aboutYourLeaseOrTenure.{PayACapitalSumAmountDetails, PayACapitalSumInformationDetails} +import navigation.AboutYourLeaseOrTenureNavigator +import navigation.identifiers.{PayCapitalSumAmountDetailsId, PayCapitalSumDetailsId} +import play.api.Logging +import play.api.i18n.I18nSupport +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Request} +import repositories.SessionRepo +import views.html.aboutYourLeaseOrTenure.{payACapitalSumAmountDetails, payACapitalSumDetails} + +import javax.inject.{Inject, Named, Singleton} +import scala.concurrent.Future + +@Singleton +class PayACapitalSumAmountDetailsController @Inject() ( + mcc: MessagesControllerComponents, + navigator: AboutYourLeaseOrTenureNavigator, + payACapitalSumAmountDetailsView: payACapitalSumAmountDetails, + withSessionRefiner: WithSessionRefiner, + @Named("session") val session: SessionRepo +) extends FORDataCaptureController(mcc) + with I18nSupport + with Logging { + + def show: Action[AnyContent] = (Action andThen withSessionRefiner).async { implicit request => + Future.successful( + Ok( + payACapitalSumAmountDetailsView( + request.sessionData.aboutLeaseOrAgreementPartTwo.flatMap(_.payACapitalSumAmountDetails) match { + case Some(data) => payACapitalSumAmountDetailsForm.fill(data) + case _ => payACapitalSumAmountDetailsForm + }, + getBackLink(request.sessionData), + request.sessionData.toSummary + ) + ) + ) + } + + def submit = (Action andThen withSessionRefiner).async { implicit request => + continueOrSaveAsDraft[PayACapitalSumAmountDetails]( + payACapitalSumAmountDetailsForm, + formWithErrors => + BadRequest( + payACapitalSumAmountDetailsView( + formWithErrors, + getBackLink(request.sessionData), + request.sessionData.toSummary + ) + ), + data => { + val updatedData = updateAboutLeaseOrAgreementPartTwo(_.copy(payACapitalSumAmountDetails = Some(data))) + session.saveOrUpdate(updatedData) + Redirect(navigator.nextPage(PayCapitalSumAmountDetailsId, updatedData).apply(updatedData)) + } + ) + } + + private def getBackLink(answers: Session)(implicit request: Request[AnyContent]): String = + navigator.from match { + case "TL" => controllers.routes.TaskListController.show().url + "#pay-a-capital-sum-details" + case _ => + answers.aboutLeaseOrAgreementPartTwo.flatMap( + _.payACapitalSumDetails.map(_.capitalSumOrPremium.name) + ) match { + case Some("yes") => + controllers.aboutYourLeaseOrTenure.routes.PayACapitalSumController.show().url + case Some("no") => controllers.aboutYourLeaseOrTenure.routes.TenantsAdditionsDisregardedController.show().url + case _ => + logger.warn(s"Back link for pay capital sum page reached with unknown tenants additions disregarded value") + controllers.routes.TaskListController.show().url + } + } +} diff --git a/app/form/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsForm.scala b/app/form/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsForm.scala new file mode 100644 index 000000000..cfcf9b318 --- /dev/null +++ b/app/form/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsForm.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2024 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. + */ + +package form.aboutYourLeaseOrTenure + +import form.DateMappings.requiredDateMapping +import form.MappingSupport.currencyMapping +import models.submissions.aboutYourLeaseOrTenure.{PayACapitalSumAmountDetails, PayACapitalSumInformationDetails} +import play.api.data.Form +import play.api.data.Forms.{mapping, optional} +import play.api.i18n.Messages + +object PayACapitalSumAmountDetailsForm { + def payACapitalSumAmountDetailsForm(implicit messages: Messages): Form[PayACapitalSumAmountDetails] = + Form( + mapping( + "capitalSumPaidDetails" -> currencyMapping(".capitalSumPaidDetails") + )(PayACapitalSumAmountDetails.apply)(o => Some(o.capitalSumPaidAmountDetails)) + ) +} diff --git a/app/models/submissions/aboutYourLeaseOrTenure/AboutLeaseOrAgreementPartTwo.scala b/app/models/submissions/aboutYourLeaseOrTenure/AboutLeaseOrAgreementPartTwo.scala index 1f70d18f6..e50658d82 100644 --- a/app/models/submissions/aboutYourLeaseOrTenure/AboutLeaseOrAgreementPartTwo.scala +++ b/app/models/submissions/aboutYourLeaseOrTenure/AboutLeaseOrAgreementPartTwo.scala @@ -37,6 +37,7 @@ case class AboutLeaseOrAgreementPartTwo( tenantsAdditionsDisregardedDetails: Option[TenantsAdditionsDisregardedDetails] = None, payACapitalSumDetails: Option[PayACapitalSumDetails] = None, payACapitalSumInformationDetails: Option[PayACapitalSumInformationDetails] = None, // Added Feb 2024 - 6030 Journey + payACapitalSumAmountDetails: Option[PayACapitalSumAmountDetails] = None, // Added Nov 2024 - 6048 Journey capitalSumDescription: Option[CapitalSumDescription] = None, // 6020 paymentWhenLeaseIsGrantedDetails: Option[PaymentWhenLeaseIsGrantedDetails] = None, tenancyLeaseAgreementExpire: Option[TenancyLeaseAgreementExpire] = None, diff --git a/app/models/submissions/aboutYourLeaseOrTenure/PayACapitalSumAmountDetails.scala b/app/models/submissions/aboutYourLeaseOrTenure/PayACapitalSumAmountDetails.scala new file mode 100644 index 000000000..e922c1d3b --- /dev/null +++ b/app/models/submissions/aboutYourLeaseOrTenure/PayACapitalSumAmountDetails.scala @@ -0,0 +1,29 @@ +/* + * 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. + */ + +package models.submissions.aboutYourLeaseOrTenure + +import play.api.libs.json.{Json, OFormat} + +import java.time.LocalDate + +case class PayACapitalSumAmountDetails( + capitalSumPaidAmountDetails: BigDecimal +) + +object PayACapitalSumAmountDetails { + implicit val format: OFormat[PayACapitalSumAmountDetails] = Json.format +} diff --git a/app/navigation/AboutYourLeaseOrTenureNavigator.scala b/app/navigation/AboutYourLeaseOrTenureNavigator.scala index 1532ed074..c3e002da3 100644 --- a/app/navigation/AboutYourLeaseOrTenureNavigator.scala +++ b/app/navigation/AboutYourLeaseOrTenureNavigator.scala @@ -332,13 +332,31 @@ class AboutYourLeaseOrTenureNavigator @Inject() (audit: Audit) extends Navigator case FOR6030 => controllers.aboutYourLeaseOrTenure.routes.PayACapitalSumDetailsController.show() case FOR6045 | FOR6046 => controllers.aboutYourLeaseOrTenure.routes.CapitalSumDescriptionController.show() + case FOR6048 => controllers.aboutYourLeaseOrTenure.routes.PayACapitalSumAmountDetailsController.show() case _ => controllers.aboutYourLeaseOrTenure.routes.PaymentWhenLeaseIsGrantedController.show() } case _ => answers.forType match { - case FOR6020 | FOR6045 | FOR6046 => + case FOR6020 | FOR6045 | FOR6046 | FOR6048 => + controllers.aboutYourLeaseOrTenure.routes.LegalOrPlanningRestrictionsController.show() + case _ => controllers.aboutYourLeaseOrTenure.routes.PaymentWhenLeaseIsGrantedController.show() + } + } + + private def payCapitalSumDetailsRouting: Session => Call = answers => + answers.aboutLeaseOrAgreementPartTwo.flatMap( + _.payACapitalSumDetails.map(_.capitalSumOrPremium.name) + ) match { + case Some("yes") => + answers.forType match { + case FOR6048 => controllers.aboutYourLeaseOrTenure.routes.LegalOrPlanningRestrictionsController.show() + case _ => aboutYourLeaseOrTenure.routes.PaymentWhenLeaseIsGrantedController.show() + } + case _ => + answers.forType match { + case FOR6048 => controllers.aboutYourLeaseOrTenure.routes.LegalOrPlanningRestrictionsController.show() - case _ => controllers.aboutYourLeaseOrTenure.routes.PaymentWhenLeaseIsGrantedController.show() + case _ => controllers.aboutYourLeaseOrTenure.routes.PaymentWhenLeaseIsGrantedController.show() } } @@ -577,7 +595,8 @@ class AboutYourLeaseOrTenureNavigator @Inject() (audit: Audit) extends Navigator IsGivenRentFreePeriodId -> isGivenRentFreePeriodIdRouting, RentFreePeriodDetailsId -> (_ => aboutYourLeaseOrTenure.routes.PayACapitalSumController.show()), PayCapitalSumId -> payCapitalSumRouting, - PayCapitalSumDetailsId -> (_ => aboutYourLeaseOrTenure.routes.PaymentWhenLeaseIsGrantedController.show()), + PayCapitalSumAmountDetailsId -> payCapitalSumDetailsRouting, + PayCapitalSumDetailsId -> payCapitalSumDetailsRouting, PayWhenLeaseGrantedId -> (_ => aboutYourLeaseOrTenure.routes.LegalOrPlanningRestrictionsController.show()), LegalOrPlanningRestrictionId -> legalOrPlanningRestrictionRouting, LegalOrPlanningRestrictionDetailsId -> (_ => diff --git a/app/navigation/identifiers/AboutYourLeaseOrTenureIdenifiers.scala b/app/navigation/identifiers/AboutYourLeaseOrTenureIdenifiers.scala index a31163fc1..27b6c9c38 100644 --- a/app/navigation/identifiers/AboutYourLeaseOrTenureIdenifiers.scala +++ b/app/navigation/identifiers/AboutYourLeaseOrTenureIdenifiers.scala @@ -146,6 +146,9 @@ case object TenantsAdditionsDisregardedDetailsId extends Identifier { case object PayCapitalSumId extends Identifier { override def toString: String = "payCapitalSumPage" } case object PayCapitalSumDetailsId extends Identifier { override def toString: String = "payCapitalSumDetailsPage" } +case object PayCapitalSumAmountDetailsId extends Identifier { + override def toString: String = "payCapitalSumAmountDetailsPage" +} case object PayWhenLeaseGrantedId extends Identifier { override def toString: String = "payWhenLeaseGrantedPage" } diff --git a/app/views/aboutYourLeaseOrTenure/payACapitalSumAmountDetails.scala.html b/app/views/aboutYourLeaseOrTenure/payACapitalSumAmountDetails.scala.html new file mode 100644 index 000000000..77841c5e6 --- /dev/null +++ b/app/views/aboutYourLeaseOrTenure/payACapitalSumAmountDetails.scala.html @@ -0,0 +1,82 @@ +@* + * Copyright 2024 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. + *@ + +@import models.ForType.* +@import models.submissions.aboutYourLeaseOrTenure.PayACapitalSumInformationDetails +@import uk.gov.hmrc.govukfrontend.views.viewmodels.content.Text +@import uk.gov.hmrc.govukfrontend.views.html.components.implicits._ +@import uk.gov.hmrc.govukfrontend.views.html.components.GovukButton +@import uk.gov.hmrc.govukfrontend.views.html.components.FormWithCSRF +@import uk.gov.hmrc.hmrcfrontend.views.Aliases.CurrencyInput +@import uk.gov.hmrc.govukfrontend.views.html.components.GovukDateInput +@import uk.gov.hmrc.govukfrontend.views.Aliases.Label +@import uk.gov.hmrc.hmrcfrontend.views.html.components.HmrcCurrencyInput +@import uk.gov.hmrc.govukfrontend.views.Aliases.Hint +@import actions.SessionRequest +@import models.submissions.aboutYourLeaseOrTenure.PayACapitalSumAmountDetails + +@import models.pages.Summary + +@this(layout: Layout, + govukButton: GovukButton, + govukDateInput: GovukDateInput, + hmrcCurrencyInput : HmrcCurrencyInput, + formWithCSRF: FormWithCSRF +) + + +@(theForm: Form[PayACapitalSumAmountDetails], backLink: String, summary: Summary)(implicit request: SessionRequest[?], messages: Messages) + + +@layout( + pageHeading = messages("capitalSumPaidDetails6048.heading"), + showH1 = false, + showSection = true, + summary = Some(summary), + sectionName = messages("label.section.aboutYourLeaseOrTenure"), + backLinkUrl = backLink, + theForm = theForm +) { + + + @formWithCSRF(action = controllers.aboutYourLeaseOrTenure.routes.PayACapitalSumAmountDetailsController.submit()) { + + @hmrcCurrencyInput( + CurrencyInput( + id = "capitalSumPaidDetails", + name = "capitalSumPaidDetails", + value = theForm("capitalSumPaidDetails").value, + classes = "govuk-input--width-10", + label = Label( + content = Text(messages("capitalSumPaidDetails6048.heading")), + classes = "govuk-label--l govuk-fieldset__legend govuk-fieldset__legend--l", + isPageHeading = true + ), + autocomplete = Some("off"), + errorMessage = theForm.errors.asTextErrorMessageForField("capitalSumPaidDetails"), + hint = Some(Hint(content = Text(messages("hint.currentAnnualRent")))) + + ) + ) + + @includes.continueSaveAsDraftButtons(govukButton) + + + } + } + + + diff --git a/conf/leaseOrTenure.routes b/conf/leaseOrTenure.routes index d6add2e6a..9e6744a86 100644 --- a/conf/leaseOrTenure.routes +++ b/conf/leaseOrTenure.routes @@ -145,6 +145,9 @@ POST /pay-a-capital-sum controll GET /pay-a-capital-sum-details controllers.aboutYourLeaseOrTenure.PayACapitalSumDetailsController.show() POST /pay-a-capital-sum-details controllers.aboutYourLeaseOrTenure.PayACapitalSumDetailsController.submit() +GET /pay-a-capital-sum-amount-details controllers.aboutYourLeaseOrTenure.PayACapitalSumAmountDetailsController.show() +POST /pay-a-capital-sum-amount-details controllers.aboutYourLeaseOrTenure.PayACapitalSumAmountDetailsController.submit() + GET /receive-payment-when-lease-granted controllers.aboutYourLeaseOrTenure.PaymentWhenLeaseIsGrantedController.show() POST /receive-payment-when-lease-granted controllers.aboutYourLeaseOrTenure.PaymentWhenLeaseIsGrantedController.submit() diff --git a/conf/messages b/conf/messages index 8748593a2..4722a97db 100644 --- a/conf/messages +++ b/conf/messages @@ -1232,6 +1232,7 @@ error.payACapitalSum.missing = Select yes if you paid a capital sum or premium f # PAY A CAPITAL SUM DETAILS ################## capitalSumPaidDetails.heading = Provide details of the capital sum paid +capitalSumPaidDetails6048.heading = What was the capital sum or premium paid for the lease or agreement? capitalSumPaidDetails.p1 = You do not have to provide details if the rent has been reviewed since the payment was made. label.capitalSumPaidDetails = How much did you pay for your lease or agreement? label.capitalSumPaidDetailsDateInput = When was this sum paid? diff --git a/conf/messages.cy b/conf/messages.cy index eaeee8124..22a5454d5 100644 --- a/conf/messages.cy +++ b/conf/messages.cy @@ -1226,6 +1226,7 @@ error.payACapitalSum.missing = Dewiswch ‘do’ os gwnaethoch dalu swm cyfalaf # PAY A CAPITAL SUM DETAILS ################## capitalSumPaidDetails.heading = Provide details of the capital sum paid +capitalSumPaidDetails6048.heading = What was the capital sum or premium paid for the lease or agreement? capitalSumPaidDetails.p1 = You do not have to provide details if the rent has been reviewed since the payment was made. label.capitalSumPaidDetails = How much did you pay for your lease or agreement? label.capitalSumPaidDetailsDateInput = When was this sum paid? diff --git a/test/controllers/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsControllerSpec.scala b/test/controllers/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsControllerSpec.scala new file mode 100644 index 000000000..0c1a6ea92 --- /dev/null +++ b/test/controllers/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsControllerSpec.scala @@ -0,0 +1,73 @@ +/* + * Copyright 2024 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. + */ + +package controllers.aboutYourLeaseOrTenure + +import models.submissions.aboutYourLeaseOrTenure.AboutLeaseOrAgreementPartTwo +import org.jsoup.Jsoup +import play.api.http.Status +import play.api.test.FakeRequest +import play.api.test.Helpers._ +import utils.TestBaseSpec + +class PayACapitalSumAmountDetailsControllerSpec extends TestBaseSpec { + + def payACapitalSumAmountDetailsController( + aboutLeaseOrAgreementPartTwo: Option[AboutLeaseOrAgreementPartTwo] = Some(prefilledAboutLeaseOrAgreementPartTwo) + ) = + new PayACapitalSumAmountDetailsController( + stubMessagesControllerComponents(), + aboutYourLeaseOrTenureNavigator, + payACapitalSumAmountDetailsView, + preEnrichedActionRefiner(aboutLeaseOrAgreementPartTwo = aboutLeaseOrAgreementPartTwo), + mockSessionRepo + ) + + "payACapitalSumAmountDetailsController GET /" should { + "return 200 and HTML with pay a capital sum amount in the session" in { + val result = payACapitalSumAmountDetailsController().show(fakeRequest) + status(result) shouldBe Status.OK + contentType(result) shouldBe Some("text/html") + charset(result) shouldBe Some("utf-8") + contentAsString(result) should include( + controllers.aboutYourLeaseOrTenure.routes.PayACapitalSumController.show().url + ) + } + + "return correct backLink when 'from=TL' query param is present" in { + val result = payACapitalSumAmountDetailsController().show()(FakeRequest(GET, "/path?from=TL")) + contentAsString(result) should include( + controllers.routes.TaskListController.show().url + "#pay-a-capital-sum-details" + ) + } + + "CurrentAnnualRentController123 SUBMIT /" should { + "throw a BAD_REQUEST if an empty form is submitted123" in { + val res = payACapitalSumAmountDetailsController().submit( + FakeRequest().withFormUrlEncodedBody(Seq.empty*) + ) + status(res) shouldBe BAD_REQUEST + } + + "Redirect when form data currentAnnualRent submitted" in { + val res = payACapitalSumAmountDetailsController().submit( + FakeRequest(POST, "/").withFormUrlEncodedBody("capitalSumPaidDetails" -> "1234") + ) + status(res) shouldBe SEE_OTHER + } + } + } +} diff --git a/test/utils/FakeObjects.scala b/test/utils/FakeObjects.scala index 3ce329539..225d85fb2 100644 --- a/test/utils/FakeObjects.scala +++ b/test/utils/FakeObjects.scala @@ -1658,6 +1658,7 @@ trait FakeObjects { legalOrPlanningRestrictionsDetails = Some(LegalOrPlanningRestrictionsDetails("Legal planning restrictions")), capitalSumDescription = Some(CapitalSumDescription("capital Sum Description")), payACapitalSumDetails = Some(PayACapitalSumDetails(AnswerYes)), + payACapitalSumAmountDetails = Some(PayACapitalSumAmountDetails(123.12)), payACapitalSumInformationDetails = Some(PayACapitalSumInformationDetails(Some(123.12), Some(prefilledDateInput))), paymentWhenLeaseIsGrantedDetails = Some(PaymentWhenLeaseIsGrantedDetails(AnswerYes)), tenancyLeaseAgreementExpire = Some(TenancyLeaseAgreementExpire(prefilledDateInput)), diff --git a/test/utils/FakeViews.scala b/test/utils/FakeViews.scala index bf91dbfe6..aeefc4a66 100644 --- a/test/utils/FakeViews.scala +++ b/test/utils/FakeViews.scala @@ -316,6 +316,7 @@ trait FakeViews { this: Injecting => lazy val propertyUseLeasebackArrangementView = inject[propertyUseLeasebackArrangement] lazy val payACapitalSumView = inject[payACapitalSum] lazy val payACapitalSumDetailsView = inject[payACapitalSumDetails] + lazy val payACapitalSumAmountDetailsView = inject[payACapitalSumAmountDetails] lazy val canRentBeReducedOnReviewView = inject[canRentBeReducedOnReview] lazy val rentPayableVaryOnQuantityOfBeersDetailsView = inject[rentPayableVaryOnQuantityOfBeersDetails] lazy val howIsCurrentRentFixedView = inject[howIsCurrentRentFixed] diff --git a/test/views/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsViewSpec.scala b/test/views/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsViewSpec.scala new file mode 100644 index 000000000..42822dc63 --- /dev/null +++ b/test/views/aboutYourLeaseOrTenure/PayACapitalSumAmountDetailsViewSpec.scala @@ -0,0 +1,71 @@ +/* + * 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. + */ + +package views.aboutYourLeaseOrTenure + +import actions.SessionRequest +import form.aboutYourLeaseOrTenure.PayACapitalSumAmountDetailsForm +import models.pages.Summary +import models.submissions.aboutYourLeaseOrTenure.{PayACapitalSumAmountDetails, PayACapitalSumInformationDetails} +import play.api.data.Form +import views.behaviours.QuestionViewBehaviours + +class PayACapitalSumAmountDetailsViewSpec extends QuestionViewBehaviours[PayACapitalSumAmountDetails] { + + val messageKeyPrefix = "capitalSumPaidDetails6048" + + val sessionRequest = SessionRequest(baseFilled6048Session, fakeRequest) + + override val form = PayACapitalSumAmountDetailsForm.payACapitalSumAmountDetailsForm(messages) + + val backLink = controllers.aboutYourLeaseOrTenure.routes.PayACapitalSumController.show().url + + def createView = () => + payACapitalSumAmountDetailsView(form, backLink, Summary("99996048001"))(sessionRequest, messages) + + def createViewUsingForm = (form: Form[PayACapitalSumAmountDetails]) => + payACapitalSumAmountDetailsView(form, backLink, Summary("99996048001"))(sessionRequest, messages) + + "capital sum or premium view" must { + + behave like normalPage(createView, messageKeyPrefix) + + "has a link marked with back.link.label leading to pay a capital sum Page" in { + val doc = asDocument(createView()) + val backlinkText = doc.select("a[class=govuk-back-link]").text() + backlinkText shouldBe messages("back.link.label") + val backlinkUrl = doc.select("a[class=govuk-back-link]").attr("href") + backlinkUrl shouldBe controllers.aboutYourLeaseOrTenure.routes.PayACapitalSumController.show().url + } + + "Section heading is visible" in { + val doc = asDocument(createViewUsingForm(form)) + val sectionText = doc.getElementsByClass("govuk-caption-m").text() + assert(sectionText == messages("label.section.aboutYourLeaseOrTenure")) + } + + "contain currency field for the value payACapitalSumDetails" in { + val doc = asDocument(createViewUsingForm(form)) + assertRenderedById(doc, "capitalSumPaidDetails") + } + + "contain continue button with the value Continue" in { + val doc = asDocument(createViewUsingForm(form)) + val loginButton = doc.getElementById("continue").text() + assert(loginButton == messages("button.label.continue")) + } + } +}