Skip to content

Commit

Permalink
DDCE-4993 Fix currency input padding issue (#524)
Browse files Browse the repository at this point in the history
WIP
WIP

WIP
  • Loading branch information
gastonracui authored Apr 30, 2024
1 parent 2a89904 commit 0a49eef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ object PurchaseDetailsForm extends Mappings {
mapping(
"price" -> text("purchaseDetails.price.error.required").verifying(isAValidPurchasePrice),
"currency" -> text("purchaseDetails.currency.error.required")
)(PurchaseDetailsInput.apply)(PurchaseDetailsInput.unapply)
)((price, currency) => PurchaseDetailsInput.apply(price = BigDecimal(price).toString(), currency = currency))(
PurchaseDetailsInput.unapply
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import play.api.i18n.Messages
import play.api.libs.json.{Json, OFormat}

case class PurchaseDetails(amount: String, currency: Currency) {
private val formattedAmount = BigDecimal(amount)
def formatted(implicit messages: Messages): String =
if (currency.code == "GBP") s"£$amount" else s"$amount, ${messages(currency.displayName)}"
if (currency.code == "GBP") s"£$formattedAmount" else s"$formattedAmount, ${messages(currency.displayName)}"
}

object PurchaseDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,29 @@ class DeclarationSpec extends BaseSpecWithApplication with CoreTestData {
private val vehicleRegistrationNumber = "reg"

"PurchaseDetails toString" should {
"include the price string as entered" in {
"format the price string entered" in {
val currency = Currency("EUR", "title.euro_eur", Some("EUR"), List("Europe", "European"))

PurchaseDetails("1", currency).formatted mustBe "1, Euro (EUR)"
PurchaseDetails("1.", currency).formatted mustBe "1., Euro (EUR)"
PurchaseDetails("1.", currency).formatted mustBe "1, Euro (EUR)"
PurchaseDetails("1.0", currency).formatted mustBe "1.0, Euro (EUR)"
PurchaseDetails("1.00", currency).formatted mustBe "1.00, Euro (EUR)"
PurchaseDetails("1.000", currency).formatted mustBe "1.000, Euro (EUR)"
PurchaseDetails("00001.000", currency).formatted mustBe "1.000, Euro (EUR)"
PurchaseDetails("00044001.000", currency).formatted mustBe "44001.000, Euro (EUR)"

PurchaseDetails("01", currency).formatted mustBe "01, Euro (EUR)"
PurchaseDetails("01.", currency).formatted mustBe "01., Euro (EUR)"
PurchaseDetails("01.0", currency).formatted mustBe "01.0, Euro (EUR)"
PurchaseDetails("01.00", currency).formatted mustBe "01.00, Euro (EUR)"
PurchaseDetails("01.000", currency).formatted mustBe "01.000, Euro (EUR)"
PurchaseDetails("01", currency).formatted mustBe "1, Euro (EUR)"
PurchaseDetails("01.", currency).formatted mustBe "1, Euro (EUR)"
PurchaseDetails("01.0", currency).formatted mustBe "1.0, Euro (EUR)"
PurchaseDetails("01.00", currency).formatted mustBe "1.00, Euro (EUR)"
PurchaseDetails("01.000", currency).formatted mustBe "1.000, Euro (EUR)"

PurchaseDetails("0.1", currency).formatted mustBe "0.1, Euro (EUR)"
PurchaseDetails("0.10", currency).formatted mustBe "0.10, Euro (EUR)"
PurchaseDetails("0.100", currency).formatted mustBe "0.100, Euro (EUR)"

PurchaseDetails(".01", currency).formatted mustBe ".01, Euro (EUR)"
PurchaseDetails(".001", currency).formatted mustBe ".001, Euro (EUR)"
PurchaseDetails(".01", currency).formatted mustBe "0.01, Euro (EUR)"
PurchaseDetails(".001", currency).formatted mustBe "0.001, Euro (EUR)"
}
}

Expand Down

0 comments on commit 0a49eef

Please sign in to comment.