diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 307e79f15..d2d6a6dd1 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -24,7 +24,7 @@ private if resource.need_two_factor_authentication?(request) user_two_factor_authentication_path else - params.dig("user", "start").present? ? lettings_logs_path : super + params.dig("user", "start").present? ? root_path : super end end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index e69de29bb..e691b3e5b 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -0,0 +1 @@ +
<%= "Welcome back, #{@current_user.name}" %>
diff --git a/spec/features/start_page_spec.rb b/spec/features/start_page_spec.rb index f5416a549..f7c008553 100644 --- a/spec/features/start_page_spec.rb +++ b/spec/features/start_page_spec.rb @@ -10,21 +10,23 @@ RSpec.describe "Start Page Features" do sign_in user end - it "takes you to logs" do + it "takes you to the home page" do visit("/") expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back") end end context "when the user is not signed in" do - it "takes you to sign in and then to logs" do + it "takes you to sign in and then to the home page" do visit("/") click_link("Start now") expect(page).to have_current_path("/account/sign-in?start=true") fill_in("user[email]", with: user.email) fill_in("user[password]", with: user.password) click_button("Sign in") - expect(page).to have_current_path("/lettings-logs") + expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back") end end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 04d5bd323..9e1aae35d 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -133,6 +133,7 @@ RSpec.describe "User Features" do fill_in("user[password]", with: "pAssword1") click_button("Sign in") expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back") 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 0da64c9ba..1dc930884 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -22,7 +22,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end @@ -46,11 +46,29 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end end + context "when the user is on the home page" do + let(:expected_navigation_items) do + [ + NavigationItemsHelper::NavigationItem.new("Home", "/", true), + NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), + NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), + NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), + NavigationItemsHelper::NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}/details", false), + NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false), + NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), + ] + end + + it "returns navigation items with the home item set as current" do + expect(primary_items("/", current_user)).to eq(expected_navigation_items) + end + end context "when the user is on the lettings logs page" do let(:expected_navigation_items) do @@ -66,7 +84,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end @@ -85,7 +103,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the sales logs item set as current" do expect(primary_items("/sales-logs", current_user)).to eq(expected_navigation_items) end end @@ -123,7 +141,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the organisation item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/details", current_user)).to eq(expected_navigation_items) end end @@ -142,7 +160,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with no items set as current" do expect(primary_items("/account", current_user)).to eq(expected_navigation_items) end end @@ -180,7 +198,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with Schemes item set as current" do + it "returns navigation items with schemes item set as current" do expect(primary_items("/schemes/1", current_user)).to eq(expected_navigation_items) end end @@ -210,7 +228,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end @@ -234,7 +252,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end @@ -244,6 +262,25 @@ RSpec.describe NavigationItemsHelper do context "when the user is a support user" do let(:current_user) { create(:user, :support) } + context "when the user is on the home page" do + let(:expected_navigation_items) do + [ + NavigationItemsHelper::NavigationItem.new("Home", "/", true), + NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), + NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), + NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), + NavigationItemsHelper::NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}/details", false), + NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false), + NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), + ] + end + + it "returns navigation items with the home item set as current" do + expect(primary_items("/", current_user)).to eq(expected_navigation_items) + end + end + context "when the user is on the lettings logs page" do let(:expected_navigation_items) do [ @@ -256,7 +293,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end @@ -273,7 +310,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the sales logs item set as current" do expect(primary_items("/sales-logs", current_user)).to eq(expected_navigation_items) end end @@ -307,7 +344,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the no items set as current" do expect(primary_items("/account", current_user)).to eq(expected_navigation_items) end end @@ -324,7 +361,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the schemes item set as current" do expect(primary_items("/schemes", current_user)).to eq(expected_navigation_items) end end @@ -365,7 +402,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with Schemes item set as current" do + it "returns navigation items with schemes item set as current" do expect(primary_items("/schemes/1", current_user)).to eq(expected_navigation_items) expect(scheme_items("/schemes/1", 1)).to eq(expected_scheme_items) end @@ -390,7 +427,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with Schemes item set as current" do + it "returns navigation items with schemes item set as current" do expect(primary_items("/schemes/1/locations", current_user)).to eq(expected_navigation_items) expect(scheme_items("/schemes/1/locations", 1)).to eq(expected_scheme_items) end @@ -422,7 +459,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the logs item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user)).to eq(expected_navigation_items) expect(secondary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user.organisation.id)).to eq(expected_secondary_navigation_items) end @@ -453,7 +490,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the logs item set as current" do + it "returns navigation items with the users item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user)).to eq(expected_navigation_items) expect(secondary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user.organisation.id)).to eq(expected_secondary_navigation_items) end @@ -515,7 +552,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the logs item set as current" do + it "returns navigation items with the organisation item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user)).to eq(expected_navigation_items) expect(secondary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user.organisation.id)).to eq(expected_secondary_navigation_items) end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index f335b61e6..59d4e27c9 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -77,6 +77,7 @@ RSpec.describe UsersController, type: :request do sign_in user get "/", headers:, params: {} expect(path).to include("/") + expect(page).to have_content("Welcome back") expected_link = "" expect(CGI.unescape_html(response.body)).to include(expected_link) end @@ -2027,6 +2028,7 @@ RSpec.describe UsersController, type: :request do it "routes user to the home page" do get "/", headers:, params: {} expect(path).to include("/") + expect(page).to have_content("Welcome back") expected_link = "" expect(CGI.unescape_html(response.body)).to include(expected_link) end