Skip to content

Commit

Permalink
Merge pull request #80 from hmrc/fset-1979
Browse files Browse the repository at this point in the history
FSET-1979 add drop down list of civil service departments
  • Loading branch information
Henri Cook authored Feb 13, 2018
2 parents 99d201c + eb40143 commit e3fa309
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 32 deletions.
3 changes: 2 additions & 1 deletion app/connectors/ApplicationClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ trait ApplicationClient {
data.aLevel.getOrElse(false),
data.stemLevel.getOrElse(false),
data.civilServant == "Yes",
data.department
data.department,
data.departmentOther
)
).map {
case x: HttpResponse if x.status == CREATED => ()
Expand Down
3 changes: 2 additions & 1 deletion app/connectors/ExchangeObjects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ object ExchangeObjects {
aLevel: Boolean,
stemLevel: Boolean,
civilServant: Boolean,
department: Option[String]
department: Option[String],
departmentOther: Option[String]
)

case class AddMedia(userId: UniqueIdentifier, media: String)
Expand Down
24 changes: 12 additions & 12 deletions app/controllers/FastTrackApplication.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package controllers

import _root_.forms.GeneralDetailsForm
import com.mohiva.play.silhouette.api.Silhouette
import config.{ CSRCache, CSRHttp }
import connectors.ApplicationClient.PersonalDetailsNotFound
import connectors.ExchangeObjects.PersonalDetails
Expand All @@ -28,11 +27,10 @@ import mappings.{ Address, DayMonthYear }
import models.ApplicationData.ApplicationStatus._
import models.CachedDataWithApp
import org.joda.time.LocalDate
import play.api.Play
import security.Roles.PersonalDetailsRole
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
import security.{ SecurityEnvironment, SilhouetteComponent }
import security.SilhouetteComponent

import scala.concurrent.Future
import uk.gov.hmrc.http.HeaderCarrier
Expand All @@ -54,15 +52,16 @@ trait FastTrackApplication extends BaseController with ApplicationClient with Us
user.user.lastName,
user.user.firstName,
DayMonthYear("", "", ""),
None,
outsideUk = None,
Address("", None, None, None),
None,
None,
None,
None,
None,
"No",
None
postCode = None,
country = None,
phone = None,
aLevel = None,
stemLevel = None,
civilServant = "No",
department = None,
departmentOther = None
))
def presentPersonalDetails(availableSchemes: List[SchemeInfo]) = {
getPersonalDetails(user.user.userID, user.application.applicationId).map { gd =>
Expand All @@ -79,7 +78,8 @@ trait FastTrackApplication extends BaseController with ApplicationClient with Us
Some(gd.aLevel),
Some(gd.stemLevel),
if (gd.civilServant) "Yes" else "No",
gd.department
gd.department,
gd.departmentOther
))
Ok(views.html.application.personalDetails(form, availableSchemes))

Expand Down
23 changes: 21 additions & 2 deletions app/forms/GeneralDetailsForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ object GeneralDetailsForm {
override def unbind(key: String, value: Option[String]): Map[String, String] = Map(key -> value.getOrElse(""))
}

val otherDepartmentDependentFormatter = new Formatter[Option[String]] {
override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], Option[String]] = {
val check1 = data.get("civilServant")
val check2 = data.get("department")
val value = data.get(key).filterNot(_.trim.isEmpty)

(check1, check2, value) match {
case (Some("Yes"), Some("Other"), Some(v)) if v.trim.length > deptMaxLength => Left(List(FormError(key, s"error.$key.maxLength")))
case (Some("Yes"), Some("Other"), Some(v)) => Right(value)
case (Some("Yes"), Some("Other"), None) => Left(List(FormError(key, s"error.$key.required")))
case _ => Right(None)
}
}

override def unbind(key: String, value: Option[String]): Map[String, String] = Map(key -> value.getOrElse(""))
}

def form(implicit now: LocalDate) = {
val maxDob = Some(ageReference.minusYears(minAge))

Expand All @@ -79,7 +96,8 @@ object GeneralDetailsForm {
"alevel-d" -> optional(boolean).verifying("aleveld.required", _.isDefined),
"alevel" -> optional(boolean).verifying("alevel.required", _.isDefined),
"civilServant" -> nonEmptyTrimmedText("error.civilServant.required", 3),
"department" -> of(civilServantDependentFormatter)
"department" -> of(civilServantDependentFormatter),
"departmentOther" -> of(otherDepartmentDependentFormatter)
)(Data.apply)(Data.unapply)
)
}
Expand Down Expand Up @@ -132,6 +150,7 @@ object GeneralDetailsForm {
aLevel: Option[Boolean],
stemLevel: Option[Boolean],
civilServant: String,
department: Option[String]
department: Option[String],
departmentOther: Option[String]
)
}
49 changes: 49 additions & 0 deletions app/models/CivilServiceDepartments.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2018 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

