Browse Source

CLDC-2939 Link to organisations from user pages (#2489)

* Link to organisations from user pages

* Fix test
pull/2500/head
kosiakkatrina 6 months ago committed by GitHub
parent
commit
905f869460
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      app/helpers/tab_nav_helper.rb
  2. 2
      app/views/users/show.html.erb
  3. 8
      spec/helpers/tab_nav_helper_spec.rb
  4. 11
      spec/requests/users_controller_spec.rb

3
app/helpers/tab_nav_helper.rb

@ -19,7 +19,8 @@ module TabNavHelper
end
def org_cell(user)
org_name = current_user.support? ? govuk_link_to(user.organisation.name, lettings_logs_organisation_path(user.organisation)) : user.organisation.name
role = "<span class=\"app-!-colour-muted\">#{user.role.to_s.humanize}</span>"
[user.organisation.name, role].join("\n")
[org_name, role].join("\n")
end
end

2
app/views/users/show.html.erb

@ -67,7 +67,7 @@
<%= summary_list.with_row do |row|
row.with_key { "Organisation" }
row.with_value { @user.organisation.name }
row.with_value { current_user.support? ? govuk_link_to(@user.organisation.name, lettings_logs_organisation_path(@user.organisation)) : @user.organisation.name }
row.with_action
end %>

8
spec/helpers/tab_nav_helper_spec.rb

@ -2,21 +2,21 @@ require "rails_helper"
RSpec.describe TabNavHelper do
let(:organisation) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.build(:user, organisation:) }
let(:current_user) { FactoryBot.build(:user, organisation:) }
let(:scheme) { FactoryBot.create(:scheme, service_name: "Some name") }
let(:location) { FactoryBot.create(:location, scheme:) }
describe "#user_cell" do
it "returns user link and email separated by a newline character" do
expected_html = "<a class=\"govuk-link\" href=\"/users\">#{user.name}</a>\n<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{user.email}</span>"
expect(user_cell(user)).to match(expected_html)
expected_html = "<a class=\"govuk-link\" href=\"/users\">#{current_user.name}</a>\n<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{current_user.email}</span>"
expect(user_cell(current_user)).to match(expected_html)
end
end
describe "#org_cell" do
it "returns the users org name and role separated by a newline character" do
expected_html = "DLUHC\n<span class=\"app-!-colour-muted\">Data provider</span>"
expect(org_cell(user)).to match(expected_html)
expect(org_cell(current_user)).to match(expected_html)
end
end

11
spec/requests/users_controller_spec.rb

@ -1188,7 +1188,7 @@ RSpec.describe UsersController, type: :request do
describe "#index" do
let!(:other_user) { create(:user, organisation: user.organisation, name: "User 2", email: "other@example.com") }
let!(:inactive_user) { create(:user, organisation: user.organisation, active: false, name: "User 3", email: "inactive@example.com", last_sign_in_at: Time.zone.local(2022, 10, 10)) }
let!(:other_org_user) { create(:user, name: "User 4", email: "otherorg@otherexample.com", organisation: create(:organisation, :without_dpc)) }
let!(:other_org_user) { create(:user, name: "User 4", email: "otherorg@otherexample.com", organisation: create(:organisation, :without_dpc, name: "Other name")) }
before do
get "/users", headers:, params: {}
@ -1201,6 +1201,11 @@ RSpec.describe UsersController, type: :request do
expect(page).to have_content(other_org_user.name)
end
it "links to user organisations" do
expect(page).to have_link(user.organisation.name, href: "/organisations/#{user.organisation.id}/lettings-logs", count: 3)
expect(page).to have_link(other_org_user.organisation.name, href: "/organisations/#{other_org_user.organisation.id}/lettings-logs", count: 1)
end
it "shows last logged in date for all users" do
expect(page).to have_content("10 October 2022")
end
@ -1432,6 +1437,10 @@ RSpec.describe UsersController, type: :request do
expect(page).to have_link("Change", text: "if a key contact")
end
it "links to user organisation" do
expect(page).to have_link(other_user.organisation.name, href: "/organisations/#{other_user.organisation.id}/lettings-logs")
end
it "does not show option to resend confirmation email" do
expect(page).not_to have_button("Resend invite link")
end

Loading…
Cancel
Save