Browse Source

feat: add welcome message and thoroughly test routing

pull/2121/head
natdeanlewissoftwire 12 months ago
parent
commit
f2fa9de463
  1. 2
      app/controllers/auth/sessions_controller.rb
  2. 1
      app/views/home/index.html.erb
  3. 8
      spec/features/start_page_spec.rb
  4. 1
      spec/features/user_spec.rb
  5. 73
      spec/helpers/navigation_items_helper_spec.rb
  6. 2
      spec/requests/users_controller_spec.rb

2
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

1
app/views/home/index.html.erb

@ -0,0 +1 @@
<p class="govuk-body-l"><%= "Welcome back, #{@current_user.name}" %></p>

8
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

1
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

73
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

2
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 = "<a class=\"govuk-header__link govuk-header__link--homepage\" href=\"/\">"
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 = "<a class=\"govuk-header__link govuk-header__link--homepage\" href=\"/\">"
expect(CGI.unescape_html(response.body)).to include(expected_link)
end

Loading…
Cancel
Save