Add react based test around rapid set

This commit is contained in:
Thomas Walpole 2020-04-04 14:41:18 -07:00
parent 2058fe16a5
commit 696f9d38a5
2 changed files with 25 additions and 11 deletions

View File

@ -279,9 +279,9 @@ private
send_keys(*clear, value)
else
driver.execute_script 'arguments[0].select()', self unless clear == :none
if rapid == true || (value.length > 30 && rapid != false)
if rapid == true || ((value.length > auto_rapid_set_length) && rapid != false)
send_keys(value[0..3])
driver.execute_script RAPID_SET_TEXT, self, value[4...-3]
driver.execute_script RAPID_SET_TEXT, self, value[0...-3]
send_keys(value[-3..-1])
else
send_keys(value)
@ -289,6 +289,10 @@ private
end
end
def auto_rapid_set_length
30
end
def perform_with_options(click_options, &block)
raise ArgumentError, 'A block must be provided' unless block
@ -531,9 +535,8 @@ private
JS
RAPID_SET_TEXT = <<~'JS'
(function(el, val) {
var value = el.value + val;
if (el.maxLength != -1){
(function(el, value) {
if (el.maxLength && el.maxLength != -1){
value = value.slice(0, el.maxLength);
}
el.value = value;

View File

@ -441,21 +441,32 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
context 'controlled components' do
it 'can set and clear a text field' do
skip "This test doesn't support older browsers" if ie?(session)
# session.visit 'https://reactjs.org/docs/forms.html'
# session.all(:css, 'h2#controlled-components ~ p a', text: 'Try it on CodePen')[0].click
# copied into local view
session.visit 'react'
# Not necessary when accessed locally
# session.within_frame(:css, 'iframe.result-iframe:not([src=""])', wait: 10) do
session.fill_in('Name:', with: 'abc')
session.accept_prompt 'A name was submitted: abc' do
session.click_button('Submit')
end
session.fill_in('Name:', with: '')
session.accept_prompt(/A name was submitted: $/) do
session.click_button('Submit')
end
# end
end
it 'works with rapid fill' do
skip "This test doesn't support older browsers" if ie?(session)
session.visit 'react'
long_string = (0...60).map { |i| ((i % 26) + 65).chr }.join
session.fill_in('Name:', with: long_string)
session.accept_prompt "A name was submitted: #{long_string}" do
session.click_button('Submit')
require 'byebug'
byebug
end
end
end
end