Browse Source

lint

pull/28/head
Kat 4 years ago
parent
commit
364aa6742e
  1. 33
      app/helpers/tasklist_helper.rb
  2. 2
      app/models/form.rb
  3. 3
      spec/features/case_log_spec.rb
  4. 4
      spec/helpers/tasklist_helper_spec.rb
  5. 2
      spec/models/form_spec.rb

33
app/helpers/tasklist_helper.rb

@ -1,25 +1,26 @@
module TasklistHelper
STATUSES = {
:not_started => "Not started",
:cannot_start_yet => "Cannot start yet",
:completed => "Completed",
:in_progress => "In progress"
}
not_started: "Not started",
cannot_start_yet: "Cannot start yet",
completed: "Completed",
in_progress: "In progress",
}.freeze
STYLES = {
:not_started => "govuk-tag--grey",
:cannot_start_yet => "govuk-tag--grey",
:completed => "",
:in_progress => "govuk-tag--blue"
}
not_started: "govuk-tag--grey",
cannot_start_yet: "govuk-tag--grey",
completed: "",
in_progress: "govuk-tag--blue",
}.freeze
def get_subsection_status(subsection_name, case_log, questions)
if subsection_name == "declaration"
return all_questions_completed(case_log) ? :not_started : :cannot_start_yet
end
return :not_started if questions.all? {|question| case_log[question].blank?}
return :completed if questions.all? {|question| case_log[question].present?}
return :not_started if questions.all? { |question| case_log[question].blank? }
return :completed if questions.all? { |question| case_log[question].present? }
:in_progress
end
@ -39,16 +40,18 @@ module TasklistHelper
def get_sections_count(form, case_log, status = :all)
subsections = form.all_subsections.keys
return subsections.count if status == :all
subsections.count { |subsection| get_subsection_status(subsection, case_log, form.questions_for_subsection(subsection).keys) == status }
end
private
private
def all_questions_completed(case_log)
case_log.attributes.all? { |_question, answer| answer.present?}
case_log.attributes.all? { |_question, answer| answer.present? }
end
def is_incomplete?(subsection, case_log, questions)
status = get_subsection_status(subsection, case_log, questions)
status == :not_started || status == :in_progress
%i[not_started in_progress].include?(status)
end
end

2
app/models/form.rb

@ -62,6 +62,6 @@ class Form
end
def questions_for_subsection(subsection)
pages_for_subsection(subsection).map {|title, _value| questions_for_page(title)}.reduce(:merge)
pages_for_subsection(subsection).map { |title, _value| questions_for_page(title) }.reduce(:merge)
end
end

3
spec/features/case_log_spec.rb

@ -26,7 +26,6 @@ RSpec.describe "Test Features" do
click_button("Save and continue")
end
describe "Create new log" do
it "redirects to the task list for the new log" do
visit("/case_logs")
@ -63,7 +62,7 @@ RSpec.describe "Test Features" do
it "skips to the first section if no answers are completed" do
visit("/case_logs/#{empty_case_log.id}")
expect(page).to have_link("Skip to next incomplete section", :href => /#household_characteristics/)
expect(page).to have_link("Skip to next incomplete section", href: /#household_characteristics/)
end
it "shows the number of completed sections if no sections are completed" do

4
spec/helpers/tasklist_helper_spec.rb

@ -25,13 +25,13 @@ RSpec.describe TasklistHelper do
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" }
%w[net_income net_income_frequency net_income_uc_proportion housing_benefit].each { |x| case_log[x] = "value" }
status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions)
expect(status).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))
completed_case_log = CaseLog.new(case_log.attributes.map { |key, value| Hash[key, value || "value"] }.reduce(:merge))
status = get_subsection_status("declaration", completed_case_log, declaration_questions)
expect(status).to eq(:not_started)
end

2
spec/models/form_spec.rb

@ -38,7 +38,7 @@ RSpec.describe Form, type: :model do
it "returns all questions for subsection" do
result = form.questions_for_subsection(subsection)
expect(result.length).to eq(4)
expect(result.keys).to eq(["net_income", "net_income_frequency", "net_income_uc_proportion", "housing_benefit"])
expect(result.keys).to eq(%w[net_income net_income_frequency net_income_uc_proportion housing_benefit])
end
end
end

Loading…
Cancel
Save