From 85b71ef738bf731cc3c52566d70bd08afc5df806 Mon Sep 17 00:00:00 2001
From: Antony
Date: Tue, 26 Sep 2023 17:27:41 +1000
Subject: [PATCH] Support time inputs
---
lib/capybara/cuprite/node.rb | 3 +++
spec/features/session_spec.rb | 24 ++++++++++++++++++++++++
spec/support/views/with_js.erb | 2 ++
3 files changed, 29 insertions(+)
diff --git a/lib/capybara/cuprite/node.rb b/lib/capybara/cuprite/node.rb
index 3efab57c..70ece9a2 100644
--- a/lib/capybara/cuprite/node.rb
+++ b/lib/capybara/cuprite/node.rb
@@ -103,6 +103,9 @@ def set(value, options = {})
command(:select_file, files)
when "color"
node.evaluate("this.setAttribute('value', '#{value}')")
+ when "time"
+ value = value.strftime("%H:%M") if value.is_a?(Time)
+ node.evaluate("this.setAttribute('value', '#{value}')")
else
command(:set, value.to_s)
end
diff --git a/spec/features/session_spec.rb b/spec/features/session_spec.rb
index db0e640d..5816a6ed 100644
--- a/spec/features/session_spec.rb
+++ b/spec/features/session_spec.rb
@@ -243,6 +243,30 @@
element.set("#ddeeff")
expect(element.value).to eq("#ddeeff")
end
+
+ it "sets a value for a time input" do
+ element = @session.find(:css, "#change_me_time")
+ element.set("17:21")
+ expect(element.value).to eq("17:21")
+ end
+
+ it "sets a value for a time input with a time object" do
+ element = @session.find(:css, "#change_me_time")
+ element.set(Time.new(2023, 9, 26, 17, 21))
+ expect(element.value).to eq("17:21")
+ end
+
+ it "sets a value for a date input" do
+ element = @session.find(:css, "#change_me_date")
+ element.set("2023-09-26")
+ expect(element.value).to eq("2023-09-26")
+ end
+
+ it "sets a value for a date input with a date object" do
+ element = @session.find(:css, "#change_me_date")
+ element.set(Date.new(2023, 9, 26))
+ expect(element.value).to eq("2023-09-26")
+ end
end
describe "Node#visible" do
diff --git a/spec/support/views/with_js.erb b/spec/support/views/with_js.erb
index b837d7ba..0a5315e1 100644
--- a/spec/support/views/with_js.erb
+++ b/spec/support/views/with_js.erb
@@ -39,6 +39,8 @@