]> git.openstreetmap.org Git - rails.git/blob - test/system/profile_image_change_test.rb
Add "Change Image" button to user profile
[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_body do
10       assert_no_button "Edit Profile Details"
11       assert_no_link "Change Image"
12     end
13   end
14
15   test "can't change image of another user" do
16     user = create(:user)
17     another_user = create(:user)
18
19     sign_in_as(user)
20     visit user_path(another_user)
21
22     within_content_body do
23       assert_no_button "Edit Profile Details"
24       assert_no_link "Change Image"
25     end
26   end
27
28   test "can add and remove image" do
29     user = create(:user)
30
31     sign_in_as(user)
32     visit user_path(user)
33
34     within_content_body do
35       click_on "Edit Profile Details"
36       click_on "Change Image"
37       assert_unchecked_field "Add an image"
38       assert_no_field "Keep the current image"
39       assert_no_field "Remove the current image"
40       assert_no_field "Replace the current image"
41
42       attach_file "Avatar", "test/gpx/fixtures/a.gif"
43
44       assert_checked_field "Add an image"
45
46       click_on "Update Profile"
47     end
48
49     assert_text "Profile image updated."
50
51     within_content_body do
52       click_on "Edit Profile Details"
53       click_on "Change Image"
54       assert_no_field "Add an image"
55       assert_checked_field "Keep the current image"
56       assert_unchecked_field "Remove the current image"
57       assert_unchecked_field "Replace the current image"
58
59       choose "Remove the current image"
60       click_on "Update Profile"
61     end
62
63     assert_text "Profile image updated."
64
65     within_content_body do
66       click_on "Edit Profile Details"
67       click_on "Change Image"
68       assert_unchecked_field "Add an image"
69       assert_no_field "Keep the current image"
70       assert_no_field "Remove the current image"
71       assert_no_field "Replace the current image"
72     end
73   end
74 end