Browse Source

feat: fix page_routing_spec.rb

pull/1378/head
natdeanlewissoftwire 3 years ago
parent
commit
b0e94d0663
  1. 159
      spec/features/form/page_routing_spec.rb

159
spec/features/form/page_routing_spec.rb

@ -20,95 +20,106 @@ RSpec.describe "Form Page Routing" do
sign_in user sign_in user
end end
it "can route the user to a different page based on their answer on the current page", js: true do context "with 21/22 logs" do
visit("/lettings-logs/#{id}/conditional-question") around do |example|
# using a question name that is already in the db to avoid Timecop.freeze(Time.zone.local(2022, 1, 1)) do
# having to add a new column to the db for this test Singleton.__init__(FormHandler)
choose("lettings-log-preg-occ-1-field", allow_label_click: true) example.run
click_button("Save and continue") end
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question-yes-page") Timecop.return
click_link(text: "Back") Singleton.__init__(FormHandler)
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question") end
choose("lettings-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question-no-page")
end
it "can route based on multiple conditions", js: true do
visit("/lettings-logs/#{id}/person-1-gender")
choose("lettings-log-sex1-f-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/person-1-working-situation")
visit("/lettings-logs/#{id}/conditional-question")
choose("lettings-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question-no-page")
choose("lettings-log-cbl-0-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question/check-answers")
end
context "when the answers are inferred", js: true do it "can route the user to a different page based on their answer on the current page", js: true do
it "shows question if the answer could not be inferred" do visit("/lettings-logs/#{id}/conditional-question")
visit("/lettings-logs/#{id}/property-postcode") # using a question name that is already in the db to avoid
fill_in("lettings-log-postcode-full-field", with: "PO5 3TE") # having to add a new column to the db for this test
choose("lettings-log-preg-occ-1-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question-yes-page")
click_link(text: "Back")
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question")
choose("lettings-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/do-you-know-the-local-authority") expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question-no-page")
end end
it "shows question if the answer could not be inferred from an empty input" do it "can route based on multiple conditions", js: true do
visit("/lettings-logs/#{id}/property-postcode") visit("/lettings-logs/#{id}/person-1-gender")
choose("lettings-log-sex1-f-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/do-you-know-the-local-authority") expect(page).to have_current_path("/lettings-logs/#{id}/person-1-working-situation")
visit("/lettings-logs/#{id}/conditional-question")
choose("lettings-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question-no-page")
choose("lettings-log-cbl-0-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/conditional-question/check-answers")
end end
it "does not show question if the answer could be inferred" do context "when the answers are inferred", js: true do
stub_request(:get, /api.postcodes.io/) it "shows question if the answer could not be inferred" do
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) visit("/lettings-logs/#{id}/property-postcode")
fill_in("lettings-log-postcode-full-field", with: "PO5 3TE")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/do-you-know-the-local-authority")
end
visit("/lettings-logs/#{id}/property-postcode") it "shows question if the answer could not be inferred from an empty input" do
fill_in("lettings-log-postcode-full-field", with: "P0 5ST") visit("/lettings-logs/#{id}/property-postcode")
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/property-wheelchair-accessible") expect(page).to have_current_path("/lettings-logs/#{id}/do-you-know-the-local-authority")
end end
end
context "when answer is invalid" do it "does not show question if the answer could be inferred" do
it "shows error with invalid value in the field" do stub_request(:get, /api.postcodes.io/)
visit("/lettings-logs/#{id}/property-postcode") .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
fill_in("lettings-log-postcode-full-field", with: "fake_postcode")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/property-postcode") visit("/lettings-logs/#{id}/property-postcode")
expect(find("#lettings-log-postcode-full-field-error").value).to eq("fake_postcode") fill_in("lettings-log-postcode-full-field", with: "P0 5ST")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/property-wheelchair-accessible")
end
end end
it "does not reset the displayed date" do context "when answer is invalid" do
lettings_log.update!(startdate: "2021/10/13") it "shows error with invalid value in the field" do
visit("/lettings-logs/#{id}/tenancy-start-date") visit("/lettings-logs/#{id}/property-postcode")
fill_in("lettings_log[startdate(1i)]", with: "202") fill_in("lettings-log-postcode-full-field", with: "fake_postcode")
fill_in("lettings_log[startdate(2i)]", with: "32") click_button("Save and continue")
fill_in("lettings_log[startdate(3i)]", with: "0")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/tenancy-start-date") expect(page).to have_current_path("/lettings-logs/#{id}/property-postcode")
expect(find_field("lettings_log[startdate(3i)]").value).to eq("13") expect(find("#lettings-log-postcode-full-field-error").value).to eq("fake_postcode")
expect(find_field("lettings_log[startdate(2i)]").value).to eq("10") end
expect(find_field("lettings_log[startdate(1i)]").value).to eq("2021")
end
it "does not reset the displayed date if it's empty" do it "does not reset the displayed date" do
lettings_log.update!(startdate: nil) lettings_log.update!(startdate: "2021/10/13")
visit("/lettings-logs/#{id}/tenancy-start-date") visit("/lettings-logs/#{id}/tenancy-start-date")
fill_in("lettings_log[startdate(1i)]", with: "202") fill_in("lettings_log[startdate(1i)]", with: "202")
fill_in("lettings_log[startdate(2i)]", with: "32") fill_in("lettings_log[startdate(2i)]", with: "32")
fill_in("lettings_log[startdate(3i)]", with: "0") fill_in("lettings_log[startdate(3i)]", with: "0")
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/tenancy-start-date")
expect(find_field("lettings_log[startdate(3i)]").value).to eq("13")
expect(find_field("lettings_log[startdate(2i)]").value).to eq("10")
expect(find_field("lettings_log[startdate(1i)]").value).to eq("2021")
end
expect(page).to have_current_path("/lettings-logs/#{id}/tenancy-start-date") it "does not reset the displayed date if it's empty" do
expect(find_field("lettings_log[startdate(3i)]").value).to eq(nil) lettings_log.update!(startdate: nil)
expect(find_field("lettings_log[startdate(2i)]").value).to eq(nil) visit("/lettings-logs/#{id}/tenancy-start-date")
expect(find_field("lettings_log[startdate(1i)]").value).to eq(nil) fill_in("lettings_log[startdate(1i)]", with: "202")
fill_in("lettings_log[startdate(2i)]", with: "32")
fill_in("lettings_log[startdate(3i)]", with: "0")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{id}/tenancy-start-date")
expect(find_field("lettings_log[startdate(3i)]").value).to eq(nil)
expect(find_field("lettings_log[startdate(2i)]").value).to eq(nil)
expect(find_field("lettings_log[startdate(1i)]").value).to eq(nil)
end
end end
end end

Loading…
Cancel
Save