object CivilServiceDepartments {
val list = List(
("Business, Energy and Industrial Strategy", false),
("Cabinet Office", false),
("Competition and Markets Authority", false),
("Crown Commercial Service", false),
("Crown Prosecution Service", false),
("Department for Communities and Local Government", false),
("Department for Culture, Media and Sport", false),
("Department for Education", false),
("Department for Environment, Food and Rural Affairs", false),
("Department for Exiting the European Union", false),
("Department for International Development", false),
("Department for International Trade", false),
("Department for Transport", false),
("Department for Work and Pensions", false),
("Department of Health", false),
("Education and Skills Funding Agency", false),
("Foreign and Commonwealth Office", false),
("Insolvency Service", false),
("Health and Safety Executive", false),
("Her Majesty's Prison and Probation Service", false),
("Her Majesty's Revenue and Customs", false),
("Her Majesty's Treasury", false),
("Home Office", false),
("Ministry of Defence", false),
("Ministry of Justice", false),
("Valuation Office Agency", false),
("Other", true)
)
}
20 changes: 12 additions & 8 deletions app/views/application/personalDetails.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@(form: Form[_root_.forms.GeneralDetailsForm.Data], availableSchemes: List[SchemeInfo])(implicit request: Request[_], messages: Messages, flash: Flash, user: Option[CachedData], feedbackUrl: String)

@import helpers.CSRFieldConstructor._
@import views.html.widgets.{ pageProgress, checkbox, date, radioBox, radioBoxHorizontal }
@import views.html.widgets.{ pageProgress, date, radioBox, radioBoxHorizontal, select_guard }

@isOutsideUkChecked = @{
form("outsideUk").value match {
Expand Down Expand Up @@ -212,13 +212,17 @@ <h2 class="heading-large">Civil servants</h2>
@radioBoxHorizontal(form("civilServant"), options = List(("yes", "Yes", true), ("no", "No", false)),
optionTrigger = "civilservant-panel")
<div id="civilservant-panel" class="toggle-content" aria-hidden="true">
<div class="form-group">
<label for="isCivilServantInput" class="form-label">Which department do you work in?</label>
@helper.inputText(form("department"),
'_label -> "",
'class -> "form-control",
'_showConstraints -> false
)
<div data-optional>
@select_guard(form("department"), models.CivilServiceDepartments.list,
"departmentDetail", "-- Select one --") {
Which department do you work in?
}
</div>
<div class="form-group toggle-content" id="departmentDetail" data-requiredifshown data-optional>
@helper.inputText(form("departmentOther"),
'_label -> "Provide more information",
'class -> "form-control",
'_showConstraints -> false)
</div>
</div>
</fieldset>
Expand Down
2 changes: 2 additions & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ error.phoneNumber.format = You''ve entered an invalid phone number
error.civilServant.required = Tell us if you are a civil servant
error.department.required = Tell us which department you work in
error.department.maxLength = Maximum length is 256
error.departmentOther.required = Tell us the name of the other department
error.departmentOther.maxLength = Maximum length is 256

#assistance
error.hasDisability.required=Tell us if you consider yourself to have a disability
Expand Down
4 changes: 2 additions & 2 deletions test/connectors/exchange/PersonalDetailsExamples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import mappings.AddressExamples
import org.joda.time.LocalDate

object PersonalDetailsExamples {
val FullDetails = PersonalDetails("firstName", "lastName", "preferredName", "email", LocalDate.now(), false,
val FullDetails = PersonalDetails("firstName", "lastName", "preferredName", "email", LocalDate.now(), outsideUk = false,
AddressExamples.FullAddress, Some("ABC123"), None, Some("1234567"), aLevel = true, stemLevel = true, civilServant = false,
department = None)
department = None, departmentOther = None)
}
29 changes: 23 additions & 6 deletions test/forms/GeneralDetailsFormSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ class GeneralDetailsFormSpec extends BaseSpec {
+ ("civilServant" -> "Yes")
+ ("department" -> " " * (deptMaxLength + 1)))
}

"be invalid if you specify you are a civil servant, select department Other and specify the other department name " +
"which exceeds the max" in new Fixture {
assertFormError("error.departmentOther.maxLength", validFormValues - "civilServant"
+ ("civilServant" -> "Yes")
+ ("department" -> "Other")
+ ("departmentOther" -> "A" * (deptMaxLength + 1))
)
}

"be invalid if you specify you are a civil servant, select department Other and not specify the other department name " in new Fixture {
assertFormError("error.departmentOther.required", validFormValues - "civilServant"
+ ("civilServant" -> "Yes")
+ ("department" -> "Other")
)
}
}

trait Fixture {
Expand All @@ -160,15 +176,16 @@ class GeneralDetailsFormSpec extends BaseSpec {
"Bloggs",
"Joe",
DayMonthYear("21", "1", "1988"),
None,
outsideUk = None,
Address("line1", Some("line2"), Some("line3"), Some("line4")),
Some("E14 9EL"),
None,
country = None,
Some("07912333333"),
Some(false),
Some(false),
"No",
None
aLevel = Some(false),
stemLevel = Some(false),
civilServant = "No",
department = None,
departmentOther = None
)

val validFormValues = Map(
Expand Down

0 comments on commit e3fa309

Please sign in to comment.