]> git.openstreetmap.org Git - rails.git/blob - test/system/profile_image_change_test.rb
Fix eslint warning
[rails.git] / test / system / profile_image_change_test.rb
1 require "application_system_test_case"
2
3 class ProfileImageChangeTest < ApplicationSystemTestCase
4   test "can't change image when unauthorized" do
5     user = create(:user)
6
7     visit user_path(user)
8
9     within_content_heading do
10       assert_no_link "Change Image"
11     end
12
13     within_content_body do
14       assert_no_button "Edit Profile Details"
15       assert_no_link "Change Image"
16     end
17   end
18
19   test "can't change image of another user" do
20     user = create(:user)
21     another_user = create(:user)
22
23     sign_in_as(user)
24     visit user_path(another_user)
25
26     within_content_heading do
27       assert_no_link "Change Image"
28     end
29
30     within_content_body do
31       assert_no_button "Edit Profile Details"
32       assert_no_link "Change Image"
33     end
34   end
35
36   test "can add and remove image" do
37     user = create(:user)
38
39     sign_in_as(user)
40     visit user_path(user)
41
42     within_content_body do
43       click_on "Edit Profile Details"
44       click_on "Change Image"
45       assert_unchecked_field "Add an image"
46       assert_no_field "Keep the current image"
47       assert_no_field "Remove the current image"
48       assert_no_field "Replace the current image"
49
50       attach_file "Avatar", "test/gpx/fixtures/a.gif"
51
52       assert_checked_field "Add an image"
53
54       click_on "Update Profile"
55     end
56
57     assert_text "Profile image updated."
58
59     within_content_body do
60       click_on "Edit Profile Details"
61       click_on "Change Image"
62       assert_no_field "Add an image"
63       assert_checked_field "Keep the current image"
64       assert_unchecked_field "Remove the current image"
65       assert_unchecked_field "Replace the current image"
66
67       choose "Remove the current image"
68       click_on "Update Profile"
69     end
70
71     assert_text "Profile image updated."
72
73     within_content_body do
74       click_on "Edit Profile Details"
75       click_on "Change Image"
76       assert_unchecked_field "Add an image"
77       assert_no_field "Keep the current image"
78       assert_no_field "Remove the current image"
79       assert_no_field "Replace the current image"
80     end
81   end
82
83   test "can add image by clicking the placeholder image" do
84     user = create(:user)
85
86     sign_in_as(user)
87     visit user_path(user)
88
89     within_content_heading do
90       click_on "Change Image"
91     end
92
93     within_content_body do
94       assert_unchecked_field "Add an image"
95       assert_no_field "Keep the current image"
96       assert_no_field "Remove the current image"
97       assert_no_field "Replace the current image"
98
99       attach_file "Avatar", "test/gpx/fixtures/a.gif"
100
101       assert_checked_field "Add an image"
102
103       click_on "Update Profile"
104     end
105
106     assert_text "Profile image updated."
107
108     within_content_heading do
109       click_on "Change Image"
110     end
111
112     within_content_body do
113       assert_no_field "Add an image"
114       assert_checked_field "Keep the current image"
115       assert_unchecked_field "Remove the current image"
116       assert_unchecked_field "Replace the current image"
117     end
118   end
119 end