From 1e0cb9007968d5d8302eb94717ae41932721b20c Mon Sep 17 00:00:00 2001 From: Connor Ferguson <68167430+cpfergus1@users.noreply.github.com> Date: Tue, 8 Nov 2022 06:31:22 -0700 Subject: [PATCH] Revert jQuery Changes to Xhr Var in Image Upload The was changed by mistake to `$.ajaxSetup.xhr()` and broke the image upload drop field. The error was missed because there were not any existing tests for the image drop field so the script was not being properly tested. Although `$.ajaxSetup().xhr()` could work in this situation, it will be fully reverted to original due to inability to find source of deprecation cited in commit that changed this function. (cherry picked from commit 58fcaae329ac06ff28ff93820e2d48bc11d55da4) --- .../spree/backend/models/image_upload.js | 2 +- .../admin/products/edit/images_spec.rb | 62 ++++++++++++------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/backend/app/assets/javascripts/spree/backend/models/image_upload.js b/backend/app/assets/javascripts/spree/backend/models/image_upload.js index 01e6721cb32..92a117de5f5 100644 --- a/backend/app/assets/javascripts/spree/backend/models/image_upload.js +++ b/backend/app/assets/javascripts/spree/backend/models/image_upload.js @@ -56,7 +56,7 @@ Spree.Models.ImageUpload = Backbone.Model.extend({ processData: false, // tell jQuery not to process the data contentType: false, // tell jQuery not to set contentType xhr: function () { - var xhr = $.ajaxSetup.xhr(); // Using default ajax builder but inputting upload settings + var xhr = $.ajaxSettings.xhr(); if (xhr.upload) { xhr.upload.onprogress = function (event) { if (event.lengthComputable) { diff --git a/backend/spec/features/admin/products/edit/images_spec.rb b/backend/spec/features/admin/products/edit/images_spec.rb index d885bacb37b..aadf2737931 100644 --- a/backend/spec/features/admin/products/edit/images_spec.rb +++ b/backend/spec/features/admin/products/edit/images_spec.rb @@ -40,33 +40,53 @@ end end - it "should allow an admin to upload and edit an image for a product" do - click_link "new_image_link" - within_fieldset 'New Image' do - attach_file('image_attachment', file_path) - end - click_button "Update" - expect(page).to have_content("successfully created!") - - # Icons are hidden, so hover to have them pop-up - find('tbody > tr').hover - within_row(1) do - within ".actions" do - click_icon :edit + context 'Using the new image link' do + it "should allow an admin to upload and edit an image for a product" do + click_link "new_image_link" + within_fieldset 'New Image' do + attach_file('image_attachment', file_path) + end + click_button "Update" + expect(page).to have_content("successfully created!") + + # Icons are hidden, so hover to have them pop-up + find('tbody > tr').hover + within_row(1) do + within ".actions" do + click_icon :edit + end + end + + fill_in "image_alt", with: "ruby on rails t-shirt" + click_button "Update" + + expect(page).to have_content "successfully updated!" + expect(page).to have_field "image[alt]", with: "ruby on rails t-shirt" + + find('tbody > tr').hover + accept_alert do + click_icon :trash end + expect(page).not_to have_field "image[alt]", with: "ruby on rails t-shirt" end + end - fill_in "image_alt", with: "ruby on rails t-shirt" - click_button "Update" + context 'Using the drag and drop upload window' do + it "should allow an admin to upload an image and edit an image for a product" do + page.find(".upload").drop(file_path) + find('tbody > tr').hover + within_row(1) do + within ".actions" do + click_icon :edit + end + end - expect(page).to have_content "successfully updated!" - expect(page).to have_field "image[alt]", with: "ruby on rails t-shirt" + fill_in "image_alt", with: "ruby on rails t-shirt" + click_button "Update" - find('tbody > tr').hover - accept_alert do - click_icon :trash + expect(page).to have_content "successfully updated!" + expect(page).to have_field "image[alt]", with: "ruby on rails t-shirt" end - expect(page).not_to have_field "image[alt]", with: "ruby on rails t-shirt" end context 'Using Active Storage',