From 82a7510d185437dfb4a479c0e45c8f8da550344a Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Sun, 21 Apr 2024 13:23:37 +0100 Subject: [PATCH] Add first system tests --- test/application_system_test_case.rb | 4 +++- test/system/sign_ups_test.rb | 24 ++++++++++++++++++++++++ test/test_helper.rb | 4 ++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/system/sign_ups_test.rb diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index d7e6bba..15fb146 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,5 +1,7 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [ 1400, 1400 ] + driven_by :selenium, + using: :headless_firefox, + screen_size: [ 1400, 1400 ] end diff --git a/test/system/sign_ups_test.rb b/test/system/sign_ups_test.rb new file mode 100644 index 0000000..ab06856 --- /dev/null +++ b/test/system/sign_ups_test.rb @@ -0,0 +1,24 @@ +require "application_system_test_case" + +class SignUpsTest < ApplicationSystemTestCase + test "can sign up" do + visit new_user_url + fill_in attr_name(User, :username), with: "awesome_user" + fill_in attr_name(User, :first_name), with: "Awesome" + fill_in attr_name(User, :last_name), with: "User" + fill_in attr_name(User, :email), with: "awesome_user@example.com" + fill_in attr_name(User, :password), with: "password" + fill_in attr_name(User, :password_confirmation), with: "password" + click_on I18n.t("users.new.sign_up") + + assert_text I18n.t("users.create.success", name: "Awesome") + end + + test "can validate email address" do + user = users(:unverified) + token = user.generate_token_for(:email_verification) + + visit account_verification_url(id: token) + assert_text I18n.t("account_verifications.show.success") + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0e99c76..78276a1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,5 +17,9 @@ module ActiveSupport assert_includes record.errors[field.to_sym], "can't be blank" assert_raises { record.save(validate: false) } end + + def attr_name(klass, attr) + klass.human_attribute_name(attr) + end end end