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