1 # frozen_string_literal: true
 
   3 require "application_system_test_case"
 
   5 class ProfileLinksChangeTest < ApplicationSystemTestCase
 
   6   test "can't change links when unauthorized" do
 
  11     within_content_body do
 
  12       assert_no_button "Edit Profile Details"
 
  13       assert_no_link "Edit Links"
 
  17   test "can't change links of another user" do
 
  19     another_user = create(:user)
 
  22     visit user_path(another_user)
 
  24     within_content_body do
 
  25       assert_no_button "Edit Profile Details"
 
  26       assert_no_link "Edit Links"
 
  30   test "can add and remove social link without submitting" do
 
  36     within_content_body do
 
  37       click_on "Edit Profile Details"
 
  40       assert_no_field "Social Profile Link 1"
 
  42       click_on "Add Social Link"
 
  44       assert_field "Social Profile Link 1"
 
  46       click_on "Remove Social Profile Link 1"
 
  48       assert_no_field "Social Profile Link 1"
 
  52   test "can add and remove social links" do
 
  58     within_content_body do
 
  59       click_on "Edit Profile Details"
 
  62       assert_no_field "Social Profile Link 1"
 
  64       click_on "Add Social Link"
 
  65       fill_in "Social Profile Link 1", :with => "https://example.com/user/fred"
 
  66       click_on "Update Profile"
 
  68       assert_link "example.com/user/fred"
 
  70       click_on "Edit Profile Details"
 
  72       click_on "Remove Social Profile Link 1"
 
  74       assert_no_field "Social Profile Link 1"
 
  76       click_on "Update Profile"
 
  78       assert_no_link "example.com/user/fred"
 
  82   test "can control social links using keyboard without submitting" do
 
  88     within_content_body do
 
  89       click_on "Edit Profile Details"
 
  91       click_on "Add Social Link"
 
  93       assert_field "Social Profile Link 1"
 
  95       send_keys :tab, :enter
 
  97       assert_no_field "Social Profile Link 1"
 
 101   test "can control social links using keyboard" do
 
 105     visit user_path(user)
 
 107     within_content_body do
 
 108       click_on "Edit Profile Details"
 
 109       click_on "Edit Links"
 
 110       click_on "Add Social Link"
 
 111       send_keys "https://example.com/user/typed"
 
 112       click_on "Update Profile"
 
 114       assert_link "example.com/user/typed"
 
 116       click_on "Edit Profile Details"
 
 117       click_on "Edit Links"
 
 118       find_field("Social Profile Link 1").click
 
 119       send_keys :tab, :enter
 
 121       assert_no_field "Social Profile Link 1"
 
 123       click_on "Update Profile"
 
 125       assert_no_link "example.com/user/typed"
 
 129   test "can add and remove multiple links" do
 
 133     visit user_path(user)
 
 135     within_content_body do
 
 136       click_on "Edit Profile Details"
 
 137       click_on "Edit Links"
 
 138       click_on "Add Social Link"
 
 139       fill_in "Social Profile Link 1", :with => "https://example.com/a"
 
 140       click_on "Add Social Link"
 
 141       fill_in "Social Profile Link 2", :with => "https://example.com/b"
 
 142       click_on "Add Social Link"
 
 143       fill_in "Social Profile Link 3", :with => "https://example.com/c"
 
 144       click_on "Update Profile"
 
 146       assert_link "example.com/a"
 
 147       assert_link "example.com/b"
 
 148       assert_link "example.com/c"
 
 150       click_on "Edit Profile Details"
 
 151       click_on "Edit Links"
 
 152       assert_field "Social Profile Link 1", :with => "https://example.com/a"
 
 153       assert_field "Social Profile Link 2", :with => "https://example.com/b"
 
 154       assert_field "Social Profile Link 3", :with => "https://example.com/c"
 
 156       click_on "Remove Social Profile Link 2"
 
 158       assert_field "Social Profile Link 1", :with => "https://example.com/a"
 
 159       assert_field "Social Profile Link 2", :with => "https://example.com/c"
 
 161       click_on "Add Social Link"
 
 162       fill_in "Social Profile Link 3", :with => "https://example.com/d"
 
 163       click_on "Update Profile"
 
 165       assert_link "example.com/a"
 
 166       assert_no_link "example.com/b"
 
 167       assert_link "example.com/c"
 
 168       assert_link "example.com/d"