Browse Source

lint

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

25
app/helpers/tasklist_helper.rb

@ -1,17 +1,17 @@
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"
@ -20,6 +20,7 @@ module TasklistHelper
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
def all_questions_completed(case_log)
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

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

2
spec/helpers/tasklist_helper_spec.rb

@ -25,7 +25,7 @@ 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

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