mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove capybara_ext from spree and bring its helpers that are required in ofn
This commit is contained in:
@@ -13,9 +13,9 @@ describe "Tax Categories" do
|
||||
click_link "Tax Categories"
|
||||
expect(page).to have_content("Listing Tax Categories")
|
||||
within_row(1) do
|
||||
expect(column_text(1)).to eq("Clothing")
|
||||
expect(column_text(2)).to eq("For Clothing")
|
||||
expect(column_text(3)).to eq("False")
|
||||
expect(find("td:nth-child(1)").text).to eq("Clothing")
|
||||
expect(find("td:nth-child(2)").text).to eq("For Clothing")
|
||||
expect(find("td:nth-child(3)").text).to eq("False")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -44,7 +44,7 @@ describe "Tax Categories" do
|
||||
it "should be able to update an existing tax category" do
|
||||
create(:tax_category)
|
||||
click_link "Tax Categories"
|
||||
within_row(1) { click_icon :edit }
|
||||
within_row(1) { find(".icon-edit").click }
|
||||
fill_in "tax_category_description", with: "desc 99"
|
||||
click_button "Update"
|
||||
expect(page).to have_content("successfully updated!")
|
||||
|
||||
@@ -43,7 +43,7 @@ describe "Taxonomies" do
|
||||
it "should allow an admin to update an existing taxonomy" do
|
||||
create(:taxonomy)
|
||||
click_link "Taxonomies"
|
||||
within_row(1) { click_icon :edit }
|
||||
within_row(1) { find(".icon-edit").click }
|
||||
fill_in "taxonomy_name", with: "sports 99"
|
||||
click_button "Update"
|
||||
expect(page).to have_content("successfully updated!")
|
||||
|
||||
@@ -105,7 +105,7 @@ feature '
|
||||
uncheck 'Only show complete orders'
|
||||
page.find('a.icon-search').click
|
||||
|
||||
click_icon :edit
|
||||
find(".icon-edit").click
|
||||
|
||||
expect(page).to have_current_path spree.edit_admin_order_path(incomplete_order)
|
||||
end
|
||||
|
||||
@@ -32,8 +32,7 @@ Shoulda::Matchers.configure do |config|
|
||||
end
|
||||
end
|
||||
|
||||
# Allow connections to phantomjs/selenium whilst raising errors
|
||||
# when connecting to external sites
|
||||
# Allow connections to selenium whilst raising errors when connecting to external sites
|
||||
require 'webmock/rspec'
|
||||
WebMock.enable!
|
||||
WebMock.disable_net_connect!(
|
||||
@@ -44,7 +43,6 @@ WebMock.disable_net_connect!(
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }
|
||||
require 'spree/testing_support/capybara_ext'
|
||||
require 'spree/api/testing_support/setup'
|
||||
require 'spree/testing_support/authorization_helpers'
|
||||
require 'spree/testing_support/preferences'
|
||||
@@ -65,6 +63,11 @@ end
|
||||
|
||||
Capybara.default_max_wait_time = 30
|
||||
|
||||
Capybara.configure do |config|
|
||||
config.match = :prefer_exact
|
||||
config.ignore_hidden_elements = true
|
||||
end
|
||||
|
||||
require "paperclip/matchers"
|
||||
|
||||
# Override setting in Spree engine: Spree::Core::MailSettings
|
||||
|
||||
@@ -95,16 +95,29 @@ module WebHelper
|
||||
end
|
||||
end
|
||||
|
||||
def within_row(num, &block)
|
||||
within("table.index tbody tr:nth-child(#{num})", &block)
|
||||
end
|
||||
|
||||
def select2_select(value, options)
|
||||
id = options[:from]
|
||||
options[:from] = "#s2id_#{id}"
|
||||
targetted_select2(value, options)
|
||||
end
|
||||
|
||||
def targetted_select2(value, options)
|
||||
# find select2 element and click it
|
||||
find(options[:from]).find('a').click
|
||||
select_select2_result(value)
|
||||
end
|
||||
|
||||
def select_select2_result(value)
|
||||
sleep(1)
|
||||
page.execute_script(%Q{$("div.select2-result-label:contains('#{value}')").mouseup()})
|
||||
end
|
||||
|
||||
# Support having different texts to search for and to click in the select2
|
||||
# field.
|
||||
#
|
||||
# This overrides the method in Spree.
|
||||
def targetted_select2_search(value, options)
|
||||
page.execute_script %{$('#{options[:from]}').select2('open')}
|
||||
page.execute_script "$('#{options[:dropdown_css]} input.select2-input').val('#{value}').trigger('keyup-change');"
|
||||
@@ -124,6 +137,18 @@ module WebHelper
|
||||
page.execute_script "jQuery('#{selector}').select2('close');"
|
||||
end
|
||||
|
||||
def set_select2_field(field, value)
|
||||
page.execute_script %Q{$('#{field}').select2('val', '#{value}')}
|
||||
end
|
||||
|
||||
def select2_search(value, options)
|
||||
label = find_label_by_text(options[:from])
|
||||
within label.first(:xpath,".//..") do
|
||||
options[:from] = "##{find(".select2-container")["id"]}"
|
||||
targetted_select2_search(value, options)
|
||||
end
|
||||
end
|
||||
|
||||
def select2_search_async(value, options)
|
||||
id = find_label_by_text(options[:from])
|
||||
options[:from] = "#s2id_#{id}"
|
||||
@@ -145,6 +170,28 @@ module WebHelper
|
||||
page.execute_script(%{$("div.select2-result-label:contains('#{value}')").mouseup()})
|
||||
end
|
||||
|
||||
def find_label_by_text(text)
|
||||
label = find_label(text)
|
||||
counter = 0
|
||||
|
||||
# Because JavaScript testing is prone to errors...
|
||||
while label.nil? && counter < 10
|
||||
sleep(1)
|
||||
counter += 1
|
||||
label = find_label(text)
|
||||
end
|
||||
|
||||
if label.nil?
|
||||
raise "Could not find label by text #{text}"
|
||||
end
|
||||
|
||||
label
|
||||
end
|
||||
|
||||
def find_label(text)
|
||||
first(:xpath, "//label[text()[contains(.,'#{text}')]]")
|
||||
end
|
||||
|
||||
def accept_js_alert
|
||||
page.driver.browser.switch_to.alert.accept
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user