Skip to content

Commit

Permalink
MCSC 874 - 'New' in WhichScheme not being translated in Welsh (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
TJSarno authored Nov 18, 2024
1 parent 1dd8819 commit c59cd32
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/forms/mappings/Formatters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ trait Formatters {
.bind(key, data)
.flatMap {
case s if PSTR.fromString(s).isDefined => Right(s.toUpperCase.replaceAll(" ", ""))
case PSTR.New => Right(PSTR.New)
case PSTR.New | PSTR.NewInWelsh => Right(PSTR.New)
case _ => Left(Seq(FormError(key, invalidKey, args)))
}

Expand Down
3 changes: 2 additions & 1 deletion app/models/PSTR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ case class PSTR(value: String)

object PSTR {

val New: String = "New"
val New: String = "New"
val NewInWelsh: String = "Newydd"

private val pattern: Regex = """(\d\s*){8}[A-Za-z]{2}""".r.anchored

Expand Down
6 changes: 3 additions & 3 deletions app/pages/annualallowance/taxyear/WhichSchemePage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ case class WhichSchemePage(period: Period, schemeIndex: SchemeIndex) extends Que
val selectedScheme: Option[String] = answers.get(WhichSchemePage(period, schemeIndex))

selectedScheme match {
case Some(PSTR.New) =>
case Some(PSTR.New | PSTR.NewInWelsh) =>
controllers.annualallowance.taxyear.routes.PensionSchemeDetailsController
.onPageLoad(NormalMode, period, schemeIndex)
case Some(_) =>
case Some(_) =>
controllers.annualallowance.taxyear.routes.PensionSchemeInputAmountsController
.onPageLoad(NormalMode, period, schemeIndex)
case None => controllers.routes.JourneyRecoveryController.onPageLoad(None)
case None => controllers.routes.JourneyRecoveryController.onPageLoad(None)
}
}

Expand Down
10 changes: 6 additions & 4 deletions app/services/SchemeService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ package services

import models.{PSTR, PensionSchemeDetails, Period, SchemeIndex, UserAnswers, WhichScheme}
import pages.annualallowance.taxyear.PensionSchemeDetailsPage
import play.api.i18n.Messages

object SchemeService {

def whichScheme(answers: UserAnswers): WhichScheme = {
def whichScheme(answers: UserAnswers)(implicit messages: Messages): WhichScheme = {
val schemeRefs: Seq[PSTR] = allSchemeRefs(answers)
val schemeRefsOrNew: Seq[String] = schemeRefs.map(pstr => pstr.value)
WhichScheme(schemeRefsOrNew :+ PSTR.New)

WhichScheme(schemeRefsOrNew :+ messages("site.newPSTR"))
}

def maybeAddSchemeDetailsToPeriod(
answers: UserAnswers,
schemeRef: String,
period: Period,
schemeIndex: SchemeIndex
): UserAnswers =
if (schemeRef != PSTR.New) {
)(implicit messages: Messages): UserAnswers =
if (schemeRef != messages("site.newPSTR")) {
val schemeName: Option[String] = findSchemeName(answers, schemeRef)

schemeName match {
Expand Down
1 change: 1 addition & 0 deletions conf/messages.cy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ site.startAgain = Dechrau eto
site.signIn = Mewngofnodi
site.govuk = GOV.UK
site.opensInNewTab = (yn agor tab newydd)
site.newPSTR = Newydd

date.day = Diwrnod
date.month = Mis
Expand Down
1 change: 1 addition & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ site.startAgain = Start again
site.signIn = Sign in
site.govuk = GOV.UK
site.opensInNewTab = (opens in a new tab)
site.newPSTR = New

date.day = Day
date.month = Month
Expand Down
11 changes: 7 additions & 4 deletions test/services/SchemeServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ package services
import base.SpecBase
import models.{PSTR, PensionSchemeDetails, Period, SchemeIndex}
import pages.annualallowance.taxyear.PensionSchemeDetailsPage
import play.api.i18n.Messages
import play.api.test.Helpers.stubMessages

class SchemeServiceSpec extends SpecBase {
private implicit val messages: Messages = stubMessages()

"WhichScheme" - {

"options should include an option to add a new scheme if there are no previous schemes" in {
SchemeService.whichScheme(emptyUserAnswers).values must be(Seq(PSTR.New))
SchemeService.whichScheme(emptyUserAnswers).values must be(Seq(messages("site.newPSTR")))
}

"options should include previous scheme references from a single period and new" in {
Expand All @@ -36,7 +39,7 @@ class SchemeServiceSpec extends SpecBase {
)
.get

SchemeService.whichScheme(userAnswers).values must be(Seq("pstr1", PSTR.New))
SchemeService.whichScheme(userAnswers).values must be(Seq("pstr1", messages("site.newPSTR")))
}

"options should include multiple scheme references from a single period and new" in {
Expand All @@ -52,7 +55,7 @@ class SchemeServiceSpec extends SpecBase {
)
.get

SchemeService.whichScheme(userAnswers).values must be(Seq("pstr1", "pstr2", PSTR.New))
SchemeService.whichScheme(userAnswers).values must be(Seq("pstr1", "pstr2", messages("site.newPSTR")))
}

"options should include scheme references from multiple periods and new" in {
Expand All @@ -68,7 +71,7 @@ class SchemeServiceSpec extends SpecBase {
)
.get

SchemeService.whichScheme(userAnswers).values must be(Seq("pstr1", "pstr2", PSTR.New))
SchemeService.whichScheme(userAnswers).values must be(Seq("pstr1", "pstr2", messages("site.newPSTR")))
}
}

Expand Down

0 comments on commit c59cd32

Please sign in to comment.