Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

157 lines
4.9 KiB

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(:lettings_log) do
FactoryBot.create(
:lettings_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",
},
],
}
ecstat_question = lettings_log.form.get_question("ecstat1", lettings_log)
ecstat_answer = Answer.new(log: lettings_log, question: ecstat_question)
earnings_question = lettings_log.form.get_question("earnings", lettings_log)
earnings_answer = Answer.new(log: lettings_log, question: earnings_question)
expect(display_informative_text(informative_text, lettings_log))
.to eq(I18n.t("soft_validations.net_income.hint_text", ecstat1: ecstat_answer.answer_label.downcase, earnings: earnings_answer.answer_label))
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",
},
],
}
question = lettings_log.form.get_question("ecstat1", lettings_log)
answer = Answer.new(question:, log: lettings_log)
expect(display_informative_text(informative_text, lettings_log))
.to eq(I18n.t("test.one_argument", ecstat1: answer.answer_label.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",
},
],
}
question = lettings_log.form.get_question("ecstat1", lettings_log)
answer = Answer.new(question:, log: lettings_log)
expect(display_informative_text(informative_text, lettings_log))
.to eq(I18n.t("test.one_argument", ecstat1: answer.answer_label.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, lettings_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 = { "translation" => "test.title_text.no_argument" }
expect(display_title_text(title_text, lettings_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",
},
],
}
question = lettings_log.form.get_question("ecstat1", lettings_log)
answer = Answer.new(log: lettings_log, question:)
expect(display_title_text(title_text, lettings_log))
.to eq(I18n.t("test.title_text.one_argument", ecstat1: answer.answer_label.downcase))
end
end
context "when title text is not defined" do
it "returns an empty string" do
expect(display_title_text(nil, lettings_log)).to eq("")
end
end
context "when title text is empty string" do
it "returns an empty string" do
expect(display_title_text("", lettings_log)).to eq("")
end
end
end
end