From 0d2932d1d966c1b34057b4b91bab1c75d05f1f76 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Thu, 7 Mar 2019 13:50:59 -0800 Subject: [PATCH] Add firefox date/time inputs being set via string tests --- lib/capybara/selenium/node.rb | 2 +- spec/selenium_spec_firefox.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index af1e0b26..ae0c9923 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -398,7 +398,7 @@ private end def to_date_str - value.to_date.strftime('%Y-%m-%d') + value.to_date.iso8601 end def timeable? diff --git a/spec/selenium_spec_firefox.rb b/spec/selenium_spec_firefox.rb index 5a2a031e..0234443f 100644 --- a/spec/selenium_spec_firefox.rb +++ b/spec/selenium_spec_firefox.rb @@ -73,6 +73,35 @@ RSpec.describe 'Capybara::Session with firefox' do # rubocop:disable RSpec/Multi include Capybara::SpecHelper include_examples 'Capybara::Session', TestSessions::SeleniumFirefox, :selenium_firefox include_examples Capybara::RSpecMatchers, TestSessions::SeleniumFirefox, :selenium_firefox + + describe 'filling in Firefox-specific date and time fields with keystrokes' do + let(:datetime) { Time.new(1983, 6, 19, 6, 30) } + let(:session) { TestSessions::SeleniumFirefox } + + before do + session.visit('/form') + end + + it 'should fill in a date input with a String' do + session.fill_in('form_date', with: datetime.to_date.iso8601) + session.click_button('awesome') + expect(Date.parse(extract_results(session)['date'])).to eq datetime.to_date + end + + it 'should fill in a time input with a String' do + session.fill_in('form_time', with: datetime.to_time.strftime('%T')) + session.click_button('awesome') + results = extract_results(session)['time'] + expect(Time.parse(results).strftime('%r')).to eq datetime.strftime('%r') + end + + it 'should fill in a datetime input with a String' do + # FF doesn't currently support datetime-local so this is really just a text input + session.fill_in('form_datetime', with: datetime.iso8601) + session.click_button('awesome') + expect(Time.parse(extract_results(session)['datetime'])).to eq datetime + end + end end RSpec.describe Capybara::Selenium::Driver do