Browse Source

check if title text exists in display_title_text (#633)

* check if title text exists in display_title_text

* lint

* Remove all strings from title text in interruption screen
pull/637/head v0.1.16
kosiakkatrina 3 years ago committed by GitHub
parent
commit
de2d86a8ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/helpers/interruption_screen_helper.rb
  2. 32
      config/forms/2021_2022.json
  3. 32
      config/forms/2022_2023.json
  4. 6
      config/locales/en.yml
  5. 2
      spec/fixtures/forms/2021_2022.json
  6. 14
      spec/helpers/interruption_screen_helper_spec.rb

12
app/helpers/interruption_screen_helper.rb

@ -22,9 +22,11 @@ module InterruptionScreenHelper
end end
def display_title_text(title_text, case_log) def display_title_text(title_text, case_log)
if title_text["arguments"] return "" if title_text.nil?
translation_params = {} translation_params = {}
title_text["arguments"].each do |argument| arguments = title_text["arguments"] || {}
arguments.each do |argument|
value = if argument["label"] value = if argument["label"]
case_log.form.get_question(argument["key"], case_log).answer_label(case_log).downcase case_log.form.get_question(argument["key"], case_log).answer_label(case_log).downcase
else else
@ -32,10 +34,6 @@ module InterruptionScreenHelper
end end
translation_params[argument["i18n_template"].to_sym] = value translation_params[argument["i18n_template"].to_sym] = value
end end
translation = I18n.t(title_text["translation"], **translation_params) I18n.t(title_text["translation"], **translation_params).to_s
else
translation = I18n.t(title_text)
end
translation.to_s
end end
end end

32
config/forms/2021_2022.json

@ -6884,7 +6884,7 @@
}, },
"net_income_value_check": { "net_income_value_check": {
"depends_on": [{ "net_income_soft_validation_triggered?": true }], "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": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"arguments": [ "arguments": [
@ -7779,6 +7779,16 @@
}, },
"min_rent_value_check": { "min_rent_value_check": {
"depends_on": [{ "rent_in_soft_min_range?": true }], "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": { "informative_text": {
"translation": "soft_validations.rent.min.hint_text", "translation": "soft_validations.rent.min.hint_text",
"arguments": [ "arguments": [
@ -7791,11 +7801,6 @@
"key": "soft_min_for_period", "key": "soft_min_for_period",
"label": false, "label": false,
"i18n_template": "soft_min_for_period" "i18n_template": "soft_min_for_period"
},
{
"key": "brent",
"label": true,
"i18n_template": "brent"
} }
] ]
}, },
@ -7818,6 +7823,16 @@
}, },
"max_rent_value_check": { "max_rent_value_check": {
"depends_on": [{ "rent_in_soft_max_range?": true }], "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": { "informative_text": {
"translation": "soft_validations.rent.max.hint_text", "translation": "soft_validations.rent.max.hint_text",
"arguments": [ "arguments": [
@ -7830,11 +7845,6 @@
"key": "soft_max_for_period", "key": "soft_max_for_period",
"label": false, "label": false,
"i18n_template": "soft_max_for_period" "i18n_template": "soft_max_for_period"
},
{
"key": "brent",
"label": true,
"i18n_template": "brent"
} }
] ]
}, },

32
config/forms/2022_2023.json

@ -6928,7 +6928,7 @@
}, },
"net_income_value_check": { "net_income_value_check": {
"depends_on": [{ "net_income_soft_validation_triggered?": true }], "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": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"arguments": [ "arguments": [
@ -7820,6 +7820,16 @@
}, },
"min_rent_value_check": { "min_rent_value_check": {
"depends_on": [{ "rent_in_soft_min_range?": true }], "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": { "informative_text": {
"translation": "soft_validations.rent.min.hint_text", "translation": "soft_validations.rent.min.hint_text",
"arguments": [ "arguments": [
@ -7832,11 +7842,6 @@
"key": "soft_min_for_period", "key": "soft_min_for_period",
"label": false, "label": false,
"i18n_template": "soft_min_for_period" "i18n_template": "soft_min_for_period"
},
{
"key": "brent",
"label": true,
"i18n_template": "brent"
} }
] ]
}, },
@ -7859,6 +7864,16 @@
}, },
"max_rent_value_check": { "max_rent_value_check": {
"depends_on": [{ "rent_in_soft_max_range?": true }], "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": { "informative_text": {
"translation": "soft_validations.rent.max.hint_text", "translation": "soft_validations.rent.max.hint_text",
"arguments": [ "arguments": [
@ -7871,11 +7886,6 @@
"key": "soft_max_for_period", "key": "soft_max_for_period",
"label": false, "label": false,
"i18n_template": "soft_max_for_period" "i18n_template": "soft_max_for_period"
},
{
"key": "brent",
"label": true,
"i18n_template": "brent"
} }
] ]
}, },

6
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?" message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?"
rent: rent:
min: min:
hint_text: '<h1 class="govuk-heading-l app-panel--interruption">You told us the rent is %{brent}</h1><p>The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.</p>' 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: max:
hint_text: '<h1 class="govuk-heading-l app-panel--interruption">You told us the rent is %{brent}</h1><p>The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.</p>' 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: retirement:
min: min:
title: "You told us this person is under %{age} and retired" title: "You told us this person is under %{age} and retired"

2
spec/fixtures/forms/2021_2022.json vendored

@ -600,7 +600,7 @@
}, },
"net_income_value_check": { "net_income_value_check": {
"depends_on": [{ "net_income_soft_validation_triggered?": true }], "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": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"arguments": [{ "arguments": [{

14
spec/helpers/interruption_screen_helper_spec.rb

@ -100,7 +100,7 @@ RSpec.describe InterruptionScreenHelper do
describe "display_title_text" do describe "display_title_text" do
context "when title text has no arguments" do context "when title text has no arguments" do
it "returns the correct title text" 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)) expect(display_title_text(title_text, case_log))
.to eq(I18n.t("test.title_text.no_argument")) .to eq(I18n.t("test.title_text.no_argument"))
end 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)) .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
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
end end

Loading…
Cancel
Save