1 # frozen_string_literal: true
 
   3 require "application_system_test_case"
 
   5 class ProfileImageChangeTest < ApplicationSystemTestCase
 
   6   test "can't change image when unauthorized" do
 
  11     within_content_heading do
 
  12       assert_no_link "Change Image"
 
  15     within_content_body do
 
  16       assert_no_button "Edit Profile Details"
 
  17       assert_no_link "Change Image"
 
  21   test "can't change image of another user" do
 
  23     another_user = create(:user)
 
  26     visit user_path(another_user)
 
  28     within_content_heading do
 
  29       assert_no_link "Change Image"
 
  32     within_content_body do
 
  33       assert_no_button "Edit Profile Details"
 
  34       assert_no_link "Change Image"
 
  38   test "can add and remove image" do
 
  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"
 
  52       attach_file "Avatar", "test/gpx/fixtures/a.gif"
 
  54       assert_checked_field "Add an image"
 
  56       click_on "Update Profile"
 
  59     assert_text "Profile image updated."
 
  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"
 
  69       choose "Remove the current image"
 
  70       click_on "Update Profile"
 
  73     assert_text "Profile image updated."
 
  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"
 
  85   test "can add image by clicking the placeholder image" do
 
  91     within_content_heading do
 
  92       click_on "Change Image"
 
  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"
 
 101       attach_file "Avatar", "test/gpx/fixtures/a.gif"
 
 103       assert_checked_field "Add an image"
 
 105       click_on "Update Profile"
 
 108     assert_text "Profile image updated."
 
 110     within_content_heading do
 
 111       click_on "Change Image"
 
 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"