Browse Source

CLDC-2692: Update breadcrumb usage (#2287)

* CLDC-2692: Add breadcrumbs to log question pages

* CLDC-2692: Remove final current page breadcrumbs

* CLDC-2692: Use Home as the root of all breadcrumbs

* CLDC-2692: Use a back link when accessing log question page from duplicate logs

* Update tests
pull/2309/head
Rachael Booth 10 months ago committed by GitHub
parent
commit
f64f255e22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      app/helpers/form_page_helper.rb
  2. 5
      app/helpers/review_helper.rb
  3. 2
      app/views/form/check_answers.html.erb
  4. 14
      app/views/form/page.html.erb
  5. 2
      app/views/locations/index.html.erb
  6. 2
      app/views/logs/edit.html.erb
  7. 2
      app/views/schemes/show.html.erb
  8. 2
      app/views/users/show.html.erb
  9. 2
      spec/features/form/accessible_autocomplete_spec.rb
  10. 56
      spec/features/form/form_navigation_spec.rb
  11. 2
      spec/features/form/page_routing_spec.rb
  12. 22
      spec/features/lettings_log_spec.rb
  13. 22
      spec/features/sales_log_spec.rb
  14. 1
      spec/views/form/page_view_spec.rb

8
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

5
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

2
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 => "",
}) %>
<div class="govuk-grid-row">

14
app/views/form/page.html.erb

@ -1,7 +1,15 @@
<% content_for :title, @page.header.presence || @page.questions.first.header.html_safe %>
<% if accessed_from_duplicate_logs?(request.query_parameters["referrer"]) %>
<% content_for :before_content do %>
<%= govuk_back_link(href: send(@log.form.previous_page_redirect_path(@page, @log, current_user, params[:referrer]), @log)) %>
<%= 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 %>
<div data-controller="govukfrontend"></div>
@ -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) %>

2
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 %>

2
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) => "",
}) %>
<div class="govuk-grid-row">

2
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 %>

2
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 %>

2
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

56
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

2
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")

22
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

22
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

1
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)

Loading…
Cancel
Save