CLDC-1945 numeric questions decimal letter entry (#1442)
* rename variables in test file
* write tests for new validations
* validate that answers to numeric questions are given to the correct level of accuracy and in normal format with only digits
* add error messages for new validations
* add or alter step on numeric questions in sales, amend one test given step changes
* copy change
* remove validation that is specific to number format and fold that functionality into accuracy validation, rejig tests accordingly
* fix various tests
* remove reference to currency in validation message that concerns step only and doesn't check whether firled is currency related
* alter copy to avoid redundant repetition in validaiton message
* save changes made in rebase
* changes after PO review
two step values had been missed in previous work
in various places there were custom validations applied that duplicated the functionality of the generic min max validation that is applied to all numeric questions, in these situations sometimes the min and max on the question class was inconsistent with the limit that triggered validations
these have been corrected and made consistent
various tests were affected by this and have been amended accordingly
* remove tests introduced by mistake in rebase
@ -6,6 +6,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question
@header="What is the mortgage amount?"
@type="numeric"
@min=1
@step=1
@width=5
@prefix="£"
@hint_text="Enter the amount of mortgage agreed with the mortgage lender. Exclude any deposits or cash payments. Numeric in pounds. Rounded to the nearest pound."
@ -6,6 +6,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question
@header="What is the full purchase price?"
@type="numeric"
@min=0
@step=0.01
@width=5
@prefix="£"
@hint_text="For all schemes, including Right to Acquire (RTA), Right to Buy (RTB), Voluntary Right to Buy (VRTB) or Preserved Right to Buy (PRTB) sales, enter the full price of the property without any discount"
@ -6,6 +6,7 @@ class Form::Sales::Questions::Value < ::Form::Question
@header="What was the full purchase price?"
@type="numeric"
@min=0
@step=1
@width=5
@prefix="£"
@hint_text="Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)"
elsifincorrect_accuracy||value.to_d!=value.to_i# if the user enters a value in exponent notation (eg '4e1') the to_i method does not convert this to the correct value
expect(sales_record.errors["savings"]).toinclude(matchI18n.t("validations.numeric.above_min",field:"Buyer’s total savings (to nearest £10) before any deposit paid",min:"£0"))
expect(sales_log.errors["savings"]).toinclude(matchI18n.t("validations.numeric.above_min",field:"Buyer’s total savings before any deposit paid",min:"£0"))
end
context"when validating percent"do
it"validates that suffixes are added in the error message"do
@ -406,7 +406,7 @@ RSpec.describe Imports::LettingsLogsImportService do
end
it"intercepts the relevant validation error"do
expect(logger).toreceive(:warn).with(/Removing offered with error: Enter a number between 0 and 20 for the amount of times the property has been re-let/)
expect(logger).toreceive(:warn).with(/Removing offered with error: Times previously offered since becoming available must be between 0 and 20/)