Browse Source

Add tests for helper

pull/338/head
Kat 3 years ago committed by MadeTech Dushan
parent
commit
3bd171c9c8
  1. 15
      app/helpers/interuption_screen_helper.rb
  2. 8
      config/forms/2021_2022.json
  3. 10
      config/locales/en.yml
  4. 65
      spec/helpers/interuption_screen_helper_spec.rb

15
app/helpers/interuption_screen_helper.rb

@ -1,7 +1,16 @@
module InteruptionScreenHelper
def display_informative_text(informative_text, case_log)
translation_question = informative_text["argument"].map { |x| case_log.form.get_question(x) }
translation = I18n.t(informative_text["translation"], informative_text["argument"][0].to_sym => translation_question[0].answer_label(case_log), informative_text["argument"][1].to_sym => translation_question[1].answer_label(case_log))
"<span>#{translation}</span>".html_safe
translation_questions = informative_text["argument"].map { |x| case_log.form.get_question(x) }
begin
case translation_questions.count
when 2
translation = I18n.t(informative_text["translation"], informative_text["argument"][0].to_sym => translation_questions[0].answer_label(case_log), informative_text["argument"][1].to_sym => translation_questions[1].answer_label(case_log))
when 1
translation = I18n.t(informative_text["translation"], informative_text["argument"][0].to_sym => translation_questions[0].answer_label(case_log))
end
rescue StandardError
return ""
end
translation.html_safe
end
end

8
config/forms/2021_2022.json

@ -4577,12 +4577,16 @@
},
"net_income_value_check": {
"depends_on": [{ "net_income_soft_validation_triggered?": true }],
"title_text": "Net income value outside expected range",
"title_text": "Net income is higher than expected based on the main tenant’s working situation",
"informative_text": {
"translation": "soft_validations.net_income.hint_text",
"argument": ["ecstat1", "earnings"]
},
"questions": {
"net_income_value_check": {
"check_answer_label": "Net income soft validation",
"hidden_in_check_answers": true,
"header": "Is this value correct?",
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {

10
config/locales/en.yml

@ -88,8 +88,8 @@ en:
reasonpref:
not_homeless: "Answer cannot be ‘homeless or about to lose their home’ as you already told us the tenant was not homeless immediately prior to this letting"
reasonable_preference_reason:
reason_required: "If reasonable preference is \"Yes\", a reason must be given"
reason_not_required: "If reasonable preference is \"No\", no reasons should be given"
reason_required: 'If reasonable preference is "Yes", a reason must be given'
reason_not_required: 'If reasonable preference is "No", no reasons should be given'
underoccupation_benefitcap:
dont_know_required: "must be don’t know if tenant’s main reason for leaving is don’t know"
reservist:
@ -130,7 +130,6 @@ en:
not_homeless: "Answer cannot be ‘no’ as you already told us the tenant was homeless or about to lose their home"
previous_la_known: "Enter a local authority"
tenancy:
length:
fixed_term_not_required: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term"
@ -144,7 +143,7 @@ en:
soft_validations:
net_income:
hint_text: "This is based on the tenant’s work situation: %{ecstat1}\nThe household income you have entered is %{earnings}"
hint_text: "This is based on the tenant’s work situation: %{ecstat1}<br>The household income you have entered is %{earnings}"
in_soft_min_range:
message: "Net income is lower than expected based on the main tenant’s working situation. Are you sure this is correct?"
in_soft_max_range:
@ -159,3 +158,6 @@ en:
code_has_been_sent: "Your security code has been sent."
code_required: "Security code is required"
code_incorrect: "Security code is incorrect"
test:
one_argument: "This is based on the tenant’s work situation: %{ecstat1}"

65
spec/helpers/interuption_screen_helper_spec.rb

@ -0,0 +1,65 @@
require "rails_helper"
RSpec.describe InteruptionScreenHelper do
form_handler = FormHandler.instance
let(:form) { form_handler.get_form("test_form") }
let(:subsection) { form.get_subsection("household_characteristics") }
let(:user) { FactoryBot.create(:user) }
let(:case_log) do
FactoryBot.create(
:case_log,
:in_progress,
ecstat1: 1,
earnings: 750,
incfreq: 0,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
)
end
describe "display_informative_text" do
context "when 2 out of 2 arguments are given" do
it "returns correct informative text" do
informative_text = {
"translation" => "soft_validations.net_income.hint_text",
"argument" => %w[ecstat1 earnings],
}
expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more<br>The household income you have entered is £750.00 every week")
end
end
context "when 1 out of 1 arguments is given" do
it "returns correct informative text" do
informative_text = {
"translation" => "test.one_argument",
"argument" => %w[ecstat1],
}
expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
end
end
end
context "when 2 out of 1 arguments are given" do
it "returns correct informative text" do
informative_text = {
"translation" => "test.one_argument",
"argument" => %w[ecstat1 earnings],
}
expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
end
end
context "when 1 out of 2 arguments are given" do
it "returns an empty string" do
informative_text = {
"translation" => "soft_validations.net_income.hint_text",
"argument" => %w[ecstat1],
}
expect(display_informative_text(informative_text, case_log))
.to eq("")
end
end
end
Loading…
Cancel
Save