Browse Source

Get and display subsection completion status in tasklist

pull/28/head
Kat 4 years ago
parent
commit
18068392bb
  1. 21
      app/helpers/tasklist_helper.rb
  2. 4
      app/models/form.rb
  3. 3
      app/views/case_logs/_tasklist.html.erb
  4. 18
      spec/features/case_log_spec.rb
  5. 31
      spec/helpers/tasklist_helper_spec.rb
  6. 9
      spec/models/form_spec.rb

21
app/helpers/tasklist_helper.rb

@ -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

4
app/models/form.rb

@ -60,4 +60,8 @@ class Form
pages_for_subsection(subsection).keys[current_page_idx - 1] pages_for_subsection(subsection).keys[current_page_idx - 1]
end end
def questions_for_subsection(subsection)
pages_for_subsection(subsection).map {|title, _value| questions_for_page(title)}.reduce(:merge)
end
end end

3
app/views/case_logs/_tasklist.html.erb

@ -11,8 +11,9 @@
<li class="app-task-list__item"> <li class="app-task-list__item">
<% first_page = @form.first_page_for_subsection(subsection_key) %> <% first_page = @form.first_page_for_subsection(subsection_key) %>
<%= link_to subsection_value["label"], send("case_log_#{first_page}_path", @case_log), class: "task-name" %> <%= link_to subsection_value["label"], send("case_log_#{first_page}_path", @case_log), class: "task-name" %>
<% subsection_status=get_subsection_status(subsection_key, @case_log) %>
<strong class="govuk-tag govuk-tag--grey app-task-list__tag"> <strong class="govuk-tag govuk-tag--grey app-task-list__tag">
Not started <%= subsection_status %>
</strong> </strong>
</li> </li>
<% end %> <% end %>

18
spec/features/case_log_spec.rb

@ -25,10 +25,20 @@ RSpec.describe "Test Features" do
end end
describe "Viewing a log" do describe "Viewing a log" do
it "displays a tasklist header" do context "tasklist page" do
visit("/case_logs/#{id}") it "displays a tasklist header" do
expect(page).to have_content("Tasklist for log #{id}") visit("/case_logs/#{id}")
expect(page).to have_content("This submission is #{status}") expect(page).to have_content("Tasklist for log #{id}")
expect(page).to have_content("This submission is #{status}")
end
it "displays a section status" do
visit("/case_logs/#{empty_case_log.id}")
assert_selector ".govuk-tag", text: /Not started/, count: 8
assert_selector ".govuk-tag", text: /Completed/, count: 0
assert_selector ".govuk-tag", text: /Cannot start yet/, count: 1
end
end end
it "displays the household questions when you click into that section" do it "displays the household questions when you click into that section" do

31
spec/helpers/tasklist_helper_spec.rb

@ -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

9
spec/models/form_spec.rb

@ -32,4 +32,13 @@ RSpec.describe Form, type: :model do
end end
end end
end end
describe ".questions_for_subsection" do
let(:subsection) { "income_and_benefits" }
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"])
end
end
end end

Loading…
Cancel
Save