From 3083051d790de08349d6c6fc2615c1c9d530ac23 Mon Sep 17 00:00:00 2001 From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com> Date: Tue, 21 Mar 2023 11:22:57 +0000 Subject: [PATCH] CLDC-2132 breadcrumbs logs link (#1427) * ensure the log review page has the correct links in the breadcrumbs * ensure check your answers pages have the correct links in the breadcrumbs * write feature tests to check that breadcrumbs have the correct links * utilise rails url helpers * when routing to a log show page, remove unnecessary :id call in url helper * slight tweak of methods used to get name of an instance of the class --- app/views/form/check_answers.html.erb | 6 ++-- app/views/form/review.html.erb | 22 ++++--------- spec/features/lettings_log_spec.rb | 26 +++++++++++++++ spec/features/sales_log_spec.rb | 46 ++++++++++++++++++++++++++- 4 files changed, 81 insertions(+), 19 deletions(-) diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 46a945017..3da071be5 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -1,9 +1,9 @@ <% content_for :title, "#{subsection.id.humanize} - Check your answers" %> <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { - "Logs" => "/logs", - "Log #{@log.id}" => send("#{@log.class.name.underscore}_path", @log), + "Logs" => url_for(@log.class), + "Log #{@log.id}" => url_for(@log), subsection.label => "", - }) %> +}) %>
diff --git a/app/views/form/review.html.erb b/app/views/form/review.html.erb index bc46c89d8..0e63875d9 100644 --- a/app/views/form/review.html.erb +++ b/app/views/form/review.html.erb @@ -1,18 +1,10 @@ -<% if @log.sales? %> - <% content_for :title, "Review sales log" %> - <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { - "Logs" => "/logs", - "Log #{@log.id}" => "/sales-logs/#{@log.id}", - "Review sales log" => "", - }) %> -<% else %> - <% content_for :title, "Review lettings log" %> - <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { - "Logs" => "/logs", - "Log #{@log.id}" => "/lettings-logs/#{@log.id}", - "Review lettings log" => "", - }) %> -<% end %> +<% class_name = @log.class.model_name.human.downcase %> +<% content_for :title, "Review #{class_name}" %> +<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { + "Logs" => url_for(@log.class), + "Log #{@log.id}" => url_for(@log), + "Review #{class_name}" => "", +}) %>
diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index 483924f0f..b8ff6885a 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -94,6 +94,32 @@ RSpec.describe "Lettings Log Features" do end end + context "when visiting a subsection check answers page" do + let(:lettings_log) { FactoryBot.create(:lettings_log, :about_completed) } + + 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 "Logs" + expect(breadcrumbs.first[:href]).to eq lettings_logs_path + expect(breadcrumbs[1].text).to eq "Log #{lettings_log.id}" + expect(breadcrumbs[1][:href]).to eq lettings_log_path(lettings_log) + end + end + + context "when reviewing a complete log" do + let(:lettings_log) { FactoryBot.create(:lettings_log, :completed) } + + 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 "Logs" + expect(breadcrumbs.first[:href]).to eq lettings_logs_path + expect(breadcrumbs[1].text).to eq "Log #{lettings_log.id}" + expect(breadcrumbs[1][:href]).to eq lettings_log_path(lettings_log) + end + end + context "when the owning organisation question isn't answered" do it "doesn't show the managing agent question" do visit("/lettings-logs") diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb index 04331d824..759b298f3 100644 --- a/spec/features/sales_log_spec.rb +++ b/spec/features/sales_log_spec.rb @@ -28,7 +28,7 @@ RSpec.describe "Sales Log Features" do click_link("Logs") end - it "navigates you to the lettings logs page" do + it "navigates you to the sales logs page" do expect(page).to have_current_path("/sales-logs") end end @@ -65,4 +65,48 @@ RSpec.describe "Sales Log Features" do end end end + + context "when signed in as a support user" do + let(:devise_notify_mailer) { DeviseNotifyMailer.new } + let(:notify_client) { instance_double(Notifications::Client) } + let(:otp) { "999111" } + let(:organisation) { FactoryBot.create(:organisation, name: "Big ORG") } + let(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now, organisation:) } + let(:sales_log) { FactoryBot.create(:sales_log, :completed) } + + before do + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) + allow(notify_client).to receive(:send_email).and_return(true) + allow(SecureRandom).to receive(:random_number).and_return(otp) + visit("/sales-logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: user.password) + click_button("Sign in") + fill_in("code", with: otp) + click_button("Submit") + end + + context "when visiting a subsection check answers page as a support user" 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 "Logs" + expect(breadcrumbs.first[:href]).to eq sales_logs_path + expect(breadcrumbs[1].text).to eq "Log #{sales_log.id}" + expect(breadcrumbs[1][:href]).to eq sales_log_path(sales_log.id) + end + end + + context "when reviewing a complete log" 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 "Logs" + expect(breadcrumbs.first[:href]).to eq sales_logs_path + expect(breadcrumbs[1].text).to eq "Log #{sales_log.id}" + expect(breadcrumbs[1][:href]).to eq sales_log_path(sales_log.id) + end + end + end end