Skip to content

Commit

Permalink
Add JS-enabled integration tests for /users page
Browse files Browse the repository at this point in the history
The equivalent non-JS functionality is already being tested in
controller and unit tests. These additional happy path tests should give
us confidence that the JavaScript functionality continues to work as
expected.
  • Loading branch information
chrisroos committed Sep 12, 2023
1 parent e22212c commit 201e2b7
Showing 1 changed file with 84 additions and 10 deletions.
94 changes: 84 additions & 10 deletions test/integration/admin_user_index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class AdminUserIndexTest < ActionDispatch::IntegrationTest
context "logged in as an admin" do
setup do
use_javascript_driver

current_time = Time.zone.now
Timecop.freeze(current_time)

Expand All @@ -13,27 +15,99 @@ class AdminUserIndexTest < ActionDispatch::IntegrationTest
org1 = create(:organisation, name: "Org 1")
org2 = create(:organisation, name: "Org 2")

create(:user, name: "Aardvark", email: "aardvark@example.com", current_sign_in_at: current_time - 5.minutes)
create(:two_step_enabled_user, name: "Abbey", email: "abbey@example.com")
create(:user, name: "Abbot", email: "mr_ab@example.com")
create(:user, name: "Bert", email: "bbbert@example.com")
create(:user, name: "Ed", email: "ed@example.com", organisation: org1)
create(:user, name: "Eddie", email: "eddie_bb@example.com")
create(:two_step_exempted_user, name: "Ernie", email: "ernie@example.com", organisation: org2)
create(:suspended_user, name: "Suspended McFee", email: "suspenders@example.com")
@aardvark = create(:user, name: "Aardvark", email: "aardvark@example.com", current_sign_in_at: current_time - 5.minutes)
@abbey = create(:two_step_enabled_user, name: "Abbey", email: "abbey@example.com")
@abbot = create(:user, name: "Abbot", email: "mr_ab@example.com")
@bert = create(:user, name: "Bert", email: "bbbert@example.com")
@ed = create(:user, name: "Ed", email: "ed@example.com", organisation: org1)
@eddie = create(:user, name: "Eddie", email: "eddie_bb@example.com")
@ernie = create(:two_step_exempted_user, name: "Ernie", email: "ernie@example.com", organisation: org2)
@suspended_mcfee = create(:suspended_user, name: "Suspended McFee", email: "suspenders@example.com")

application = create(:application, name: "App name")
create(:supported_permission, application:, name: "App permission")
@aardvark.grant_application_signin_permission(application)
@bert.grant_application_permission(application, "App permission")

visit "/users"
end

teardown do
Timecop.return
end

should "display the 2SV enrollment status for users" do
visit "/users"

within "table" do
assert has_css?("td", text: "Enabled", count: 1)
assert has_css?("td", text: "Not set up", count: 7)
end
end

should "list all users" do
assert_results @admin, @aardvark, @abbey, @abbot, @bert, @ed, @eddie, @ernie, @suspended_mcfee
end

should "filter users by search string" do
fill_in "Search", with: "bb"
click_on "Search"

assert_results @abbey, @abbot, @bert, @eddie
end

should "filter users by status" do
check "Suspended", allow_label_click: true

assert_results @suspended_mcfee
end

should "filter users by 2sv status" do
click_on "2SV Status"

check "Exempted", allow_label_click: true
assert_results @ernie

check "Enable", allow_label_click: true
assert_results @ernie, @abbey
end

should "filter users by role" do
click_on "Role"

check "Admin", allow_label_click: true
assert_results @admin
end

should "filter users by organisation" do
click_on "Organisation"

check "Org 1", allow_label_click: true
assert_results @ed

check "Org 2", allow_label_click: true
assert_results @ed, @ernie
end

should "filter users by permission" do
click_on "Permissions"

check "App name signin", allow_label_click: true
assert_results @aardvark

check "App name App permission", allow_label_click: true
assert_results @aardvark, @bert
end
end

private

def assert_results(*users)
expected_table_caption = [users.count, "user".pluralize(users.count)].join(" ")

table = find("table caption", text: expected_table_caption).ancestor(:table)
assert table.has_css?("tbody tr", count: users.count)

users.each do |user|
assert table.has_content?(user.name)
end
end
end

0 comments on commit 201e2b7

Please sign in to comment.