|
1 | | -RSpec.describe "Admin Users Management", type: :system, js: true do |
| 1 | +RSpec.describe "Admin Users Management", type: :system, js: true, skip_seed: true do |
| 2 | + let(:organization) { create(:organization, skip_items: true) } |
| 3 | + let(:user) { create(:user, organization: organization) } |
| 4 | + let(:organization_admin) { create(:organization_admin, organization: organization) } |
| 5 | + let(:super_admin) { create(:super_admin, organization: organization) } |
| 6 | + |
2 | 7 | context "While signed in as an Administrative User (super admin)" do |
3 | 8 | before do |
4 | | - sign_in(@super_admin) |
| 9 | + sign_in(super_admin) |
5 | 10 | end |
6 | 11 |
|
7 | 12 | it "creates an user" do |
|
16 | 21 | end |
17 | 22 |
|
18 | 23 | it "edits an existing user" do |
| 24 | + create(:user, organization: organization, name: "AAlphabetically First User") |
| 25 | + |
19 | 26 | visit admin_users_path |
20 | 27 | click_link "Edit", match: :first |
21 | | - expect(page).to have_content("Update #{@organization_admin.name}") |
| 28 | + expect(page).to have_content("Update AAlphabetically First User") |
| 29 | + |
22 | 30 | fill_in "user_name", with: "TestUser" |
23 | | - select(@organization.name, from: 'user_organization_id') |
| 31 | + select(organization.name, from: 'user_organization_id') |
24 | 32 | click_on "Save" |
25 | 33 |
|
26 | 34 | expect(page.find(".alert")).to have_content "TestUser updated" |
27 | 35 |
|
28 | 36 | # Check if the organization role has been updated |
29 | 37 | tbody = find('#filterrific_results table tbody') |
30 | 38 | first_row = tbody.find('tr', text: 'TestUser') |
31 | | - expect(first_row).to have_text(@organization.name) |
| 39 | + expect(first_row).to have_text(organization.name) |
32 | 40 | end |
33 | 41 |
|
34 | 42 | it 'adds a role' do |
35 | | - user = FactoryBot.create(:user, name: 'User 123') |
36 | | - FactoryBot.create(:partner, name: 'Partner ABC') |
| 43 | + user = create(:user, name: 'User 123', organization: organization) |
| 44 | + create(:partner, name: 'Partner ABC', organization: organization) |
| 45 | + |
37 | 46 | visit edit_admin_user_path(user) |
38 | 47 | expect(page).to have_content('User 123') |
39 | 48 | select "Partner", from: "resource_type" |
|
48 | 57 | end |
49 | 58 |
|
50 | 59 | it "deletes an existing user" do |
| 60 | + create(:user, organization: organization, name: "AAlphabetically First User") |
| 61 | + |
51 | 62 | visit admin_users_path |
| 63 | + |
52 | 64 | page.accept_confirm do |
53 | 65 | click_link "Delete", match: :first |
54 | 66 | end |
|
57 | 69 | end |
58 | 70 |
|
59 | 71 | it "filters users by name" do |
60 | | - user_names = User.all.pluck(:name) |
| 72 | + create(:user, name: "UserA", organization: organization) |
| 73 | + create(:user, name: "UserB", organization: organization) |
| 74 | + create(:user, name: "UserC", organization: organization) |
| 75 | + |
| 76 | + user_names = ["UserA", "UserB", "UserC"] |
61 | 77 |
|
62 | 78 | visit admin_users_path |
| 79 | + |
63 | 80 | user_names.each do |name| |
64 | 81 | expect(page.find("table")).to have_content(name) |
65 | 82 | end |
66 | 83 |
|
67 | 84 | fill_in "filterrific_search_name", with: user_names.first |
| 85 | + |
68 | 86 | user_names[1..].each do |name| |
69 | 87 | expect(page.find("table")).not_to have_content(name) |
70 | 88 | end |
| 89 | + |
71 | 90 | expect(page.find("table")).to have_content(user_names.first) |
72 | 91 | end |
73 | 92 |
|
74 | 93 | it "filters users by email" do |
75 | | - user_email = @organization_admin.email |
| 94 | + user_email = organization_admin.email |
76 | 95 |
|
77 | 96 | visit admin_users_path |
78 | 97 | fill_in "filterrific_search_email", with: user_email |
|
0 commit comments