6 changed files with 81 additions and 5 deletions
@ -0,0 +1,21 @@ |
|||||||
|
module TasklistHelper |
||||||
|
def get_subsection_status(subsection_name, case_log) |
||||||
|
@form = Form.new(2021, 2022) |
||||||
|
questions = @form.questions_for_subsection(subsection_name).keys |
||||||
|
|
||||||
|
if subsection_name == "declaration" |
||||||
|
return all_questions_completed(case_log) ? "Not started" : "Cannot start yet" |
||||||
|
end |
||||||
|
if questions.all? {|question| case_log[question].blank?} |
||||||
|
return "Not started" |
||||||
|
end |
||||||
|
if questions.all? {|question| case_log[question].present?} |
||||||
|
return "Completed" |
||||||
|
end |
||||||
|
"In progress" |
||||||
|
end |
||||||
|
|
||||||
|
def all_questions_completed(case_log) |
||||||
|
case_log.attributes.all? { |_question, answer| answer.present?} |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,31 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe TasklistHelper do |
||||||
|
describe "get subsection status" do |
||||||
|
let!(:case_log) { FactoryBot.create(:case_log) } |
||||||
|
@form = Form.new(2021, 2022) |
||||||
|
|
||||||
|
it "returns not started if none of the questions in the subsection are answered" do |
||||||
|
expect(get_subsection_status("income_and_benefits", case_log)).to eq("Not started") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns cannot start yet if the subsection is declaration" do |
||||||
|
expect(get_subsection_status("declaration", case_log)).to eq("Cannot start yet") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns in progress if some of the questions have been answered" do |
||||||
|
case_log["previous_postcode"] = "P0 5TT" |
||||||
|
expect(get_subsection_status("local_authority", case_log)).to eq("In progress") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns completed if all the questions in the subsection have been answered" do |
||||||
|
%w(net_income net_income_frequency net_income_uc_proportion housing_benefit).each {|x| case_log[x] = "value" } |
||||||
|
expect(get_subsection_status("income_and_benefits", case_log)).to eq("Completed") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns not started if the subsection is declaration and all the questions are completed" do |
||||||
|
completed_case_log = CaseLog.new(case_log.attributes.map { |key, value| Hash[key, value || "value"] }.reduce(:merge)) |
||||||
|
expect(get_subsection_status("declaration", completed_case_log)).to eq("Not started") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue