diff --git a/app/helpers/form_page_helper.rb b/app/helpers/form_page_helper.rb
index 99c5276bc..aefbed1c1 100644
--- a/app/helpers/form_page_helper.rb
+++ b/app/helpers/form_page_helper.rb
@@ -10,4 +10,12 @@ module FormPageHelper
def accessed_from_duplicate_logs?(referrer)
%w[duplicate_logs duplicate_logs_banner].include?(referrer)
end
+
+ def duplicate_log_set_path(log, original_log_id)
+ send("#{log.class.name.underscore}_duplicate_logs_path", log, original_log_id:)
+ end
+
+ def relevant_check_answers_path(log, subsection)
+ send("#{log.class.name.underscore}_#{subsection.id}_check_answers_path", log)
+ end
end
diff --git a/app/helpers/review_helper.rb b/app/helpers/review_helper.rb
index e76602a28..87fb691eb 100644
--- a/app/helpers/review_helper.rb
+++ b/app/helpers/review_helper.rb
@@ -11,17 +11,16 @@ module ReviewHelper
end
def review_breadcrumbs(log)
- class_name = log.class.model_name.human.downcase
if log.collection_closed_for_editing?
content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
breadcrumb_logs_title(log, current_user) => breadcrumb_logs_link(log, current_user),
- "Log #{log.id}" => "",
})
else
content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
breadcrumb_logs_title(log, current_user) => breadcrumb_logs_link(log, current_user),
"Log #{log.id}" => url_for(log),
- "Review #{class_name}" => "",
})
end
end
diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb
index 9247f1aab..7c26dd123 100644
--- a/app/views/form/check_answers.html.erb
+++ b/app/views/form/check_answers.html.erb
@@ -1,8 +1,8 @@
<% content_for :title, "#{subsection.id.humanize} - Check your answers" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
breadcrumb_logs_title(@log, current_user) => breadcrumb_logs_link(@log, current_user),
"Log #{@log.id}" => url_for(@log),
- subsection.label => "",
}) %>
diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb
index a16c01c89..32ccdaed5 100644
--- a/app/views/form/page.html.erb
+++ b/app/views/form/page.html.erb
@@ -1,7 +1,15 @@
<% content_for :title, @page.header.presence || @page.questions.first.header.html_safe %>
-
-<% content_for :before_content do %>
- <%= govuk_back_link(href: send(@log.form.previous_page_redirect_path(@page, @log, current_user, params[:referrer]), @log)) %>
+<% if accessed_from_duplicate_logs?(request.query_parameters["referrer"]) %>
+ <% content_for :before_content do %>
+ <%= govuk_back_link(href: duplicate_log_set_path(@log, request.query_parameters["original_log_id"])) %>
+ <% end %>
+<% else %>
+ <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
+ breadcrumb_logs_title(@log, current_user) => breadcrumb_logs_link(@log, current_user),
+ "Log #{@log.id}" => url_for(@log),
+ @subsection.label => relevant_check_answers_path(@log, @subsection),
+ }) %>
<% end %>
@@ -66,7 +74,7 @@
<% if !@page.interruption_screen? %>
<% if accessed_from_duplicate_logs?(request.query_parameters["referrer"]) %>
<%= f.govuk_submit "Save changes" %>
- <%= govuk_link_to "Cancel", send("#{@log.class.name.underscore}_duplicate_logs_path", @log, original_log_id: request.query_parameters["original_log_id"]) %>
+ <%= govuk_link_to "Cancel", duplicate_log_set_path(@log, request.query_parameters["original_log_id"]) %>
<% elsif returning_to_question_page?(@page, request.query_parameters["referrer"]) %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", send(@log.form.cancel_path(@page, @log), @log) %>
diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb
index 1705724bb..88b17321e 100644
--- a/app/views/locations/index.html.erb
+++ b/app/views/locations/index.html.erb
@@ -4,9 +4,9 @@
<% if current_user.support? %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
"Schemes (#{@scheme.owning_organisation.name})" => schemes_organisation_path(@scheme.owning_organisation),
content_for(:title) => scheme_path(@scheme),
- "Locations" => "",
}) %>
<% else %>
<% content_for :before_content do %>
diff --git a/app/views/logs/edit.html.erb b/app/views/logs/edit.html.erb
index b4769698b..68bf78e87 100644
--- a/app/views/logs/edit.html.erb
+++ b/app/views/logs/edit.html.erb
@@ -1,7 +1,7 @@
<% content_for :title, "Log #{@log.id}" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
breadcrumb_logs_title(@log, current_user) => breadcrumb_logs_link(@log, current_user),
- content_for(:title) => "",
}) %>
diff --git a/app/views/schemes/show.html.erb b/app/views/schemes/show.html.erb
index fee4b8a83..c45cefb14 100644
--- a/app/views/schemes/show.html.erb
+++ b/app/views/schemes/show.html.erb
@@ -3,8 +3,8 @@
<% if current_user.support? %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
"Schemes (#{@scheme.owning_organisation.name})" => schemes_organisation_path(@scheme.owning_organisation),
- content_for(:title) => "",
}) %>
<% else %>
<% content_for :before_content do %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 895a2fe79..a8f12cd36 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -2,8 +2,8 @@
<% if current_user.support? %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
+ "Home" => root_path,
"Users (#{@user.organisation.name})" => users_organisation_path(@user.organisation),
- content_for(:title) => "",
}) %>
<% else %>
<% content_for :before_content do %>
diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb
index 255f95f83..373d0232d 100644
--- a/spec/features/form/accessible_autocomplete_spec.rb
+++ b/spec/features/form/accessible_autocomplete_spec.rb
@@ -60,7 +60,7 @@ RSpec.describe "Accessible Autocomplete" do
it "maintains enhancement state across back navigation", js: true do
find("#lettings-log-prevloc-field").click.native.send_keys("T", "h", "a", "n", :down, :enter)
click_button("Save and continue")
- click_link(text: "Back")
+ page.go_back
expect(page).to have_selector("input", class: "autocomplete__input", count: 1)
end
end
diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb
index 256b16d74..bb326c76c 100644
--- a/spec/features/form/form_navigation_spec.rb
+++ b/spec/features/form/form_navigation_spec.rb
@@ -86,41 +86,18 @@ RSpec.describe "Form Navigation" do
expect(page).to have_current_path("/lettings-logs/#{empty_lettings_log.id}/household-characteristics/check-answers")
end
- describe "Back link directs correctly", js: true do
- it "go back to tasklist page from tenant code" do
- visit("/lettings-logs/#{id}")
- visit("/lettings-logs/#{id}/tenant-code-test")
- click_link(text: "Back")
- expect(page).to have_content("Log #{id}")
- end
-
- it "go back to tenant code page from tenant age page", js: true do
- visit("/lettings-logs/#{id}/tenant-code-test")
- click_button("Save and continue")
- visit("/lettings-logs/#{id}/person-1-age")
- click_link(text: "Back")
- expect(page).to have_field("lettings-log-tenancycode-field")
- end
-
- it "doesn't get stuck in infinite loops", js: true do
- visit("/lettings-logs")
- visit("/lettings-logs/#{id}/net-income")
- fill_in("lettings-log-earnings-field", with: 740)
- choose("lettings-log-incfreq-1-field", allow_label_click: true)
- click_button("Save and continue")
- click_link(text: "Back")
- click_link(text: "Back")
- expect(page).to have_current_path("/lettings-logs/#{id}")
- end
-
- context "when changing an answer from the check answers page", js: true do
- it "the back button routes correctly" do
- visit("/lettings-logs/#{id}/household-characteristics/check-answers")
- first("a", text: /Answer/).click
- click_link("Back")
- expect(page).to have_current_path("/lettings-logs/#{id}/household-characteristics/check-answers")
- end
- end
+ it "has correct breadcrumbs" do
+ visit("/lettings-logs/#{id}/armed-forces")
+ breadcrumbs = page.find_all(".govuk-breadcrumbs__link")
+ expect(breadcrumbs.length).to eq 4
+ expect(breadcrumbs[0].text).to eq "Home"
+ expect(breadcrumbs[0][:href]).to eq root_path
+ expect(breadcrumbs[1].text).to eq "Lettings logs"
+ expect(breadcrumbs[1][:href]).to eq lettings_logs_path
+ expect(breadcrumbs[2].text).to eq "Log #{lettings_log.id}"
+ expect(breadcrumbs[2][:href]).to eq lettings_log_path(lettings_log)
+ expect(breadcrumbs[3].text).to eq "Household needs"
+ expect(breadcrumbs[3][:href]).to eq lettings_log_household_needs_check_answers_path(lettings_log)
end
end
@@ -198,5 +175,14 @@ RSpec.describe "Form Navigation" do
lettings_log.reload
expect(lettings_log.duplicates.count).to eq(1)
end
+
+ it "shows back link to duplicate logs page instead of log breadcrumbs" do
+ expect(lettings_log.duplicates.count).to eq(1)
+ visit("lettings-logs/#{id}/tenant-code-test?first_remaining_duplicate_id=#{id}&original_log_id=#{id}&referrer=duplicate_logs")
+ breadcrumbs = page.find_all(".govuk-breadcrumbs__link")
+ expect(breadcrumbs.length).to eq 0
+ click_link(text: "Back")
+ expect(page).to have_current_path("/lettings-logs/#{id}/duplicate-logs?original_log_id=#{id}")
+ end
end
end
diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb
index e6c821221..7409ff413 100644
--- a/spec/features/form/page_routing_spec.rb
+++ b/spec/features/form/page_routing_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe "Form Page Routing" do
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")
+ page.go_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")
diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb
index f5aefb6e4..f8740e6f8 100644
--- a/spec/features/lettings_log_spec.rb
+++ b/spec/features/lettings_log_spec.rb
@@ -157,10 +157,13 @@ RSpec.describe "Lettings Log Features" do
it "has the correct breadcrumbs with the correct links" do
visit lettings_log_setup_check_answers_path(lettings_log)
breadcrumbs = page.find_all(".govuk-breadcrumbs__link")
- expect(breadcrumbs.first.text).to eq "Lettings logs (DLUHC)"
- expect(breadcrumbs.first[:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation)
- expect(breadcrumbs[1].text).to eq "Log #{lettings_log.id}"
- expect(breadcrumbs[1][:href]).to eq lettings_log_path(lettings_log)
+ expect(breadcrumbs.length).to eq 3
+ expect(breadcrumbs[0].text).to eq "Home"
+ expect(breadcrumbs[0][:href]).to eq root_path
+ expect(breadcrumbs[1].text).to eq "Lettings logs (DLUHC)"
+ expect(breadcrumbs[1][:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation)
+ expect(breadcrumbs[2].text).to eq "Log #{lettings_log.id}"
+ expect(breadcrumbs[2][:href]).to eq lettings_log_path(lettings_log)
end
end
@@ -170,10 +173,13 @@ RSpec.describe "Lettings Log Features" do
it "has the correct breadcrumbs with the correct links" do
visit review_lettings_log_path(lettings_log)
breadcrumbs = page.find_all(".govuk-breadcrumbs__link")
- expect(breadcrumbs.first.text).to eq "Lettings logs (DLUHC)"
- expect(breadcrumbs.first[:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation)
- expect(breadcrumbs[1].text).to eq "Log #{lettings_log.id}"
- expect(breadcrumbs[1][:href]).to eq lettings_log_path(lettings_log)
+ expect(breadcrumbs.length).to eq 3
+ expect(breadcrumbs[0].text).to eq "Home"
+ expect(breadcrumbs[0][:href]).to eq root_path
+ expect(breadcrumbs[1].text).to eq "Lettings logs (DLUHC)"
+ expect(breadcrumbs[1][:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation)
+ expect(breadcrumbs[2].text).to eq "Log #{lettings_log.id}"
+ expect(breadcrumbs[2][:href]).to eq lettings_log_path(lettings_log)
end
end
diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb
index 83fd2f458..2fa221156 100644
--- a/spec/features/sales_log_spec.rb
+++ b/spec/features/sales_log_spec.rb
@@ -164,10 +164,13 @@ RSpec.describe "Sales Log Features" do
it "has the correct breadcrumbs with the correct links" do
visit sales_log_setup_check_answers_path(sales_log.id)
breadcrumbs = page.find_all(".govuk-breadcrumbs__link")
- expect(breadcrumbs.first.text).to eq "Sales logs (DLUHC)"
- expect(breadcrumbs.first[:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation)
- expect(breadcrumbs[1].text).to eq "Log #{sales_log.id}"
- expect(breadcrumbs[1][:href]).to eq sales_log_path(sales_log.id)
+ expect(breadcrumbs.length).to eq 3
+ expect(breadcrumbs[0].text).to eq "Home"
+ expect(breadcrumbs[0][:href]).to eq root_path
+ expect(breadcrumbs[1].text).to eq "Sales logs (DLUHC)"
+ expect(breadcrumbs[1][:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation)
+ expect(breadcrumbs[2].text).to eq "Log #{sales_log.id}"
+ expect(breadcrumbs[2][:href]).to eq sales_log_path(sales_log.id)
end
end
@@ -175,10 +178,13 @@ RSpec.describe "Sales Log Features" do
it "has the correct breadcrumbs with the correct links" do
visit review_sales_log_path(sales_log.id, sales_log: true)
breadcrumbs = page.find_all(".govuk-breadcrumbs__link")
- expect(breadcrumbs.first.text).to eq "Sales logs (DLUHC)"
- expect(breadcrumbs.first[:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation)
- expect(breadcrumbs[1].text).to eq "Log #{sales_log.id}"
- expect(breadcrumbs[1][:href]).to eq sales_log_path(sales_log.id)
+ expect(breadcrumbs.length).to eq 3
+ expect(breadcrumbs[0].text).to eq "Home"
+ expect(breadcrumbs[0][:href]).to eq root_path
+ expect(breadcrumbs[1].text).to eq "Sales logs (DLUHC)"
+ expect(breadcrumbs[1][:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation)
+ expect(breadcrumbs[2].text).to eq "Log #{sales_log.id}"
+ expect(breadcrumbs[2][:href]).to eq sales_log_path(sales_log.id)
end
end
end
diff --git a/spec/views/form/page_view_spec.rb b/spec/views/form/page_view_spec.rb
index 614f56562..6664981f9 100644
--- a/spec/views/form/page_view_spec.rb
+++ b/spec/views/form/page_view_spec.rb
@@ -25,6 +25,7 @@ RSpec.describe "form/page" do
end
before do
+ sign_in create(:user)
assign(:log, lettings_log)
assign(:page, page)
assign(:subsection, subsection)