Skip to content

Commit

Permalink
Merge pull request #19 from hmrc/TAMC-941
Browse files Browse the repository at this point in the history
Tamc 941
  • Loading branch information
pankaj2453 committed May 31, 2016
2 parents f6ccc83 + 09508e1 commit a2ac93d
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 37 deletions.
20 changes: 14 additions & 6 deletions app/controllers/TransferController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import errors.TransferorDeceased
import details.CitizenDetailsService
import details.TamcUser
import scala.concurrent.ExecutionContext.Implicits.global
import forms.MultiYearForm.multiYearForm
import forms.MultiYearForm._
import services.TimeService
import services.CachingService
import forms.CurrentYearForm.currentYearForm
Expand Down Expand Up @@ -136,7 +136,7 @@ trait TransferController extends FrontendController with AuthorisedActions with
case (false, extraYears, recipient) if (extraYears.isEmpty) =>
throw new NoTaxYearsAvailable
case (false, extraYears, recipient) if (!extraYears.isEmpty) =>
Ok(views.html.multi_year_select(multiYearForm(), recipient.data, extraYears))
Ok(views.html.previousYears(recipient.data, extraYears))
case (currentYearAvailable, extraYears, recipient) =>
Ok(views.html.eligible_years(
currentYearForm(!extraYears.isEmpty),
Expand Down Expand Up @@ -168,10 +168,8 @@ trait TransferController extends FrontendController with AuthorisedActions with
_ =>
if (extraYears.isEmpty && currentYearAvailable && (success.applyForCurrentYear != Some(true))) {
throw new NoTaxYearsSelected
} else if (!extraYears.isEmpty && currentYearAvailable && !(success.applyForCurrentYear == Some(true) || success.applyForRetrospectiveYears == Some(true))) {
throw new NoTaxYearsSelected
} else if (!extraYears.isEmpty && success.applyForRetrospectiveYears == Some(true)) {
Ok(views.html.multi_year_select(multiYearForm(), recipient.data, extraYears))
} else if (!extraYears.isEmpty) {
Ok(views.html.previousYears(recipient.data, extraYears))
} else {
Redirect(controllers.routes.TransferController.confirmYourEmail())
}
Expand All @@ -180,6 +178,16 @@ trait TransferController extends FrontendController with AuthorisedActions with
} recover (handleError)
}

def previousYears = TamcAuthPersonalDetailsAction {
implicit auth =>
implicit request =>
implicit details =>
registrationService.getCurrentAndExtraYearEligibility flatMap {
case (currentYearAvailable, extraYears, recipient) =>
Future.successful(Ok(views.html.multi_year_select(multiYearForm(), recipient.data, extraYears)))
}recover (handleError)
}

def extraYearsAction = TamcAuthPersonalDetailsAction {
implicit auth =>
implicit request =>
Expand Down
5 changes: 2 additions & 3 deletions app/forms/CurrentYearForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import models.CurrentYearInput
object CurrentYearForm {
def currentYearForm(historicYearsAvailable: Boolean = false) = Form[CurrentYearInput](mapping(
"applyForCurrentYear" ->
optional(boolean).verifying("pages.form.field-required.applyForCurrentYear", _.isDefined),
"applyForHistoricYears" ->
optional(boolean).verifying("pages.form.field-required.applyForHistoricYears", selection => !(historicYearsAvailable && selection.isEmpty)))(CurrentYearInput.apply)(CurrentYearInput.unapply))
optional(boolean).verifying("pages.form.field-required.applyForCurrentYear", _.isDefined)
)(CurrentYearInput.apply)(CurrentYearInput.unapply))
}
2 changes: 1 addition & 1 deletion app/models/CurrentYearInput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package models

