Skip to content

Commit

Permalink
Extract some methods in Capybara test
Browse files Browse the repository at this point in the history
In my previous commit, I introduced some pretty unreadable assertions
into this test. This is an attempt to improve the situation, but
I reckon it could still be much better
  • Loading branch information
mike29736 committed Sep 6, 2023
1 parent 0637a92 commit 3d4fa47
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/integration/manage_api_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,15 @@ class ManageApiUsersTest < ActionDispatch::IntegrationTest

click_link @api_user.name

within "table#editable-permissions" do
# The existence of the <tr> indicates that the API User has "singin"
# permission for Whitehall
assert has_selector?("tr", text: "Whitehall")
end
assert has_select?("Permissions for Whitehall", selected: ["Managing Editor"])
assert_has_signin_permission_for("Whitehall")
assert_has_other_permissions("Whitehall", ["Managing Editor"])

unselect "Managing Editor", from: "Permissions for Whitehall"
click_button "Update API user"

click_link @api_user.name

within "table#editable-permissions" do
# The existence of the <tr> indicates that the API User has "singin"
# permission for Whitehall
assert has_selector?("tr", text: "Whitehall")
end
assert_has_signin_permission_for("Whitehall")

click_link "Account access log"
assert page.has_text?("Access token generated for Whitehall by #{@superadmin.name}")
Expand Down Expand Up @@ -121,4 +113,16 @@ class ManageApiUsersTest < ActionDispatch::IntegrationTest
assert page.has_selector?(".alert-success", text: "#{@api_user.email} is now active.")
end
end

def assert_has_signin_permission_for(application_name)
within "table#editable-permissions" do
# The existence of the <tr> indicates that the API User has "singin"
# permission for the application
assert has_selector?("tr", text: application_name)
end
end

def assert_has_other_permissions(application_name, permission_names)
assert has_select?("Permissions for #{application_name}", selected: permission_names)
end
end

0 comments on commit 3d4fa47

Please sign in to comment.