Move range specs to non-selenium specific and support in rack driver
This commit is contained in:
parent
eedeb31052
commit
3d6e491382
|
@ -45,6 +45,7 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
|
|||
|
||||
if radio? then set_radio(value)
|
||||
elsif checkbox? then set_checkbox(value)
|
||||
elsif range? then set_range(value)
|
||||
elsif input_field? then set_input(value)
|
||||
elsif textarea? then native['_capybara_raw_value'] = value.to_s
|
||||
end
|
||||
|
@ -208,6 +209,14 @@ private
|
|||
end
|
||||
end
|
||||
|
||||
def set_range(value)
|
||||
min, max, step = (native['min'] || 0).to_f, (native['max'] || 100).to_f, (native['step'] || 1).to_f
|
||||
value = value.to_f
|
||||
value = value.clamp(min,max)
|
||||
value = ((value - min) / step).round * step + min
|
||||
native['value'] = value.clamp(min,max)
|
||||
end
|
||||
|
||||
def set_input(value) # rubocop:disable Naming/AccessorMethodName
|
||||
if text_or_password? && attribute_is_not_blank?(:maxlength)
|
||||
# Browser behavior for maxlength="0" is inconsistent, so we stick with
|
||||
|
@ -293,6 +302,10 @@ protected
|
|||
tag_name == 'textarea'
|
||||
end
|
||||
|
||||
def range?
|
||||
input_field? && type === 'range'
|
||||
end
|
||||
|
||||
OPTION_OWNER_XPATH = XPath.parent(:optgroup, :select, :datalist).to_s.freeze
|
||||
DISABLED_BY_FIELDSET_XPATH = XPath.generate do |x|
|
||||
x.parent(:fieldset)[
|
||||
|
|
|
@ -95,6 +95,26 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|||
expect(extract_results(@session)['html5_color']).to eq('#112233')
|
||||
end
|
||||
|
||||
describe 'with input[type="range"]' do
|
||||
it 'should set the range slider correctly' do
|
||||
@session.fill_in('form_age', with: 51)
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['age'].to_f).to eq 51
|
||||
end
|
||||
|
||||
it 'should set the range slider to valid values' do
|
||||
@session.fill_in('form_age', with: '37.6')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['age'].to_f).to eq 37.5
|
||||
end
|
||||
|
||||
it 'should respect the range slider limits' do
|
||||
@session.fill_in('form_age', with: '3')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['age'].to_f).to eq 13
|
||||
end
|
||||
end
|
||||
|
||||
it 'should fill in a field with a custom type' do
|
||||
@session.fill_in('Schmooo', with: 'Schmooo is the game')
|
||||
@session.click_button('awesome')
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
<p>
|
||||
<label for="form_age">Age</label>
|
||||
<input type="range" name="form[age]" value="18" min="13" max="100" id="form_age"/>
|
||||
<input type="range" name="form[age]" value="18" min="13" max="100" step="0.5" id="form_age"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -205,18 +205,6 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
|
|||
end
|
||||
end
|
||||
|
||||
describe '#fill_in with input[type="range"]' do
|
||||
before do
|
||||
session.visit('/form')
|
||||
end
|
||||
|
||||
it 'should set the range slider correctly' do
|
||||
session.fill_in('form_age', with: 51)
|
||||
session.click_button('awesome')
|
||||
expect(Integer(extract_results(session)['age'])).to eq 51
|
||||
end
|
||||
end
|
||||
|
||||
describe '#path' do
|
||||
it 'returns xpath' do
|
||||
# this is here because it is testing for an XPath that is specific to the algorithm used in the selenium driver
|
||||
|
|
Loading…
Reference in New Issue