Browse Source

Display the correct number of completed sections

pull/713/head
Kat 3 years ago
parent
commit
03de88f7d3
  1. 4
      app/helpers/tasklist_helper.rb
  2. 2
      app/models/form/subsection.rb
  3. 2
      spec/features/form/tasklist_page_spec.rb
  4. 2
      spec/helpers/tasklist_helper_spec.rb

4
app/helpers/tasklist_helper.rb

@ -6,9 +6,9 @@ module TasklistHelper
end
def get_subsections_count(case_log, status = :all)
return case_log.form.subsections.count if status == :all
return case_log.form.subsections.count { |subsection| subsection.applicable_questions(case_log).count.positive? } if status == :all
case_log.form.subsections.count { |subsection| subsection.status(case_log) == status }
case_log.form.subsections.count { |subsection| subsection.status(case_log) == status && subsection.applicable_questions(case_log).count.positive? }
end
def next_page_or_check_answers(subsection, case_log, current_user)

2
app/models/form/subsection.rb

@ -34,7 +34,7 @@ class Form::Subsection
qs = applicable_questions(case_log)
qs_optional_removed = qs.reject { |q| case_log.optional_fields.include?(q.id) }
return :not_started if qs.all? { |question| case_log[question.id].blank? || question.read_only? || question.derived? }
return :not_started if qs.count.positive? && qs.all? { |question| case_log[question.id].blank? || question.read_only? || question.derived? }
return :completed if qs_optional_removed.all? { |question| question.completed?(case_log) }
:in_progress

2
spec/features/form/tasklist_page_spec.rb

@ -54,7 +54,7 @@ RSpec.describe "Task List" do
it "shows number of completed sections if one section is completed" do
visit("/logs/#{setup_completed_log.id}")
expect(page).to have_content("1 of 9 sections completed.")
expect(page).to have_content("1 of 8 sections completed.")
end
it "show skip link for next incomplete section" do

2
spec/helpers/tasklist_helper_spec.rb

@ -17,7 +17,7 @@ RSpec.describe TasklistHelper do
describe "get sections count" do
it "returns the total of sections if no status is given" do
expect(get_subsections_count(empty_case_log)).to eq(9)
expect(get_subsections_count(empty_case_log)).to eq(8)
end
it "returns 0 sections for completed sections if no sections are completed" do

Loading…
Cancel
Save