Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add support for image fields in FormKit PageObject (#29589)

Osama Sayeghc3bc7a6a0559
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