diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 246642c..4ba8106 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -25,9 +25,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase user end - def inject_button_to(after, *button_options) + def inject_button_to(inside, *button_options) button = button_to *button_options - evaluate_script("arguments[0].insertAdjacentHTML('beforeend', '#{button.html_safe}');", after) + inside.evaluate_script("this.insertAdjacentHTML('beforeend', arguments[0]);", + button.html_safe) end # Allow skipping interpolations when translating for testing purposes diff --git a/test/system/users_test.rb b/test/system/users_test.rb index 070c514..b012bf4 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -227,7 +227,8 @@ class UsersTest < ApplicationSystemTestCase within all(:xpath, "//tbody//tr[not(descendant::select)]").sample do |tr| user = User.find_by_email!(first(:link).text) - inject_button_to first('td:not(.link)'), "update status", user_path(user), method: :patch, + inject_button_to find('td', exact_text: user.status), "update status", + user_path(user), method: :patch, params: {user: {status: User.statuses.keys.sample}}, data: {turbo: false} click_on "update status" end @@ -237,8 +238,8 @@ class UsersTest < ApplicationSystemTestCase test 'update status forbidden for non admin' do sign_in user: users.reject(&:admin?).select(&:confirmed?).sample visit units_path - inject_button_to find('body'), "update status", user_path(User.all.sample), method: :patch, - params: {user: {status: User.statuses.keys.sample}} + inject_button_to find('body'), "update status", user_path(User.all.sample), + method: :patch, params: {user: {status: User.statuses.keys.sample}} click_on "update status" assert_text t('actioncontroller.exceptions.status.forbidden') end