diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb
new file mode 100644
index 000000000..788f258c0
--- /dev/null
+++ b/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
diff --git a/app/models/form.rb b/app/models/form.rb
index 00c3503af..960b8ca1f 100644
--- a/app/models/form.rb
+++ b/app/models/form.rb
@@ -60,4 +60,8 @@ class Form
pages_for_subsection(subsection).keys[current_page_idx - 1]
end
+
+ def questions_for_subsection(subsection)
+ pages_for_subsection(subsection).map {|title, _value| questions_for_page(title)}.reduce(:merge)
+ end
end
diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb
index d0e60c396..b09864cae 100644
--- a/app/views/case_logs/_tasklist.html.erb
+++ b/app/views/case_logs/_tasklist.html.erb
@@ -11,8 +11,9 @@
<% 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" %>
+ <% subsection_status=get_subsection_status(subsection_key, @case_log) %>
- Not started
+ <%= subsection_status %>
<% end %>
diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb
index fa3cfbbf1..2761820ad 100644
--- a/spec/features/case_log_spec.rb
+++ b/spec/features/case_log_spec.rb
@@ -25,10 +25,20 @@ RSpec.describe "Test Features" do
end
describe "Viewing a log" do
- it "displays a tasklist header" do
- visit("/case_logs/#{id}")
- expect(page).to have_content("Tasklist for log #{id}")
- expect(page).to have_content("This submission is #{status}")
+ context "tasklist page" do
+ it "displays a tasklist header" do
+ visit("/case_logs/#{id}")
+ 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
it "displays the household questions when you click into that section" do
diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb
new file mode 100644
index 000000000..98f886a29
--- /dev/null
+++ b/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
diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb
index 912370b1e..2a6c00d8c 100644
--- a/spec/models/form_spec.rb
+++ b/spec/models/form_spec.rb
@@ -32,4 +32,13 @@ RSpec.describe Form, type: :model do
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