From a411046650216799f201720e41df5ab512733af5 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 2 Jan 2024 14:02:10 +0000 Subject: [PATCH] feat: add blank homepage, update routing and tests --- app/controllers/start_controller.rb | 2 +- app/helpers/navigation_items_helper.rb | 6 +++++ app/views/home/index.html.erb | 0 spec/features/start_page_spec.rb | 2 +- spec/features/user_spec.rb | 2 +- spec/helpers/navigation_items_helper_spec.rb | 23 +++++++++++++++++++ .../auth/passwords_controller_spec.rb | 1 - spec/requests/maintenance_controller_spec.rb | 1 - spec/requests/users_controller_spec.rb | 10 ++++---- 9 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 app/views/home/index.html.erb diff --git a/app/controllers/start_controller.rb b/app/controllers/start_controller.rb index f2b96f557..318e7cace 100644 --- a/app/controllers/start_controller.rb +++ b/app/controllers/start_controller.rb @@ -1,7 +1,7 @@ class StartController < ApplicationController def index if current_user - redirect_to(lettings_logs_path) + render "home/index" end end diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 56954361d..18132a8a1 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -4,6 +4,7 @@ module NavigationItemsHelper def primary_items(path, current_user) if current_user.support? [ + NavigationItem.new("Home", root_path, home_current?(path)), NavigationItem.new("Organisations", organisations_path, organisations_current?(path)), NavigationItem.new("Users", users_path, users_current?(path)), NavigationItem.new("Lettings logs", lettings_logs_path, lettings_logs_current?(path)), @@ -12,6 +13,7 @@ module NavigationItemsHelper ].compact else [ + NavigationItem.new("Home", root_path, home_current?(path)), NavigationItem.new("Lettings logs", lettings_logs_path, lettings_logs_current?(path)), NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)), (NavigationItem.new("Schemes", schemes_path, non_support_supported_housing_schemes_current?(path)) if current_user.organisation.holds_own_stock? || current_user.organisation.stock_owners.present?), @@ -44,6 +46,10 @@ module NavigationItemsHelper private + def home_current?(path) + path == root_path + end + def lettings_logs_current?(path) path.starts_with?(lettings_logs_path) end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/features/start_page_spec.rb b/spec/features/start_page_spec.rb index 569ea4cfa..f5416a549 100644 --- a/spec/features/start_page_spec.rb +++ b/spec/features/start_page_spec.rb @@ -12,7 +12,7 @@ RSpec.describe "Start Page Features" do it "takes you to logs" do visit("/") - expect(page).to have_current_path("/lettings-logs") + expect(page).to have_current_path("/") end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 2da53970b..04d5bd323 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -132,7 +132,7 @@ RSpec.describe "User Features" do fill_in("user[email]", with: user.email) fill_in("user[password]", with: "pAssword1") click_button("Sign in") - expect(page).to have_current_path("/lettings-logs") + expect(page).to have_current_path("/") end it "tries to access account page, redirects to log in page" do diff --git a/spec/helpers/navigation_items_helper_spec.rb b/spec/helpers/navigation_items_helper_spec.rb index fcfbefc5b..0da64c9ba 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -12,6 +12,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), @@ -34,6 +35,7 @@ RSpec.describe NavigationItemsHelper do let(:stock_owner) { create(:organisation) } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -53,6 +55,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the lettings logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -71,6 +74,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the sales logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -89,6 +93,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the users page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -107,6 +112,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on their organisation details page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -125,6 +131,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the account page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -143,6 +150,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual user's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -161,6 +169,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual scheme's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true), @@ -191,6 +200,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), @@ -213,6 +223,7 @@ RSpec.describe NavigationItemsHelper do let(:stock_owner) { create(:organisation) } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -236,6 +247,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the lettings logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), @@ -252,6 +264,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the sales logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -268,6 +281,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the users page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -284,6 +298,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the account page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -300,6 +315,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the Schemes page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -316,6 +332,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual user's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -332,6 +349,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual scheme's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -356,6 +374,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the scheme locations page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -382,6 +401,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "lettings-logs" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -412,6 +432,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "users" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -442,6 +463,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "schemes" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -472,6 +494,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "details" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index 92c36608c..333985d9e 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/spec/requests/auth/passwords_controller_spec.rb @@ -67,7 +67,6 @@ RSpec.describe Auth::PasswordsController, type: :request do put "/account/password", params: update_password_params # Devise redirects once after re-sign in with new password and then root redirects as well. follow_redirect! - follow_redirect! expect(page).to have_css("div", class: "govuk-notification-banner__heading", text: message) end end diff --git a/spec/requests/maintenance_controller_spec.rb b/spec/requests/maintenance_controller_spec.rb index 4d7f8ab8c..39e587302 100644 --- a/spec/requests/maintenance_controller_spec.rb +++ b/spec/requests/maintenance_controller_spec.rb @@ -153,7 +153,6 @@ RSpec.describe MaintenanceController, type: :request do end it "the cookie banner is visible" do - follow_redirect! follow_redirect! expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.") end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 7f1b3ffef..f335b61e6 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -73,11 +73,10 @@ RSpec.describe UsersController, type: :request do end describe "title link" do - it "routes user to the /logs page" do + it "routes user to the home page" do sign_in user get "/", headers:, params: {} - follow_redirect! - expect(path).to include("/lettings-logs") + expect(path).to include("/") expected_link = "" expect(CGI.unescape_html(response.body)).to include(expected_link) end @@ -2025,10 +2024,9 @@ RSpec.describe UsersController, type: :request do sign_in user end - it "routes user to the /logs page" do + it "routes user to the home page" do get "/", headers:, params: {} - follow_redirect! - expect(path).to include("/lettings-logs") + expect(path).to include("/") expected_link = "" expect(CGI.unescape_html(response.body)).to include(expected_link) end