mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 20:36:39 +08:00
DEV: Add support for image fields in FormKit PageObject (#29589)
This commit adds an API `upload_image` to `FormKitField` page object for setting an image file on an `Image` field in FormKit. Usage is like this: ```ruby form.field("image_field").upload_image(image_path) ``` The `value` API also now supports `Image` fields; it returns an `Upload` record if the field has an uploaded image.
This commit is contained in:
parent
a553c9ea0c
commit
c3bc7a6a05
|
@ -44,6 +44,10 @@ module PageObjects
|
|||
component.find("select").value
|
||||
when "composer"
|
||||
component.find("textarea").value
|
||||
when "image"
|
||||
url = component.find(".uploaded-image-preview a.lightbox", wait: 10)[:href]
|
||||
sha1 = url.match(/(\h{40})/).captures.first
|
||||
Upload.find_by(sha1:)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -152,7 +156,17 @@ module PageObjects
|
|||
if control_type == "question"
|
||||
component.find(".form-kit__control-radio[value='false']").click
|
||||
else
|
||||
raise "'accept' is not supported for control type: #{control_type}"
|
||||
raise "'refuse' is not supported for control type: #{control_type}"
|
||||
end
|
||||
end
|
||||
|
||||
def upload_image(image_path)
|
||||
if control_type == "image"
|
||||
attach_file(image_path) do
|
||||
component.find(".image-upload-controls .btn.btn-default").click
|
||||
end
|
||||
else
|
||||
raise "'upload_image' is not supported for control type: #{control_type}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user