From bef778c2a43f30b829e25955a0f7171841ab789d Mon Sep 17 00:00:00 2001 From: Alicia Date: Fri, 29 Mar 2024 10:56:32 -0600 Subject: [PATCH 1/2] Fix user login --- app/views/users/sessions/new.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/sessions/new.html.slim b/app/views/users/sessions/new.html.slim index 33bb1e0fe..8bf338db6 100644 --- a/app/views/users/sessions/new.html.slim +++ b/app/views/users/sessions/new.html.slim @@ -16,7 +16,7 @@ = render "users/shared/links" - = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| + = form_for(resource, as: resource_name, url: session_path(resource_name), data: { turbo: false }) do |f| .c-form .c-form--group = f.label :email, "Email Address" From 3b189a7c98f8f4d168298576354198c0a84bfc8f Mon Sep 17 00:00:00 2001 From: Alicia Date: Fri, 29 Mar 2024 11:26:14 -0600 Subject: [PATCH 2/2] Add specs to user login and logout --- app/views/layouts/application.html.erb | 18 ++++----------- app/views/my_accounts/show.html.slim | 2 +- app/views/users/sessions/new.html.slim | 6 ++--- spec/system/user_login_system_spec.rb | 32 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 spec/system/user_login_system_spec.rb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d157ebd91..8f7a3f2bd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -3,23 +3,17 @@ Giving Connection - <% if request.fullpath.include? "/search" %> <% end %> - <%= yield(:head) %> - <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= favicon_link_tag %> - - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbo-track': 'reload' %> <%= stylesheet_pack_tag 'application', media: 'all', 'data-turbo-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbo-track': 'reload' %> @@ -29,11 +23,9 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','<%= Rails.application.credentials.dig(Rails.env.to_sym)[:google_tag_key] %>'); - - <%= render Navbar::Component.new(signed_in: user_signed_in?) %>
-
+
<%= render "shared/flash_messages" %>
- <%= yield %>
<%= render Footer::Component.new() %>
- - - + + diff --git a/app/views/my_accounts/show.html.slim b/app/views/my_accounts/show.html.slim index eddae25e2..7fddd7a01 100644 --- a/app/views/my_accounts/show.html.slim +++ b/app/views/my_accounts/show.html.slim @@ -56,7 +56,7 @@ div class="w-full h-full bg-white" div class="flex flex-row justify-center col-span-12" = form.submit "Update", class: "mx-auto py-2.5 px-5 text-sm font-bold text-white bg-blue-medium uppercase rounded-6px" div class="col-span-12 py-4 border-t border-gray-8" - = link_to "Log out", destroy_user_session_path, method: :delete, class:'text-xl font-bold text-blue-dark' + = link_to "Log out", destroy_user_session_path, method: :delete, class:'text-xl font-bold text-blue-dark', data: { turbo: false , test_id: "user_logout_link"} div class="hidden" data-tabs-target="panel" h4 class="px-6 text-xl text-grey-2 my-7" | My Saved Nonprofit Pages diff --git a/app/views/users/sessions/new.html.slim b/app/views/users/sessions/new.html.slim index 8bf338db6..4f58e7310 100644 --- a/app/views/users/sessions/new.html.slim +++ b/app/views/users/sessions/new.html.slim @@ -20,14 +20,14 @@ .c-form .c-form--group = f.label :email, "Email Address" - = f.email_field :email, autofocus: true, autocomplete: "email", class:"c-input" + = f.email_field :email, autofocus: true, autocomplete: "email", class:"c-input", data: { test_id: "user_login_email_input"} .c-form--group class="mb-3" = f.label :password - = f.password_field :password, autocomplete: "current-password", class:"c-input" + = f.password_field :password, autocomplete: "current-password", class:"c-input", data: { test_id: "user_login_password_input"} - if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' = link_to "Forgot your password?", new_password_path(resource_name), class:'font-bold' - if devise_mapping.confirmable? = link_to "Didn't receive confirmation instructions?", new_user_confirmation_path, class: "font-bold" .c-form--action class="mt-12" - = f.submit "Sign in", class:"c-button" + = f.submit "Sign in", class:"c-button", data: { test_id: "user_login_submit_btn"} \ No newline at end of file diff --git a/spec/system/user_login_system_spec.rb b/spec/system/user_login_system_spec.rb new file mode 100644 index 000000000..f07d6c4bd --- /dev/null +++ b/spec/system/user_login_system_spec.rb @@ -0,0 +1,32 @@ +require "system_helper" + +RSpec.describe "User Login", type: :system do + before do + @user = create(:user) + end + + it "can log in" do + visit signin_path + + find(:test_id, "user_login_email_input").fill_in with: @user.email + find(:test_id, "user_login_password_input").fill_in with: "wrong password" + click_button "user_login_submit_btn" + expect(page).to have_content("Invalid Email or password.") + + find(:test_id, "user_login_password_input").fill_in with: @user.password + click_button "user_login_submit_btn" + + expect(page).to have_content("Signed in successfully.") + end + + it "can log out" do + sign_in(@user) + visit my_account_path + + click_link "user_logout_link" + + within(:test_id, "flash_messages") do + expect(page).to have_text("Signed out successfully.") + end + end +end