case class CurrentYearInput(applyForCurrentYear: Option[Boolean], applyForRetrospectiveYears: Option[Boolean])
case class CurrentYearInput(applyForCurrentYear: Option[Boolean])
29 changes: 7 additions & 22 deletions app/views/eligible_years.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
maybeMainDataAttributes = Some(Html("data-journey=marriage-allowance:stage:current-year-select")))) {


<h1 class="heading-xlarge">Tax years you are eligible for</h1>
<h1 class="heading-xlarge">You can apply for the current tax year</h1>

@templates.form_error_notification(form)

Expand All @@ -53,7 +53,7 @@ <h2 class="heading-medium"><span style="color:grey">This current tax year</span>
</ul>

@helpers.form(action = routes.TransferController.eligibleYearsAction, args = ('id -> "current-year-form")) {
<div @if(historicYearsAvailable) {class="form-group grey-underline-large-thick"} else {class="form-group"} id="applyForCurrentYear">
<div @if(historicYearsAvailable) {class="form-group"} id="applyForCurrentYear">
<h3 class="heading-small">Do you want to apply for this current tax year onwards?</h3>
@templates.input_radio_group(
form("applyForCurrentYear"),
Expand All @@ -65,33 +65,18 @@ <h3 class="heading-small">Do you want to apply for this current tax year onwards
'_legendClass -> "visuallyhidden",
'_groupClass -> "inline spacingBottom"
)

@if(historicYearsAvailable) {
<div class="tamc-js-hidden error-inline validation-summary" id="current-year-error">
You can still apply for earlier tax years below.
</div>
<script>
<div class="tamc-js-hidden error-inline validation-summary" id="current-year-error">
You can apply for earlier years if you continue.
</div>
<script>
var _gaq = [];
</script>
}
<br><br>
</div>

@if(historicYearsAvailable) {
<div class="form-group" id="applyForHistoricYears">
<h3 class="heading-medium">You might also be eligible for earlier tax years</h3>
<h4 class="heading-small">Do you want to apply for these additional years also?</h4>
@templates.input_radio_group(
form("applyForHistoricYears"),
Seq(("true", "Yes"), ("false", "No")),
'_labelClass -> "block-label",
'_labelAfter -> true,
'_legend -> "Earlier years",
'_legendClass -> "visuallyhidden",
'_groupClass -> "inline spacingBottom"
)
</div>
}

<p class="get-started group" id="get-started">
<button class="button" type="submit">@Html(Messages("generic.continue"))</button>
Expand Down
46 changes: 46 additions & 0 deletions app/views/previousYears.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@*
* Copyright 2015 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.
*@

@(input:RegistrationFormInput,
availableYears:List[TaxYear] = List[TaxYear]())(
implicit lang: Lang,
request: Request[_],
breadcrumb: uk.gov.hmrc.play.breadcrumb.model.Breadcrumb,
user: details.TamcUser)

@import play.twirl.api.Html
@import views.helpers.TextGenerators
@import uk.gov.hmrc.play.views.html._
@import uk.gov.hmrc.time.TaxYearResolver
@import views.helpers.TextGenerators
@import uk.gov.hmrc.play.views.html._
@import config.ApplicationConfig
@import java.text.NumberFormat

@templates.tamc_main(
title = Messages("title.pattern", Messages("title.extra-years")),
mainConfig = views.helpers.MainConfig(
maybeMainDataAttributes = Some(Html("data-journey=marriage-allowance:stage:current-year-select")))) {


<h1 class="heading-xlarge" id="heading">You can apply for earlier tax years</h1>
<p class="lede">You can apply for Marriage Allowance from when it was first introduced on 6 April 2015.</p>


<p>You told us you married or formed a civil partnership with <span id="firstNameOnly">@input.name</span> on <span id="marriageDate">@TextGenerators.ukDateTransformer(Some(input.dateOfMarriage))</span>. This means you can apply for earlier tax years.</p>
<a href="@{controllers.routes.TransferController.previousYears}" id="continue" class="button" type="submit">@Html(Messages("generic.continue"))</a>
}

1 change: 1 addition & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ POST /transfer-allowance controllers.TransferController.transferActi
POST /date-of-marriage controllers.TransferController.dateOfMarriageAction
GET /eligible-years controllers.TransferController.eligibleYears
POST /eligible-years controllers.TransferController.eligibleYearsAction
GET /previous-years controllers.TransferController.previousYears
POST /extra-years controllers.TransferController.extraYearsAction
GET /confirm-your-email controllers.TransferController.confirmYourEmail
POST /confirm-your-email controllers.TransferController.confirmYourEmailAction
Expand Down
31 changes: 29 additions & 2 deletions test/controllers/ContentTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ContentTest extends UnitSpec with TestUtility {
val controllerToTest = testComponent.controller
val request = testComponent.request.withFormUrlEncodedBody(data = ("gender" -> "M"), ("nino" -> Ninos.nino1), ("transferor-email" -> "example@example.com"))
val result = controllerToTest.transfer(request)

status(result) shouldBe OK
val document = Jsoup.parse(contentAsString(result))
val transferor = document.getElementById("transferor-name")
Expand Down Expand Up @@ -232,7 +232,7 @@ class ContentTest extends UnitSpec with TestUtility {
labelNino.getElementsByClass("error-message").first().text() shouldBe "You can't enter your own details."
document.getElementById("nino-error").text() shouldBe "Confirm your spouse or civil partner's National Insurance number."
}

"display form error message when recipient nino equals transferor nino (including mixed case and spaces)" in new WithApplication(fakeApplication) {
val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015", name = TestConstants.GENERIC_CITIZEN_NAME)
val trRecipientData = Some(CacheData(transferor = Some(trrec), recipient = None, notification = None))
Expand Down Expand Up @@ -504,6 +504,33 @@ class ContentTest extends UnitSpec with TestUtility {
}
}

"Calling Previous year page " should {
"display dynamic message " in new WithApplication(fakeApplication) {

val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015")
val rcrec = UserRecord(cid = 123456, timestamp = "2015")
val cacheRecipientFormData = Some(RecipientDetailsFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1)))
val rcdata = RegistrationFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1), dateOfMarriage = new LocalDate(2011, 4, 10))
val recrecord = RecipientRecord(record = rcrec, data = rcdata,aivailableTaxYears = List(TaxYear(2014),TaxYear(2015),TaxYear(2016)))
val trRecipientData = Some(CacheData(
transferor = Some(trrec),
recipient = Some(recrecord),
notification = Some(NotificationRecord(EmailAddress("example123@example.com"))),
recipientDetailsFormData = cacheRecipientFormData))

val testComponent = makeTestComponent("user_happy_path", transferorRecipientData = trRecipientData)
val controllerToTest = testComponent.controller
val request = testComponent.request.withFormUrlEncodedBody(data = ("applyForCurrentYear" -> "true"))
val result = controllerToTest.eligibleYearsAction(request)

status(result) shouldBe OK
val document = Jsoup.parse(contentAsString(result))
document.getElementById("firstNameOnly").text() shouldBe "foo"
document.getElementById("marriageDate").text() shouldBe "10 April 2011"

}
}

"Calling Confirm email page with error in email field" should {
"display form error message (transferor email missing from request)" in new WithApplication(fakeApplication) {
val testComponent = makeTestComponent("user_happy_path")
Expand Down
Loading

0 comments on commit a2ac93d

Please sign in to comment.