diff --git a/app/helpers/interruption_screen_helper.rb b/app/helpers/interruption_screen_helper.rb index 8c97870d4..4f18a6938 100644 --- a/app/helpers/interruption_screen_helper.rb +++ b/app/helpers/interruption_screen_helper.rb @@ -22,22 +22,18 @@ module InterruptionScreenHelper end def display_title_text(title_text, case_log) - return "" if title_text.blank? + return "" if title_text.nil? - if title_text["arguments"] - translation_params = {} - title_text["arguments"].each do |argument| - value = if argument["label"] - case_log.form.get_question(argument["key"], case_log).answer_label(case_log).downcase - else - case_log.public_send(argument["key"]) - end - translation_params[argument["i18n_template"].to_sym] = value - end - translation = I18n.t(title_text["translation"], **translation_params) - else - translation = I18n.t(title_text) + translation_params = {} + arguments = title_text["arguments"] || {} + arguments.each do |argument| + value = if argument["label"] + case_log.form.get_question(argument["key"], case_log).answer_label(case_log).downcase + else + case_log.public_send(argument["key"]) + end + translation_params[argument["i18n_template"].to_sym] = value end - translation.to_s + I18n.t(title_text["translation"], **translation_params).to_s end end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 5041fedd1..93879529e 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -6884,7 +6884,7 @@ }, "net_income_value_check": { "depends_on": [{ "net_income_soft_validation_triggered?": true }], - "title_text": "soft_validations.net_income.title_text", + "title_text": { "translation": "soft_validations.net_income.title_text" }, "informative_text": { "translation": "soft_validations.net_income.hint_text", "arguments": [ @@ -7779,6 +7779,16 @@ }, "min_rent_value_check": { "depends_on": [{ "rent_in_soft_min_range?": true }], + "title_text": { + "translation": "soft_validations.rent.min.title_text", + "arguments": [ + { + "key": "brent", + "label": true, + "i18n_template": "brent" + } + ] + }, "informative_text": { "translation": "soft_validations.rent.min.hint_text", "arguments": [ @@ -7791,11 +7801,6 @@ "key": "soft_min_for_period", "label": false, "i18n_template": "soft_min_for_period" - }, - { - "key": "brent", - "label": true, - "i18n_template": "brent" } ] }, @@ -7818,6 +7823,16 @@ }, "max_rent_value_check": { "depends_on": [{ "rent_in_soft_max_range?": true }], + "title_text": { + "translation": "soft_validations.rent.max.title_text", + "arguments": [ + { + "key": "brent", + "label": true, + "i18n_template": "brent" + } + ] + }, "informative_text": { "translation": "soft_validations.rent.max.hint_text", "arguments": [ @@ -7830,11 +7845,6 @@ "key": "soft_max_for_period", "label": false, "i18n_template": "soft_max_for_period" - }, - { - "key": "brent", - "label": true, - "i18n_template": "brent" } ] }, diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index 20ae77cc4..ce32663f0 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -6928,7 +6928,7 @@ }, "net_income_value_check": { "depends_on": [{ "net_income_soft_validation_triggered?": true }], - "title_text": "soft_validations.net_income.title_text", + "title_text": { "translation": "soft_validations.net_income.title_text" }, "informative_text": { "translation": "soft_validations.net_income.hint_text", "arguments": [ @@ -7820,6 +7820,16 @@ }, "min_rent_value_check": { "depends_on": [{ "rent_in_soft_min_range?": true }], + "title_text": { + "translation": "soft_validations.rent.min.title_text", + "arguments": [ + { + "key": "brent", + "label": true, + "i18n_template": "brent" + } + ] + }, "informative_text": { "translation": "soft_validations.rent.min.hint_text", "arguments": [ @@ -7832,11 +7842,6 @@ "key": "soft_min_for_period", "label": false, "i18n_template": "soft_min_for_period" - }, - { - "key": "brent", - "label": true, - "i18n_template": "brent" } ] }, @@ -7859,6 +7864,16 @@ }, "max_rent_value_check": { "depends_on": [{ "rent_in_soft_max_range?": true }], + "title_text": { + "translation": "soft_validations.rent.max.title_text", + "arguments": [ + { + "key": "brent", + "label": true, + "i18n_template": "brent" + } + ] + }, "informative_text": { "translation": "soft_validations.rent.max.hint_text", "arguments": [ @@ -7871,11 +7886,6 @@ "key": "soft_max_for_period", "label": false, "i18n_template": "soft_max_for_period" - }, - { - "key": "brent", - "label": true, - "i18n_template": "brent" } ] }, diff --git a/config/locales/en.yml b/config/locales/en.yml index 80382be01..3e9c8898e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -240,9 +240,11 @@ en: message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" rent: min: - hint_text: '

You told us the rent is %{brent}

The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.

' + title_text: "You told us the rent is %{brent}" + hint_text: "The minimum rent for this type of property in %{la} is £%{soft_min_for_period}." max: - hint_text: '

You told us the rent is %{brent}

The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.

' + title_text: "You told us the rent is %{brent}" + hint_text: "The maximum rent for this type of property in %{la} is £%{soft_max_for_period}." retirement: min: title: "You told us this person is under %{age} and retired" diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 2bf51746c..3b83b3499 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -600,7 +600,7 @@ }, "net_income_value_check": { "depends_on": [{ "net_income_soft_validation_triggered?": true }], - "title_text": "soft_validations.net_income.title_text", + "title_text": { "translation": "soft_validations.net_income.title_text" }, "informative_text": { "translation": "soft_validations.net_income.hint_text", "arguments": [{ diff --git a/spec/helpers/interruption_screen_helper_spec.rb b/spec/helpers/interruption_screen_helper_spec.rb index fb1882666..4d9ec7abe 100644 --- a/spec/helpers/interruption_screen_helper_spec.rb +++ b/spec/helpers/interruption_screen_helper_spec.rb @@ -100,7 +100,7 @@ RSpec.describe InterruptionScreenHelper do describe "display_title_text" do context "when title text has no arguments" do it "returns the correct title text" do - title_text = "test.title_text.no_argument" + title_text = { "translation" => "test.title_text.no_argument" } expect(display_title_text(title_text, case_log)) .to eq(I18n.t("test.title_text.no_argument")) end @@ -122,5 +122,17 @@ RSpec.describe InterruptionScreenHelper do .to eq(I18n.t("test.title_text.one_argument", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase)) end end + + context "when title text is not defined" do + it "returns an empty string" do + expect(display_title_text(nil, case_log)).to eq("") + end + end + + context "when title text is empty string" do + it "returns an empty string" do + expect(display_title_text("", case_log)).to eq("") + end + end end end