Skip to content

Commit

Permalink
Support time inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Antsiscool committed Jan 4, 2024
1 parent c5ff466 commit 85b71ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/capybara/cuprite/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions spec/features/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/support/views/with_js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
</p>
<p><input type="file" name="change_me_file" id="change_me_file"></p>
<p><input type="color" name="change_me_color" id="change_me_color"></p>
<p><input type="time" name="change_me_time" id="change_me_time"></p>
<p><input type="date" name="change_me_date" id="change_me_date"></p>
<p id="changes"></p>
<p id="changes_on_input"></p>
<p id="changes_on_keydown"></p>
Expand Down

0 comments on commit 85b71ef

Please sign in to comment.