From c3bc7a6a055916e29de495d36e9873880fa0c18b Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Tue, 5 Nov 2024 15:35:53 +0300 Subject: [PATCH] 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. --- spec/system/page_objects/components/form_kit.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/system/page_objects/components/form_kit.rb b/spec/system/page_objects/components/form_kit.rb index 9ece6eec4f5..e5e0d87a3b5 100644 --- a/spec/system/page_objects/components/form_kit.rb +++ b/spec/system/page_objects/components/form_kit.rb @@ -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