Browse Source
* Interruption screen refactor * Add test for retirement_age_for_person Co-authored-by: Stéphane Meny <smeny@users.noreply.github.com> * Rubocop * update 22-23 form * fix failures * lint fixes * remove whitespace * remove commented code * make spec file use translations instead of content * update content * lint fixes * fix typo * fix question wording * fix failing spec * add full stop Co-authored-by: Stéphane Meny <smeny@users.noreply.github.com> Co-authored-by: Dushan Despotovic <dushan@madetech.com>pull/577/head
Ted-U
3 years ago
committed by
GitHub
18 changed files with 1676 additions and 188 deletions
@ -0,0 +1,41 @@
|
||||
module InterruptionScreenHelper |
||||
def display_informative_text(informative_text, case_log) |
||||
return "" unless informative_text["arguments"] |
||||
|
||||
translation_params = {} |
||||
informative_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 |
||||
|
||||
begin |
||||
translation = I18n.t(informative_text["translation"], **translation_params) |
||||
translation.to_s.html_safe |
||||
rescue I18n::MissingInterpolationArgument => e |
||||
Rails.logger.error(e.message) |
||||
"" |
||||
end |
||||
end |
||||
|
||||
def display_title_text(title_text, case_log) |
||||
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) |
||||
end |
||||
translation.to_s |
||||
end |
||||
end |
@ -1,13 +0,0 @@
|
||||
module InteruptionScreenHelper |
||||
def display_informative_text(informative_text, case_log) |
||||
arguments = informative_text["argument"].map { |x, type| type == "question" ? case_log.form.get_question(x, case_log).answer_label(case_log) : case_log.public_send(x) } |
||||
keys = informative_text["argument"].keys |
||||
|
||||
begin |
||||
translation = I18n.t(informative_text["translation"], keys[0].present? ? keys[0].to_sym : "" => arguments[0], keys[1].present? ? keys[1].to_sym : "" => arguments[1], keys[2].present? ? keys[2].to_sym : "" => arguments[2]) |
||||
rescue StandardError |
||||
return "" |
||||
end |
||||
translation.to_s.html_safe |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class AddRetirementValueCheck < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :case_logs, :retirement_value_check, :integer |
||||
end |
||||
end |
@ -0,0 +1,126 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe InterruptionScreenHelper 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: 1, |
||||
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", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "ecstat1", |
||||
"label" => true, |
||||
"i18n_template" => "ecstat1", |
||||
}, |
||||
{ |
||||
"key" => "earnings", |
||||
"label" => true, |
||||
"i18n_template" => "earnings", |
||||
}, |
||||
], |
||||
} |
||||
expect(display_informative_text(informative_text, case_log)) |
||||
.to eq(I18n.t("soft_validations.net_income.hint_text", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase, earnings: case_log.form.get_question("earnings", case_log).answer_label(case_log))) |
||||
end |
||||
end |
||||
|
||||
context "when 1 out of 1 arguments is given" do |
||||
it "returns correct informative text" do |
||||
informative_text = { |
||||
"translation" => "test.one_argument", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "ecstat1", |
||||
"label" => true, |
||||
"i18n_template" => "ecstat1", |
||||
}, |
||||
], |
||||
} |
||||
expect(display_informative_text(informative_text, case_log)) |
||||
.to eq(I18n.t("test.one_argument", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase)) |
||||
end |
||||
end |
||||
|
||||
context "when 2 out of 1 arguments are given" do |
||||
it "returns correct informative text" do |
||||
informative_text = { |
||||
"translation" => "test.one_argument", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "ecstat1", |
||||
"label" => true, |
||||
"i18n_template" => "ecstat1", |
||||
}, |
||||
{ |
||||
"key" => "earnings", |
||||
"label" => true, |
||||
"i18n_template" => "earnings", |
||||
}, |
||||
], |
||||
} |
||||
expect(display_informative_text(informative_text, case_log)) |
||||
.to eq(I18n.t("test.one_argument", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase)) |
||||
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", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "ecstat1", |
||||
"label" => true, |
||||
"i18n_template" => "ecstat1", |
||||
}, |
||||
], |
||||
} |
||||
expect(display_informative_text(informative_text, case_log)) |
||||
.to eq("") |
||||
end |
||||
end |
||||
end |
||||
|
||||
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" |
||||
expect(display_title_text(title_text, case_log)) |
||||
.to eq(I18n.t("test.title_text.no_argument")) |
||||
end |
||||
end |
||||
|
||||
context "when title text has arguments" do |
||||
it "returns the correct title text" do |
||||
title_text = { |
||||
"translation" => "test.title_text.one_argument", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "ecstat1", |
||||
"label" => true, |
||||
"i18n_template" => "ecstat1", |
||||
}, |
||||
], |
||||
} |
||||
expect(display_title_text(title_text, case_log)) |
||||
.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 |
@ -1,65 +0,0 @@
|
||||
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: 1, |
||||
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" => { "ecstat1": "question", "earnings": "question" }, |
||||
} |
||||
expect(display_informative_text(informative_text, case_log)) |
||||
.to eq("<p>You told us the lead tenant’s working situation is: <strong>Full-time – 30 hours or more</strong>.</p><p>The household income you have entered is <strong>£750.00 every week</strong>.</p>") |
||||
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" => { "ecstat1": "question" }, |
||||
} |
||||
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" => { "ecstat1": "question", "earnings": "question" }, |
||||
} |
||||
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" => { "ecstat1": "question" }, |
||||
} |
||||
expect(display_informative_text(informative_text, case_log)) |
||||
.to eq("") |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue