Sha256: 9740cf86e61cd3fb1cd0a8b3dc350b3bb508069de9027f883a9a23f578898276

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

module Spree
  module Backend
    module TestingSupport
      module CapybaraUtils
        def click_icon(type)
          first(".icon-#{type}").click
        end

        def within_row(num, &block)
          if RSpec.current_example.metadata[:js]
            within("table.table tbody tr:nth-child(#{num})", match: :first, &block)
          else
            within(all('table.table tbody tr')[num - 1], &block)
          end
        end

        def column_text(num)
          if RSpec.current_example.metadata[:js]
            find("td:nth-child(#{num})").text
          else
            all('td')[num - 1].text
          end
        end

        # delay in seconds
        def wait_for_ajax(delay = Capybara.default_max_wait_time)
          Timeout.timeout(delay) do
            active = page.evaluate_script('typeof jQuery !== "undefined" && jQuery.active')
            active = page.evaluate_script('typeof jQuery !== "undefined" && jQuery.active') until active.nil? || active.zero?
          end
        end

        def wait_for_turbo(timeout = nil)
          if has_css?('.turbo-progress-bar', visible: true, wait: 0.5.seconds)
            has_no_css?('.turbo-progress-bar', wait: timeout.presence || 1.seconds)
          end
        end

        def disable_html5_validation
          page.execute_script('for(var f=document.forms,i=f.length;i--;)f[i].setAttribute("novalidate",i)')
        end

        def wait_for(options = {}, &block)
          default_options = { error: nil, seconds: 5 }.merge(options)

          Selenium::WebDriver::Wait.new(timeout: default_options[:seconds]).until(&block)
        rescue Selenium::WebDriver::Error::TimeoutError
          default_options[:error].nil? ? false : raise(default_options[:error])
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_backend-4.4.1 lib/spree/backend/testing_support/capybara_utils.rb
spree_backend-4.4.0 lib/spree/backend/testing_support/capybara_utils.rb
spree_backend-4.4.0.rc2 lib/spree/backend/testing_support/capybara_utils.rb
spree_backend-4.4.0.rc1 lib/spree/backend/testing_support/capybara_utils.rb