discourse/spec/system/page_objects/components/uppy_image_uploader.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module PageObjects
module Components
class UppyImageUploader < PageObjects::Components::Base
def initialize(element)
@element = element
end
def select_image(path)
attach_file(path) { @element.find("label.btn-default").click }
end
def select_image_with_keyboard(path)
label = @element.find("label.btn-default")
label.send_keys(:enter)
attach_file(path) { label.click }
end
DEV: Fix flaky spec for the /about admin config area (#27697) There's currently a race condition in the following spec: https://github.com/discourse/discourse/blob/65be7a7880ba0dc1a5cb403956fabd83aaa738d6/spec/system/admin_about_config_area_spec.rb#L70-L95 where the form can be saved before the image uploader field has finished uploading the selected image and causing the assertion at line 94 to fail with the following error: ``` Failure/Error: expect(SiteSetting.about_banner_image.sha1).to eq(Upload.generate_digest(image_file)) NoMethodError: undefined method `sha1' for nil [Screenshot Image]: /__w/discourse/discourse/tmp/capybara/failures_r_spec_example_groups_admin_about_config_area_page_the_general_settings_card_can_saves_its_fields_to_their_corresponding_site_settings_312.png ~~~~~~~ JS LOGS ~~~~~~~ http://localhost:31338/assets/vendor.js 15902:14 "WARNING: uppy needs a unique id, pass one in to the component implementing this mixin" ~~~~~ END JS LOGS ~~~~~ ./spec/system/admin_about_config_area_spec.rb:94:in `block (3 levels) in <main>' ./spec/rails_helper.rb:552:in `block (3 levels) in <top (required)>' ./spec/rails_helper.rb:552:in `block (2 levels) in <top (required)>' ./spec/rails_helper.rb:513:in `block (3 levels) in <top (required)>' ./spec/rails_helper.rb:503:in `block (2 levels) in <top (required)>' ./spec/rails_helper.rb:460:in `block (2 levels) in <top (required)>' ./vendor/bundle/ruby/3.3.0/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in `block (2 levels) in <top (required)>' ``` This PR fixes the problem by making the system test wait for the image to finish uploading (with 10 seconds timeout) before carrying out the rest of the system test.
2024-07-04 08:39:22 +08:00
def has_uploaded_image?
# if there's a delete button (.btn-danger), then there must be an
# uploaded image.
# allow up to 10 seconds for the upload to finish in case this is
# called immediately after selecting an image.
@element.has_css?(".btn-danger", wait: 10)
end
def remove_image
@element.find(".btn-danger").click
end
def remove_image_with_keyboard
delete_button = @element.find(".btn-danger")
delete_button.send_keys(:enter)
end
end
end
end