4 changed files with 89 additions and 9 deletions
@ -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 |
||||
|
@ -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…
Reference in new issue