mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 07:33:37 +08:00
b53df4d884
If we don't get a `videoWidth` back for a video don't try and generate a thumbnail for it. Also as part of this change I switched getImageData, the function throwing the error, to use video.videoWidth instead of canvas.width because it's very likely we were setting canvas.width too early before the width could be read. Now that we are reading the value inside of the setTimeout hopefully we will actually have a width. Just incase we don't detect a width we will now exit early instead of throwing an error. We only need to check for `0` and not null because the value is an integer and will always return a 0 if it can't be read. https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement/videoWidth See https://meta.discourse.org/t/322363
141 lines
4.6 KiB
Ruby
141 lines
4.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Uploading files in the composer", type: :system do
|
|
fab!(:current_user) { Fabricate(:user, refresh_auto_groups: true) }
|
|
|
|
let(:modal) { PageObjects::Modals::Base.new }
|
|
let(:composer) { PageObjects::Components::Composer.new }
|
|
let(:topic) { PageObjects::Pages::Topic.new }
|
|
let(:cdp) { PageObjects::CDP.new }
|
|
|
|
before { sign_in(current_user) }
|
|
|
|
it "uploads multiple files at once" do
|
|
visit "/new-topic"
|
|
expect(composer).to be_opened
|
|
|
|
file_path_1 = file_from_fixtures("logo.png", "images").path
|
|
file_path_2 = file_from_fixtures("logo.jpg", "images").path
|
|
attach_file([file_path_1, file_path_2]) { composer.click_toolbar_button("upload") }
|
|
|
|
expect(composer).to have_no_in_progress_uploads
|
|
expect(composer.preview).to have_css(".image-wrapper", count: 2)
|
|
end
|
|
|
|
it "allows cancelling uploads" do
|
|
visit "/new-topic"
|
|
expect(composer).to be_opened
|
|
|
|
file_path_1 = file_from_fixtures("huge.jpg", "images").path
|
|
cdp.with_slow_upload do
|
|
attach_file(file_path_1) { composer.click_toolbar_button("upload") }
|
|
expect(composer).to have_in_progress_uploads
|
|
find("#cancel-file-upload").click
|
|
|
|
expect(composer).to have_no_in_progress_uploads
|
|
expect(composer.preview).to have_no_css(".image-wrapper")
|
|
end
|
|
end
|
|
|
|
context "when video thumbnails are enabled" do
|
|
before do
|
|
SiteSetting.video_thumbnails_enabled = true
|
|
SiteSetting.authorized_extensions += "|mp4"
|
|
end
|
|
|
|
it "generates a topic preview thumbnail from the video" do
|
|
visit "/new-topic"
|
|
expect(composer).to be_opened
|
|
topic.fill_in_composer_title("Video upload test")
|
|
|
|
file_path_1 = file_from_fixtures("small.mp4", "media").path
|
|
attach_file(file_path_1) { composer.click_toolbar_button("upload") }
|
|
|
|
expect(composer).to have_no_in_progress_uploads
|
|
expect(composer.preview).to have_css(".onebox-placeholder-container")
|
|
|
|
composer.submit
|
|
|
|
expect(find("#topic-title")).to have_content("Video upload test")
|
|
expect(Topic.last.image_upload_id).to eq(Upload.last.id)
|
|
end
|
|
|
|
it "generates a thumbnail from the video" do
|
|
visit "/new-topic"
|
|
expect(composer).to be_opened
|
|
topic.fill_in_composer_title("Video upload test")
|
|
|
|
file_path_1 = file_from_fixtures("small.mp4", "media").path
|
|
attach_file(file_path_1) { composer.click_toolbar_button("upload") }
|
|
|
|
expect(composer).to have_no_in_progress_uploads
|
|
expect(composer.preview).to have_css(".onebox-placeholder-container")
|
|
|
|
expect(page).to have_css(
|
|
'.onebox-placeholder-container[style*="background-image"]',
|
|
wait: Capybara.default_max_wait_time,
|
|
)
|
|
|
|
composer.submit
|
|
|
|
expect(find("#topic-title")).to have_content("Video upload test")
|
|
|
|
selector = topic.post_by_number_selector(1)
|
|
|
|
expect(page).to have_css(selector)
|
|
within(selector) do
|
|
expect(page).to have_css(".video-placeholder-container[data-thumbnail-src]")
|
|
end
|
|
end
|
|
|
|
it "handles a video where dimensions can't be read gracefully" do
|
|
visit "/new-topic"
|
|
expect(composer).to be_opened
|
|
topic.fill_in_composer_title("Zero Width Video Test")
|
|
|
|
# Inject JavaScript to mock video dimensions
|
|
page.execute_script <<-JS
|
|
HTMLVideoElement.prototype.__defineGetter__('videoWidth', function() { return 0; });
|
|
HTMLVideoElement.prototype.__defineGetter__('videoHeight', function() { return 0; });
|
|
JS
|
|
|
|
file_path_1 = file_from_fixtures("small.mp4", "media").path
|
|
attach_file(file_path_1) { composer.click_toolbar_button("upload") }
|
|
|
|
expect(composer).to have_no_in_progress_uploads
|
|
expect(composer.preview).to have_css(".onebox-placeholder-container")
|
|
|
|
composer.submit
|
|
|
|
expect(find("#topic-title")).to have_content("Zero Width Video Test")
|
|
|
|
selector = topic.post_by_number_selector(1)
|
|
|
|
expect(page).to have_css(selector)
|
|
within(selector) do
|
|
expect(page).to have_no_css(".video-placeholder-container[data-thumbnail-src]")
|
|
end
|
|
end
|
|
|
|
it "shows video player in composer" do
|
|
SiteSetting.enable_diffhtml_preview = true
|
|
|
|
visit "/new-topic"
|
|
expect(composer).to be_opened
|
|
topic.fill_in_composer_title("Video upload test")
|
|
|
|
file_path_1 = file_from_fixtures("small.mp4", "media").path
|
|
attach_file(file_path_1) { composer.click_toolbar_button("upload") }
|
|
|
|
expect(composer).to have_no_in_progress_uploads
|
|
expect(composer.preview).to have_css(".video-container video")
|
|
|
|
expect(page).to have_css(
|
|
".video-container video source[src]",
|
|
visible: false,
|
|
wait: Capybara.default_max_wait_time,
|
|
)
|
|
end
|
|
end
|
|
end
|