]> git.openstreetmap.org Git - rails.git/blob - test/system/profile_links_change_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / system / profile_links_change_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
5 class ProfileLinksChangeTest < ApplicationSystemTestCase
6   test "can't change links when unauthorized" do
7     user = create(:user)
8
9     visit user_path(user)
10
11     within_content_body do
12       assert_no_button "Edit Profile Details"
13       assert_no_link "Edit Links"
14     end
15   end
16
17   test "can't change links of another user" do
18     user = create(:user)
19     another_user = create(:user)
20
21     sign_in_as(user)
22     visit user_path(another_user)
23
24     within_content_body do
25       assert_no_button "Edit Profile Details"
26       assert_no_link "Edit Links"
27     end
28   end
29
30   test "can add and remove social link without submitting" do
31     user = create(:user)
32
33     sign_in_as(user)
34     visit user_path(user)
35
36     within_content_body do
37       click_on "Edit Profile Details"
38       click_on "Edit Links"
39
40       assert_no_field "Social Profile Link 1"
41
42       click_on "Add Social Link"
43
44       assert_field "Social Profile Link 1"
45
46       click_on "Remove Social Profile Link 1"
47
48       assert_no_field "Social Profile Link 1"
49     end
50   end
51
52   test "can add and remove social links" do
53     user = create(:user)
54
55     sign_in_as(user)
56     visit user_path(user)
57
58     within_content_body do
59       click_on "Edit Profile Details"
60       click_on "Edit Links"
61
62       assert_no_field "Social Profile Link 1"
63
64       click_on "Add Social Link"
65       fill_in "Social Profile Link 1", :with => "https://example.com/user/fred"
66       click_on "Update Profile"
67
68       assert_link "example.com/user/fred"
69
70       click_on "Edit Profile Details"
71       click_on "Edit Links"
72       click_on "Remove Social Profile Link 1"
73
74       assert_no_field "Social Profile Link 1"
75
76       click_on "Update Profile"
77
78       assert_no_link "example.com/user/fred"
79     end
80   end
81
82   test "can control social links using keyboard without submitting" do
83     user = create(:user)
84
85     sign_in_as(user)
86     visit user_path(user)
87
88     within_content_body do
89       click_on "Edit Profile Details"
90       click_on "Edit Links"
91       click_on "Add Social Link"
92
93       assert_field "Social Profile Link 1"
94
95       send_keys :tab, :enter
96
97       assert_no_field "Social Profile Link 1"
98     end
99   end
100
101   test "can control social links using keyboard" do
102     user = create(:user)
103
104     sign_in_as(user)
105     visit user_path(user)
106
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"
113
114       assert_link "example.com/user/typed"
115
116       click_on "Edit Profile Details"
117       click_on "Edit Links"
118       find_field("Social Profile Link 1").click
119       send_keys :tab, :enter
120
121       assert_no_field "Social Profile Link 1"
122
123       click_on "Update Profile"
124
125       assert_no_link "example.com/user/typed"
126     end
127   end
128
129   test "can add and remove multiple links" do
130     user = create(:user)
131
132     sign_in_as(user)
133     visit user_path(user)
134
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"
145
146       assert_link "example.com/a"
147       assert_link "example.com/b"
148       assert_link "example.com/c"
149
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"
155
156       click_on "Remove Social Profile Link 2"
157
158       assert_field "Social Profile Link 1", :with => "https://example.com/a"
159       assert_field "Social Profile Link 2", :with => "https://example.com/c"
160
161       click_on "Add Social Link"
162       fill_in "Social Profile Link 3", :with => "https://example.com/d"
163       click_on "Update Profile"
164
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"
169     end
170   end
171 end