From c6e4dc68d0edc36a2c3b9c21336a8d3dba6d0de6 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 1 Jul 2025 19:23:57 +0300 Subject: [PATCH] Add "Edit Links" button to user profile --- app/views/users/show.html.erb | 4 +- config/locales/en.yml | 1 + test/system/profile_links_change_test.rb | 93 ++++++++++++++++-------- 3 files changed, 68 insertions(+), 30 deletions(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index ced7432ba..08cf28bcd 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -262,7 +262,9 @@ <% end %> - <%= render "sidebar_section", :present => !@user.social_links.empty? do %> + <%= render "sidebar_section", :present => !@user.social_links.empty?, + :edit_title => t(".edit_links"), + :edit_path => profile_links_path do %> <%= render "social_links/show", :social_links => @user.social_links %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index ed21b3ed4..d59dd3153 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3075,6 +3075,7 @@ en: report: Report this User edit_profile_details: Edit Profile Details edit_description: Edit Description + edit_links: Edit Links contributions: one: "%{count} contribution in the last year" other: "%{count} contributions in the last year" diff --git a/test/system/profile_links_change_test.rb b/test/system/profile_links_change_test.rb index 3305c4a3e..85ac71f1d 100644 --- a/test/system/profile_links_change_test.rb +++ b/test/system/profile_links_change_test.rb @@ -1,16 +1,40 @@ require "application_system_test_case" class ProfileLinksChangeTest < ApplicationSystemTestCase - def setup - stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404) + test "can't change links when unauthorized" do + user = create(:user) - @user = create(:user) - sign_in_as(@user) - visit profile_links_path + visit user_path(user) + + within_content_body do + assert_no_button "Edit Profile Details" + assert_no_link "Edit Links" + end + end + + test "can't change links of another user" do + user = create(:user) + another_user = create(:user) + + sign_in_as(user) + visit user_path(another_user) + + within_content_body do + assert_no_button "Edit Profile Details" + assert_no_link "Edit Links" + end end test "can add and remove social link without submitting" do + user = create(:user) + + sign_in_as(user) + visit user_path(user) + within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" + assert_no_field "Social Profile Link 1" click_on "Add Social Link" @@ -24,7 +48,15 @@ class ProfileLinksChangeTest < ApplicationSystemTestCase end test "can add and remove social links" do + user = create(:user) + + sign_in_as(user) + visit user_path(user) + within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" + assert_no_field "Social Profile Link 1" click_on "Add Social Link" @@ -33,14 +65,8 @@ class ProfileLinksChangeTest < ApplicationSystemTestCase assert_link "example.com/user/fred" - click_on "Edit Profile" - end - - within_content_heading do - click_on "Links" - end - - within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" click_on "Remove Social Profile Link 1" assert_no_field "Social Profile Link 1" @@ -52,7 +78,14 @@ class ProfileLinksChangeTest < ApplicationSystemTestCase end test "can control social links using keyboard without submitting" do + user = create(:user) + + sign_in_as(user) + visit user_path(user) + within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" click_on "Add Social Link" assert_field "Social Profile Link 1" @@ -64,21 +97,22 @@ class ProfileLinksChangeTest < ApplicationSystemTestCase end test "can control social links using keyboard" do + user = create(:user) + + sign_in_as(user) + visit user_path(user) + within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" click_on "Add Social Link" send_keys "https://example.com/user/typed" click_on "Update Profile" assert_link "example.com/user/typed" - click_on "Edit Profile" - end - - within_content_heading do - click_on "Links" - end - - within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" find_field("Social Profile Link 1").click send_keys :tab, :enter @@ -91,7 +125,14 @@ class ProfileLinksChangeTest < ApplicationSystemTestCase end test "can add and remove multiple links" do + user = create(:user) + + sign_in_as(user) + visit user_path(user) + within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" click_on "Add Social Link" fill_in "Social Profile Link 1", :with => "https://example.com/a" click_on "Add Social Link" @@ -104,14 +145,8 @@ class ProfileLinksChangeTest < ApplicationSystemTestCase assert_link "example.com/b" assert_link "example.com/c" - click_on "Edit Profile" - end - - within_content_heading do - click_on "Links" - end - - within_content_body do + click_on "Edit Profile Details" + click_on "Edit Links" assert_field "Social Profile Link 1", :with => "https://example.com/a" assert_field "Social Profile Link 2", :with => "https://example.com/b" assert_field "Social Profile Link 3", :with => "https://example.com/c" -- 2.39.5