Sha256: 3a733b89712fbf0a4939a16df3acf2a2a3d49f409d5e6d87b19f9d55a611ed61

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

module Spotlight::TestFeaturesHelpers
  def fill_in_typeahead_field selector, opts = {}
    # Poltergeist / Capybara doesn't fire the events typeahead.js
    # is listening for, so we help it out a little:
    page.execute_script <<-EOF
      $("input[name='#{selector}']").val("#{opts[:with]}").trigger("input");
      $("input[name='#{selector}']").typeahead("open");
      $(".tt-suggestion").click();
    EOF

    find('.tt-suggestion').click
  end

  def add_widget type = nil
    # click to add widget
    find('[data-icon="add"]').click

    if type
      # click the item + image widget
      expect(page).to have_css("a[data-type='#{type}']")
      find("a[data-type='#{type}']").click
    end
  end

  def save_page
    sleep 1
    click_button("Save changes")
    # verify that the page was created
    expect(page).to have_content("page was successfully updated")
  end

  RSpec::Matchers.define :have_breadcrumbs do |*expected|
    match do |actual|
      errors = []
      errors << "Unable to find breadcrumbs" unless actual.has_css? ".breadcrumb"

      breadcrumbs = expected.dup

      actual.within(".breadcrumb") do
        last = breadcrumbs.pop
        breadcrumbs.each do |e|
          errors << "Unable to find breadcrumb #{e}" unless actual.has_link? e
        end

        errors << "Unable to find breadcrumb #{last}" unless actual.has_content? last
        errors << "Expected #{last} not to be a link" if actual.has_link? last
      end

      errors.empty?
    end

    failure_message do |actual|
      "expected that #{actual.all(".breadcrumb li").map { |x| x.text }.join(" / ")} would include #{expected.join(" / ")}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blacklight-spotlight-0.3.1 spec/support/features/test_features_helpers.rb
blacklight-spotlight-0.3.0 spec/support/features/test_features_helpers.rb
blacklight-spotlight-0.2.0 spec/support/features/test_features_helpers.rb