Browse Source

Remove users tab for data providers

pull/138/head
baarkerlounger 4 years ago
parent
commit
8c83bb7a7c
  1. 10
      app/helpers/tab_nav_helper.rb
  2. 7
      app/views/layouts/organisations.html.erb
  3. 62
      spec/features/organisation_spec.rb
  4. 40
      spec/helpers/tab_nav_helper_spec.rb
  5. 19
      spec/helpers/user_table_helper_spec.rb

10
app/helpers/user_table_helper.rb → app/helpers/tab_nav_helper.rb

@ -1,4 +1,4 @@
module UserTableHelper
module TabNavHelper
include GovukLinkHelper
def user_cell(user)
@ -9,4 +9,12 @@ module UserTableHelper
role = "<span class='app-!-colour-muted'>#{user.role.to_s.humanize}</span>"
[user.organisation.name, role].join("\n")
end
def tab_items(user)
items = [{ name: t("Details"), url: details_organisation_path(user.organisation) }]
if user.data_coordinator?
items << { name: t("Users"), url: users_organisation_path(user.organisation) }
end
items
end
end

7
app/views/layouts/organisations.html.erb

@ -3,10 +3,9 @@
Your organisation
</h1>
<%= render TabNavigationComponent.new(items: [
{ name: t('Details'), url: details_organisation_path(@organisation) },
{ name: t('Users'), url: users_organisation_path(@organisation) },
]) %>
<% items = tab_items(current_user) %>
<%= render TabNavigationComponent.new(items: items) %>
<h2 class="govuk-visually-hidden"><%= content_for(:tab_title) %></h2>

62
spec/features/organisation_spec.rb

@ -3,7 +3,6 @@ require_relative "form/helpers"
RSpec.describe "User Features" do
include Helpers
let!(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation }
let(:org_id) { organisation.id }
@ -11,33 +10,50 @@ RSpec.describe "User Features" do
sign_in user
end
context "Organisation page" do
it "default to organisation details" do
visit("/case-logs")
click_link("Your organisation")
expect(page).to have_content(user.organisation.name)
context "User is a data coordinator" do
let!(:user) { FactoryBot.create(:user, :data_coordinator) }
context "Organisation page" do
it "defaults to organisation details" do
visit("/case-logs")
click_link("Your organisation")
expect(page).to have_content(user.organisation.name)
end
it "can switch tabs" do
visit("/organisations/#{org_id}")
click_link("Users")
expect(page).to have_current_path("/organisations/#{org_id}/users")
click_link("Details")
expect(page).to have_current_path("/organisations/#{org_id}/details")
end
end
it "can switch tabs" do
visit("/organisations/#{org_id}")
click_link("Users")
expect(page).to have_current_path("/organisations/#{org_id}/users")
click_link("Details")
expect(page).to have_current_path("/organisations/#{org_id}/details")
context "Organisation users" do
it "users can be added" do
visit("/organisations/#{org_id}")
click_link("Users")
click_link("Invite user")
expect(page).to have_current_path("/users/new")
expect(page).to have_content("Invite user to submit CORE data")
fill_in("user[name]", with: "New User")
fill_in("user[email]", with: "new_user@example.com")
expect { click_button("Continue") }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(page).to have_current_path("/organisations/#{org_id}/users")
end
end
end
context "Organisation users" do
it "users can be added" do
visit("/organisations/#{org_id}")
click_link("Users")
click_link("Invite user")
expect(page).to have_current_path("/users/new")
expect(page).to have_content("Invite user to submit CORE data")
fill_in("user[name]", with: "New User")
fill_in("user[email]", with: "new_user@example.com")
expect { click_button("Continue") }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(page).to have_current_path("/organisations/#{org_id}/users")
context "User is a data provider" do
let!(:user) { FactoryBot.create(:user) }
context "Organisation page" do
it "can only see the details tab" do
visit("/case-logs")
click_link("Your organisation")
expect(page).to have_current_path("/organisations/#{org_id}/details")
expect(page).to have_no_link("Users")
end
end
end
end

40
spec/helpers/tab_nav_helper_spec.rb

@ -0,0 +1,40 @@
require "rails_helper"
RSpec.describe TabNavHelper do
let(:organisation) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.build(:user, organisation: organisation) }
describe "#user_cell" do
it "returns user link and email separated by a newline character" do
expected_html = "<a class=\"govuk-link\" href=\"/users\">Danny Rojas</a>\n#{user.email}"
expect(user_cell(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)
end
end
describe "#tab_items" do
context "user is a data_coordinator" do
let(:user) { FactoryBot.build(:user, :data_coordinator, organisation: organisation) }
it "returns details and user tabs" do
result = tab_items(user).map { |i| i[:name] }
expect(result.count).to eq(2)
expect(result.first).to match("Details")
expect(result.second).to match("Users")
end
end
context "user is a data_provider" do
it "returns details tab only" do
result = tab_items(user).map { |i| i[:name] }
expect(result.count).to eq(1)
expect(result.first).to match("Details")
end
end
end
end

19
spec/helpers/user_table_helper_spec.rb

@ -1,19 +0,0 @@
require "rails_helper"
RSpec.describe UserTableHelper do
let(:user) { FactoryBot.build(:user) }
describe "#user_cell" do
it "returns user link and email separated by a newline character" do
expected_html = "<a class=\"govuk-link\" href=\"/users\">Danny Rojas</a>\n#{user.email}"
expect(user_cell(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)
end
end
end
Loading…
Cancel
Save