From cca358c7c78b2f3b6473095fe77513b89f38b988 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 12 Apr 2023 13:17:54 +0100 Subject: [PATCH] feat: update tests --- spec/features/form/form_navigation_spec.rb | 2 +- spec/models/form_spec.rb | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb index aa0223616..6fdec8366 100644 --- a/spec/features/form/form_navigation_spec.rb +++ b/spec/features/form/form_navigation_spec.rb @@ -110,7 +110,7 @@ RSpec.describe "Form Navigation" do click_button("Save and continue") click_link(text: "Back") click_link(text: "Back") - expect(page).to have_current_path("/lettings-logs") + expect(page).to have_current_path("/lettings-logs/#{id}") end context "when changing an answer from the check answers page", js: true do diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 209306201..cd3ccac5b 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -21,7 +21,7 @@ RSpec.describe Form, type: :model do let(:value_check_previous_page) { form.get_page("net_income_value_check") } it "returns the next page given the previous" do - expect(form.next_page_id(previous_page, lettings_log, user)).to eq("person_1_gender") + expect(form.next_page_id(previous_page_id, lettings_log, user)).to eq("person_1_gender") end context "when the current page is a value check page" do @@ -46,20 +46,19 @@ RSpec.describe Form, type: :model do describe ".previous_page" do context "when the current page is not a value check page" do let!(:subsection) { form.get_subsection("conditional_question") } - let!(:page_ids) { subsection.pages.map(&:id) } before do lettings_log.preg_occ = 2 end it "returns the previous page if the page is routed to" do - page_index = page_ids.index("conditional_question_no_second_page") - expect(form.previous_page_id(page_ids, page_index, lettings_log, user)).to eq("conditional_question_no_page") + page = subsection.pages.find { |p| p.id == "conditional_question_no_second_page" } + expect(form.previous_page_id(page, lettings_log, user)).to eq("conditional_question_no_page") end it "returns the page before the previous one if the previous page is not routed to" do - page_index = page_ids.index("conditional_question_no_page") - expect(form.previous_page_id(page_ids, page_index, lettings_log, user)).to eq("conditional_question") + page = subsection.pages.find { |p| p.id == "conditional_question_no_page" } + expect(form.previous_page_id(page, lettings_log, user)).to eq("conditional_question") end end end @@ -70,7 +69,7 @@ RSpec.describe Form, type: :model do let(:previous_conditional_page) { form.get_page("conditional_question") } it "returns a correct page path if there is no conditional routing" do - expect(form.next_page_redirect_path(previous_page, lettings_log, user)).to eq("lettings_log_net_income_uc_proportion_path") + expect(form.next_page_redirect_path(previous_page_id, lettings_log, user)).to eq("lettings_log_net_income_uc_proportion_path") end it "returns a check answers page if previous page is the last page" do