From 1ba7d294418fc376990ecb6187637dc12b140a03 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 22 Feb 2026 00:55:21 +0100 Subject: [PATCH] Update tests to match labeled form changes --- test/application_system_test_case.rb | 12 +++++++++--- test/system/users_test.rb | 24 +++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 7d868a6..03617d3 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,7 +1,6 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - extend ActionView::Helpers::TranslationHelper include ActionView::Helpers::UrlHelper # NOTE: geckodriver installed with Firefox, ignore incompatibility warning @@ -19,8 +18,8 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase def sign_in(user: users.select(&:confirmed?).sample, password: randomize_user_password!(user)) visit new_user_session_url - fill_in User.human_attribute_name(:email).capitalize, with: user.email - fill_in User.human_attribute_name(:password).capitalize, with: password + fill_in User.human_attribute_name(:email), with: user.email + fill_in User.human_attribute_name(:password), with: password click_on t(:sign_in) user end @@ -30,6 +29,13 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase evaluate_script("arguments[0].insertAdjacentHTML('beforeend', '#{button.html_safe}');", after) end + # Allow skipping interpolations when translating for testing purposes + INTERPOLATION_PATTERNS = Regexp.union(I18n.config.interpolation_patterns) + def translate(key, **options) + options.empty? ? super.split(INTERPOLATION_PATTERNS, 2).first : super + end + alias :t :translate + #def assert_stale(element) # assert_raises(Selenium::WebDriver::Error::StaleElementReferenceError) { element.tag_name } #end diff --git a/test/system/users_test.rb b/test/system/users_test.rb index d7b3dc9..edefe81 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -6,15 +6,21 @@ class UsersTest < ApplicationSystemTestCase end test "sign in" do + visit new_user_session_path + assert find_link(href: new_user_session_path)[:disabled] + sign_in assert_no_current_path new_user_session_path - assert_text t("devise.sessions.signed_in") + assert_text t('devise.sessions.signed_in') end - test "sign in fails with invalid password" do + test 'sign in fails with invalid password' do sign_in password: random_password assert_current_path new_user_session_path - assert_text t("devise.failure.invalid", authentication_keys: User.human_attribute_name(:email)) + assert_text t('devise.failure.not_found_in_database', + authentication_keys: User.human_attribute_name(:email)) + assert find_link(href: new_user_session_path)[:disabled] + assert_not_empty find_field(User.human_attribute_name(:email)).value end test "sign out" do @@ -29,7 +35,7 @@ class UsersTest < ApplicationSystemTestCase visit new_user_session_url click_on t(:recover_password) - fill_in User.human_attribute_name(:email).capitalize, + fill_in User.human_attribute_name(:email), with: users.select(&:confirmed?).sample.email assert_emails 1 do click_on t(:recover_password) @@ -42,8 +48,8 @@ class UsersTest < ApplicationSystemTestCase visit Capybara.string(mail.body.to_s).find_link("Change my password")[:href] end new_password = random_password - fill_in t("users.passwords.edit.new_password"), with: new_password - fill_in t("users.passwords.edit.password_confirmation"), with: new_password + fill_in t("users.passwords.edit.password_html"), with: new_password + fill_in t("helpers.label.user.password_confirmation"), with: new_password assert_emails 1 do click_on t("users.passwords.edit.update_password") # Wait until redirected to make sure async request has been processed @@ -56,9 +62,9 @@ class UsersTest < ApplicationSystemTestCase visit new_user_session_url click_on t(:register) - fill_in User.human_attribute_name(:email).capitalize, with: random_email + fill_in User.human_attribute_name(:email), with: random_email password = random_password - fill_in User.human_attribute_name(:password).capitalize, with: password + fill_in User.human_attribute_name(:password), with: password fill_in t("users.registrations.new.password_confirmation"), with: password assert_difference ->{User.count}, 1 do assert_emails 1 do @@ -82,7 +88,7 @@ class UsersTest < ApplicationSystemTestCase click_on t(:register) click_on t(:resend_confirmation) - fill_in User.human_attribute_name(:email).capitalize, + fill_in User.human_attribute_name(:email), with: users.reject(&:confirmed?).sample.email assert_emails 1 do click_on t(:resend_confirmation)