From 8e93fb976ded0742e34822a91e0c0fe19b892f07 Mon Sep 17 00:00:00 2001
From: Daniel Baark <5101747+baarkerlounger@users.noreply.github.com>
Date: Tue, 12 Oct 2021 10:47:33 +0100
Subject: [PATCH] =?UTF-8?q?Navigate=20straight=20to=20check=20answers=20pa?=
=?UTF-8?q?ge=20if=20a=20section=20has=20been=20started=E2=80=A6=20(#41)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Navigate straight to check answers page if a section has been started already
* Code review suggestion
* Remove Form config specific test
---
app/helpers/tasklist_helper.rb | 14 +++++++
app/views/case_logs/_tasklist.html.erb | 7 ++--
spec/features/case_log_spec.rb | 12 ------
spec/helpers/tasklist_helper_spec.rb | 51 ++++++++++++++------------
4 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb
index 4c831029c..549ef2d22 100644
--- a/app/helpers/tasklist_helper.rb
+++ b/app/helpers/tasklist_helper.rb
@@ -36,6 +36,15 @@ module TasklistHelper
subsections.count { |subsection| get_subsection_status(subsection, case_log, form.questions_for_subsection(subsection).keys) == status }
end
+ def get_first_page_or_check_answers(subsection, case_log, form, questions)
+ path = if is_started?(subsection, case_log, questions)
+ "case_log_#{subsection}_check_answers_path"
+ else
+ "case_log_#{form.first_page_for_subsection(subsection)}_path"
+ end
+ send(path, case_log)
+ end
+
private
def all_questions_completed(case_log)
@@ -46,4 +55,9 @@ private
status = get_subsection_status(subsection, case_log, questions)
%i[not_started in_progress].include?(status)
end
+
+ def is_started?(subsection, case_log, questions)
+ status = get_subsection_status(subsection, case_log, questions)
+ %i[in_progress completed].include?(status)
+ end
end
diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb
index dbbeb6321..fdf4c5aa9 100644
--- a/app/views/case_logs/_tasklist.html.erb
+++ b/app/views/case_logs/_tasklist.html.erb
@@ -9,9 +9,10 @@
<% section_value["subsections"].map do |subsection_key, subsection_value| %>
- >
- <% 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 govuk-link" %>
- <% subsection_status=get_subsection_status(subsection_key, @case_log, @form.questions_for_subsection(subsection_key).keys) %>
+ <% questions_for_subsection = @form.questions_for_subsection(subsection_key).keys %>
+ <% next_page_path = get_first_page_or_check_answers(subsection_key, @case_log, @form, questions_for_subsection) %>
+ <%= link_to subsection_value["label"], next_page_path, class: "task-name govuk-link" %>
+ <% subsection_status = get_subsection_status(subsection_key, @case_log, questions_for_subsection) %>
<%= TasklistHelper::STATUSES[subsection_status] %>
diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb
index b83ccb932..d3962ad2c 100644
--- a/spec/features/case_log_spec.rb
+++ b/spec/features/case_log_spec.rb
@@ -83,18 +83,6 @@ RSpec.describe "Test Features" do
end
end
- it "displays the household questions when you click into that section" do
- visit("/case_logs/#{id}")
- click_link("Household characteristics")
- expect(page).to have_field("case-log-tenant-code-field")
- click_button("Save and continue")
- expect(page).to have_field("case-log-tenant-age-field")
- click_button("Save and continue")
- expect(page).to have_field("case-log-tenant-gender-male-field")
- visit page.driver.request.env["HTTP_REFERER"]
- expect(page).to have_field("case-log-tenant-age-field")
- end
-
describe "form questions" do
let(:case_log_with_checkbox_questions_answered) do
FactoryBot.create(
diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb
index f7b2a6534..7078159cd 100644
--- a/spec/helpers/tasklist_helper_spec.rb
+++ b/spec/helpers/tasklist_helper_spec.rb
@@ -1,12 +1,15 @@
require "rails_helper"
RSpec.describe TasklistHelper do
+ let!(:empty_case_log) { FactoryBot.create(:case_log) }
+ let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
+ let(:form) { Form.new(2021, 2022) }
+
describe "get subsection status" do
- @form = Form.new(2021, 2022)
- income_and_benefits_questions = @form.questions_for_subsection("income_and_benefits").keys
- declaration_questions = @form.questions_for_subsection("declaration").keys
- local_authority_questions = @form.questions_for_subsection("local_authority").keys
- let!(:case_log) { FactoryBot.create(:case_log) }
+ let(:section) { "income_and_benefits" }
+ let(:income_and_benefits_questions) { form.questions_for_subsection("income_and_benefits").keys }
+ let(:declaration_questions) { form.questions_for_subsection("declaration").keys }
+ let(:local_authority_questions) { form.questions_for_subsection("local_authority").keys }
it "returns not started if none of the questions in the subsection are answered" do
status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions)
@@ -38,47 +41,47 @@ RSpec.describe TasklistHelper do
end
describe "get next incomplete section" do
- let!(:case_log) { FactoryBot.create(:case_log) }
-
it "returns the first subsection name if it is not completed" do
- @form = Form.new(2021, 2022)
- expect(get_next_incomplete_section(@form, case_log)).to eq("household_characteristics")
+ expect(get_next_incomplete_section(form, case_log)).to eq("household_characteristics")
end
it "returns the first subsection name if it is partially completed" do
- @form = Form.new(2021, 2022)
case_log["tenant_code"] = 123
- expect(get_next_incomplete_section(@form, case_log)).to eq("household_characteristics")
+ expect(get_next_incomplete_section(form, case_log)).to eq("household_characteristics")
end
end
describe "get sections count" do
- let!(:empty_case_log) { FactoryBot.create(:case_log) }
- let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
-
it "returns the total of sections if no status is given" do
- @form = Form.new(2021, 2022)
- expect(get_sections_count(@form, empty_case_log)).to eq(9)
+ expect(get_sections_count(form, empty_case_log)).to eq(9)
end
it "returns 0 sections for completed sections if no sections are completed" do
- @form = Form.new(2021, 2022)
- expect(get_sections_count(@form, empty_case_log, :completed)).to eq(0)
+ expect(get_sections_count(form, empty_case_log, :completed)).to eq(0)
end
it "returns the number of not started sections" do
- @form = Form.new(2021, 2022)
- expect(get_sections_count(@form, empty_case_log, :not_started)).to eq(8)
+ expect(get_sections_count(form, empty_case_log, :not_started)).to eq(8)
end
it "returns the number of sections in progress" do
- @form = Form.new(2021, 2022)
- expect(get_sections_count(@form, case_log, :in_progress)).to eq(3)
+ expect(get_sections_count(form, case_log, :in_progress)).to eq(3)
end
it "returns 0 for invalid state" do
- @form = Form.new(2021, 2022)
- expect(get_sections_count(@form, case_log, :fake)).to eq(0)
+ expect(get_sections_count(form, case_log, :fake)).to eq(0)
+ end
+ end
+
+ describe "get_first_page_or_check_answers" do
+ let(:household_characteristics_questions) { form.questions_for_subsection("household_characteristics").keys }
+
+ it "returns the check answers page path if the section has been started already" do
+ expect(get_first_page_or_check_answers("household_characteristics", case_log, form, household_characteristics_questions)).to match(/check_answers/)
+ end
+
+ it "returns the first question page path for the section if it has not been started yet" do
+ expect(get_first_page_or_check_answers("household_characteristics", empty_case_log, form, household_characteristics_questions)).to match(/tenant_code/)
end
end
end