Browse Source

Fix tests

pull/103/head
baarkerlounger 4 years ago
parent
commit
d10fc27d2d
  1. 2
      Gemfile
  2. 19
      app/helpers/tasklist_helper.rb
  3. 2
      app/models/form.rb
  4. 2
      app/views/case_logs/_tasklist.html.erb
  5. 6
      spec/factories/case_log.rb
  6. 5
      spec/helpers/tasklist_helper_spec.rb

2
Gemfile

@ -33,8 +33,8 @@ gem "chartkick"
gem "roo"
# Json Schema
gem "json-schema"
gem "uk_postcode"
gem "turbo-rails", "~> 0.8"
gem "uk_postcode"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console

19
app/helpers/tasklist_helper.rb

@ -15,7 +15,7 @@ module TasklistHelper
def get_next_incomplete_section(form, case_log)
subsections = form.all_subsections.keys
subsections.find { |subsection| is_incomplete?(subsection, case_log, form, form.questions_for_subsection(subsection)) }
subsections.find { |subsection| is_incomplete?(subsection, case_log, form) }
end
def get_subsections_count(form, case_log, status = :all)
@ -25,8 +25,8 @@ module TasklistHelper
subsections.count { |subsection| form.subsection_status(subsection, case_log) == status }
end
def get_first_page_or_check_answers(subsection, case_log, form, questions)
path = if is_started?(subsection, case_log, form, questions)
def get_first_page_or_check_answers(subsection, case_log, form)
path = if is_started?(subsection, case_log, form)
"case_log_#{subsection}_check_answers_path"
else
"case_log_#{form.first_page_for_subsection(subsection)}_path"
@ -34,24 +34,19 @@ module TasklistHelper
send(path, case_log)
end
def subsection_link(subsection_key, subsection_value, status)
next_page_path = if status != :cannot_start_yet
questions = @form.questions_for_subsection(subsection_key)
get_first_page_or_check_answers(subsection_key, @case_log, @form, questions)
else
"#"
end
def subsection_link(subsection_key, subsection_value, status, form, case_log)
next_page_path = status != :cannot_start_yet ? get_first_page_or_check_answers(subsection_key, case_log, form) : "#"
link_to(subsection_value["label"], next_page_path, class: "task-name govuk-link")
end
private
def is_incomplete?(subsection, case_log, form, questions)
def is_incomplete?(subsection, case_log, form)
status = form.subsection_status(subsection, case_log)
%i[not_started in_progress].include?(status)
end
def is_started?(subsection, case_log, form, questions)
def is_started?(subsection, case_log, form)
status = form.subsection_status(subsection, case_log)
%i[in_progress completed].include?(status)
end

2
app/models/form.rb

@ -108,7 +108,7 @@ class Form
end
def page_routed_to?(page, case_log)
return true unless conditions = page_dependencies(page)
return true unless (conditions = page_dependencies(page))
conditions.all? do |question, value|
case_log[question].present? && case_log[question] == value

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

@ -11,7 +11,7 @@
<li class="app-task-list__item" id=<%= subsection_key %>>
<% questions_for_subsection = @form.questions_for_subsection(subsection_key) %>
<% subsection_status = @form.subsection_status(subsection_key, @case_log) %>
<%= subsection_link(subsection_key, subsection_value, subsection_status) %>
<%= subsection_link(subsection_key, subsection_value, subsection_status, @form, @case_log) %>
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>">
<%= TasklistHelper::STATUSES[subsection_status] %>
</strong>

6
spec/factories/case_log.rb

@ -4,7 +4,7 @@ FactoryBot.define do
trait :in_progress do
status { 1 }
tenant_code { "TH356" }
postcode { "P0 5ST" }
property_postcode { "P0 5ST" }
previous_postcode { "SW2 6HI" }
age1 { "17" }
end
@ -114,7 +114,7 @@ FactoryBot.define do
rent_type { 1 }
intermediate_rent_product_name { 2 }
needs_type { 1 }
purchaser_code { 798794 }
purchaser_code { 798_794 }
reason { "Permanently decanted from another property owned by this landlord" }
propcode { "123" }
majorrepairs { "Yes" }
@ -131,7 +131,7 @@ FactoryBot.define do
mrcday { 5 }
mrcmonth { 5 }
mrcyear { 2020 }
incref { 554355 }
incref { 554_355 }
sale_completion_date { nil }
startdate { nil }
armedforces { 1 }

5
spec/helpers/tasklist_helper_spec.rb

@ -5,7 +5,6 @@ RSpec.describe TasklistHelper do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
form_handler = FormHandler.instance
let(:form) { form_handler.get_form("test_form") }
let(:household_characteristics_questions) { form.questions_for_subsection("household_characteristics") }
describe "get next incomplete section" do
it "returns the first subsection name if it is not completed" do
@ -42,11 +41,11 @@ RSpec.describe TasklistHelper do
describe "get_first_page_or_check_answers" do
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/)
expect(get_first_page_or_check_answers("household_characteristics", case_log, form)).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/)
expect(get_first_page_or_check_answers("household_characteristics", empty_case_log, form)).to match(/tenant_code/)
end
end
end

Loading…
Cancel
Save