discourse/spec/system/s3_uploads_spec.rb

56 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
FIX: Video thumbnail uploads interfering with subsequent uploads (#23216) Short answer -- the problem is the video thumbnail generator & uploader code added a couple of months back in f144c64e139e41f176ea2ec3433a468fa49b955f. It was implemented as another Mixin which overrides `this._uppyInstance` when uploading the video thumbnail after the initial upload is complete, which means the composer's `this._uppyInstance` value is overridden, and it loses all of its preprocessors & upload code. This is generally a problem with the Mixin based architecture that I used for the Uppy code, which we need to remove at some point and refacotr. The most ideal thing to do here would be to convert this video thumbnail code into an Uppy [postprocessor](https://uppy.io/docs/uppy/#addpostprocessorfn) plugin, which runs on each upload after they are complete. I started looking into this, and the main hurdle here is adding support to tracking the progress of postprocessors to [ExtendableUploader](https://github.com/discourse/discourse/blob/cf42466dea75f1df97d580d2a5e6c221358137a8/app/assets/javascripts/discourse/app/mixins/extendable-uploader.js) so that is out of scope at this time. The fix here makes it so the ComposerVideoThumbnailUppy code is no longer a Mixin, but acts more like a normal class, a pattern which we have used in chat. I also clean up a lot of the thumbnail uploader code and remove some unnecessary things. Attempted to add a system spec, but video streaming does not work in Chrome for Testing at this time, and it is needed for the onloadedmetadata event.
2023-08-23 23:04:26 -05:00
describe "Uploading files in the composer to S3", type: :system do
fab!(:current_user) { Fabricate(:admin) }
let(:modal) { PageObjects::Modals::Base.new }
let(:composer) { PageObjects::Components::Composer.new }
let(:topic) { PageObjects::Pages::Topic.new }
describe "direct S3 uploads" do
describe "single part uploads" do
it "uploads custom avatars to S3" do
skip_unless_s3_system_specs_enabled!
setup_s3_system_test
sign_in(current_user)
visit "/my/preferences/account"
find("#edit-avatar").click
find("#uploaded-avatar").click
attach_file(File.absolute_path(file_from_fixtures("logo.jpg"))) do
find("#avatar-uploader").click
end
expect(page).to have_css(".avatar-uploader label[data-uploaded]")
modal.click_primary_button
expect(modal).to be_closed
expect(page).to have_css(
"#user-avatar-uploads[data-custom-avatar-upload-id]",
visible: false,
)
expect(current_user.reload.uploaded_avatar_id).to eq(
find("#user-avatar-uploads", visible: false)["data-custom-avatar-upload-id"].to_i,
)
end
end
describe "multipart uploads" do
it "uploads a file in the post composer" do
skip_unless_s3_system_specs_enabled!
setup_s3_system_test
sign_in(current_user)
topic.open_new_topic
file_path = file_from_fixtures("logo.png", "images").path
attach_file(file_path) { composer.click_toolbar_button("upload") }
expect(page).to have_no_css("#file-uploading")
expect(composer.preview).to have_css(".image-wrapper")
end
end
end
end