Browse Source

add test for conditional display of page

pull/193/head
MadeTech Dushan 4 years ago
parent
commit
d241ad2c09
  1. 2
      app/helpers/tasklist_helper.rb
  2. 11
      app/models/form/page.rb
  3. 3
      config/forms/2021_2022.json
  4. 24
      spec/features/form/page_routing_spec.rb
  5. 21
      spec/fixtures/forms/2021_2022.json

2
app/helpers/tasklist_helper.rb

@ -29,7 +29,7 @@ module TasklistHelper
path = if subsection.is_started?(case_log)
"case_log_#{subsection.id}_check_answers_path"
else
"case_log_#{subsection.pages.first.id}_path"
"case_log_#{subsection.applicable_questions(case_log).first.page.id}_path"
end
send(path, case_log)
end

11
app/models/form/page.rb

@ -21,11 +21,22 @@ class Form::Page
soft_validations.present?
end
def is_22_23_log?(startdate)
return false if startdate.blank?
startdate.to_date > Date.parse("2022-04-01") && startdate.to_date < Date.parse("2023-04-01")
end
def routed_to?(case_log)
return true unless depends_on
depends_on.all? do |question, value|
!case_log[question].nil? && case_log[question] == value
if question == "conditions"
return value.all? { |condition| eval(condition) }
end
case_log[question].present? && case_log[question] == value
end
end
end

3
config/forms/2021_2022.json

@ -1069,7 +1069,8 @@
"2": "Don't know"
}
}
}
},
"depends_on": { "conditions" : ["is_22_23_log?(case_log[\"startdate\"])"] }
},
"starter_tenancy": {
"header": "",

24
spec/features/form/page_routing_spec.rb

@ -72,4 +72,28 @@ RSpec.describe "Form Page Routing" do
expect(page).to have_current_path("/logs/#{id}/property-wheelchair-accessible")
end
end
context "routing based on start date period", js: true do
it "the first question in tenancy information section is joint tenancy if startdate is in 2022/23 period" do
visit("/case-logs/#{id}/startdate")
fill_in("case_log_startdate_3i", with: 10)
fill_in("case_log_startdate_2i", with: 10)
fill_in("case_log_startdate_1i", with: 2022)
click_button("Save and continue")
visit("/case-logs/#{id}")
click_link(text: "Tenancy information")
expect(page).to have_current_path("/case-logs/#{id}/joint-tenancy")
end
it "the first question in tenancy information section is not joint tenancy if startdate is in 2021/22 period" do
visit("/case-logs/#{id}/startdate")
fill_in("case_log_startdate_3i", with: 10)
fill_in("case_log_startdate_2i", with: 10)
fill_in("case_log_startdate_1i", with: 2021)
click_button("Save and continue")
visit("/case-logs/#{id}")
click_link(text: "Tenancy information")
expect(page).to have_current_path("/case-logs/#{id}/tenancy-code")
end
end
end

21
spec/fixtures/forms/2021_2022.json vendored

@ -250,16 +250,6 @@
"tenancy_information": {
"label": "Tenancy information",
"pages": {
"tenancy_code": {
"questions": {
"tenancy_code": {
"check_answer_label": "What is the tenancy code?",
"header": "What is the tenancy code?",
"type": "text",
"width": 10
}
}
},
"joint_tenancy": {
"header": "",
"description": "",
@ -275,6 +265,17 @@
"2": "Don't know"
}
}
},
"depends_on": { "conditions" : ["is_22_23_log?(case_log[\"startdate\"])"] }
},
"tenancy_code": {
"questions": {
"tenancy_code": {
"check_answer_label": "What is the tenancy code?",
"header": "What is the tenancy code?",
"type": "text",
"width": 10
}
}
},
"letting_in_sheltered_accomodation": {

Loading…
Cancel
Save