Browse Source

Navigate straight to check answers page if a section has been started… (#41)

* Navigate straight to check answers page if a section has been started already

* Code review suggestion

* Remove Form config specific test
pull/42/head
Daniel Baark 3 years ago committed by GitHub
parent
commit
8e93fb976d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/helpers/tasklist_helper.rb
  2. 7
      app/views/case_logs/_tasklist.html.erb
  3. 12
      spec/features/case_log_spec.rb
  4. 51
      spec/helpers/tasklist_helper_spec.rb

14
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

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

@ -9,9 +9,10 @@
<ul class="app-task-list__items">
<% section_value["subsections"].map do |subsection_key, subsection_value| %>
<li class="app-task-list__item" id=<%= 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 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) %>
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>">
<%= TasklistHelper::STATUSES[subsection_status] %>
</strong>

12
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(

51
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

Loading…
Cancel
Save