Skip to content

Commit

Permalink
fix intermittent spec failure for order details
Browse files Browse the repository at this point in the history
use js: true in backend feature specs where required

fix spec for order details spec

fix order details spec, reset config track inventory levels in after block

test commit to fix order details spec

refactor for wait_for_ajax

change targeted product object in order details failure spec

wait for ajax and reload order in order details spec

modify failing test suit of order details spec

refactor prototypes_spec feature

extract wait_for_condition in capybara_ext, change default time of wait_for_ajax to Capybara.default_max_wait_time

change Capybara.max_wait_time_out to 10

hound ci fixes

refactor of refund reason and authorization, change timout to 15

fix return authorisation reasons and refund reasons feature spec, change timeout from 15 to 10

Conflicts:
	backend/spec/features/admin/refund_reasons/refund_reasons_spec.rb
	backend/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb
  • Loading branch information
Priyank Gupta authored and Mafi88 committed Mar 14, 2016
1 parent 9f7672a commit bd1b8b4
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 103 deletions.
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "General Settings", type: :feature, js: true do
describe "General Settings", type: :feature do
stub_authorization!

before(:each) do
Expand Down Expand Up @@ -30,7 +30,7 @@
end
end

context "clearing the cache" do
context "clearing the cache", js: true do
it "should clear the cache" do
expect(page).to_not have_content(Spree.t(:clear_cache_ok))
expect(page).to have_content(Spree.t(:clear_cache_warning))
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/features/admin/configuration/roles_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "Roles", type: :feature, js: true do
describe "Roles", type: :feature do
stub_authorization!

before(:each) do
Expand Down
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "Stock Locations", type: :feature, js: true do
describe "Stock Locations", type: :feature do
stub_authorization!

before(:each) do
Expand All @@ -18,7 +18,7 @@
expect(page).to have_content("London")
end

it "can delete an existing stock location" do
it "can delete an existing stock location", js: true do
location = create(:stock_location)
visit current_path

Expand All @@ -32,7 +32,7 @@
expect(page).to have_content("No Stock Locations found")
end

it "can update an existing stock location" do
it "can update an existing stock location", js: true do
create(:stock_location)
visit current_path

Expand Down
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "Tax Categories", type: :feature, js: true do
describe "Tax Categories", type: :feature do
stub_authorization!

before(:each) do
Expand Down Expand Up @@ -43,7 +43,7 @@
end

context "admin editing a tax category" do
it "should be able to update an existing tax category" do
it "should be able to update an existing tax category", js: true do
create(:tax_category)
click_link "Tax Categories"
within_row(1) { click_icon :edit }
Expand Down
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "Tax Rates", type: :feature, js: true do
describe "Tax Rates", type: :feature do
stub_authorization!

let!(:tax_rate) { create(:tax_rate, calculator: stub_model(Spree::Calculator)) }
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/features/admin/configuration/zones_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "Zones", type: :feature, js: true do
describe "Zones", type: :feature do
stub_authorization!

before(:each) do
Expand Down
15 changes: 0 additions & 15 deletions backend/spec/features/admin/orders/customer_details_spec.rb
Expand Up @@ -15,21 +15,6 @@

let!(:user) { create(:user, email: 'foobar@example.com', ship_address: ship_address, bill_address: bill_address) }

# "Intelligiently" wait on condition
#
# Much better than a random sleep "here and there"
# it will not cause any delay in case the condition is fullfilled on first cycle.
def wait_for_condition
time = Capybara.default_max_wait_time
step = 0.1
while time > 0
return if yield
sleep(step)
time -= 0.1
end
fail "Could not achieve condition within #{Capybara.default_max_wait_time} seconds."
end

# Value attribute is dynamically set via JS, so not observable via a CSS/XPath selector
# As the browser might take time to make the values visible in the dom we need to
# "intelligiently" wait for that event o prevent a race.
Expand Down
141 changes: 90 additions & 51 deletions backend/spec/features/admin/orders/order_details_spec.rb
Expand Up @@ -4,13 +4,12 @@
describe "Order Details", type: :feature, js: true do
let!(:stock_location) { create(:stock_location_with_items) }
let!(:product) { create(:product, name: 'spree t-shirt', price: 20.00) }
let!(:tote) { create(:product, name: "Tote", price: 15.00) }
let(:order) { create(:order, state: 'complete', completed_at: "2011-02-01 12:36:15", number: "R100") }
let(:state) { create(:state) }
let!(:shipping_method) { create(:shipping_method, name: "Default") }

before do
order.shipments.create(stock_location_id: stock_location.id)
order.shipments.create!(stock_location_id: stock_location.id)
order.contents.add(product.master, 2)
end

Expand Down Expand Up @@ -120,59 +119,72 @@
expect(page).to have_content("Backdoor")
end

it "will show the variant sku" do
it "will show the variant sku", js: false do
order = create(:completed_order_with_totals)
visit spree.edit_admin_order_path(order)
sku = order.line_items.first.variant.sku
expect(page).to have_content("SKU: #{sku}")
end

context "with special_instructions present" do
let(:order) { create(:order, state: 'complete', completed_at: "2011-02-01 12:36:15", number: "R100", special_instructions: "Very special instructions here") }
it "will show the special_instructions" do
before(:each) do
order.update_column(:special_instructions, "Very special instructions here")
end

it "will show the special_instructions", js: false do
visit spree.edit_admin_order_path(order)
expect(page).to have_content("Very special instructions here")
end
end

context "variant doesn't track inventory" do
before do
tote.master.update_column :track_inventory, false
# make sure there's no stock level for any item
tote.master.stock_items.update_all count_on_hand: 0, backorderable: false
end
context 'when not tracking inventory' do
let(:tote) { create(:product, name: "Tote", price: 15.00) }

it "adds variant to order just fine" do
select2_search tote.name, from: Spree.t(:name_or_sku)
within("table.stock-levels") do
fill_in "variant_quantity", with: 1
click_icon :add
context "variant doesn't track inventory" do
before do
tote.master.update_column :track_inventory, false
# make sure there's no stock level for any item
tote.master.stock_items.update_all count_on_hand: 0, backorderable: false
end

within(".line-items") do
expect(page).to have_content(tote.name)
end
end
end
it "adds variant to order just fine" do
select2_search tote.name, from: Spree.t(:name_or_sku)
within("table.stock-levels") do
fill_in "variant_quantity", with: 1
click_icon :add
end

context "site doesn't track inventory" do
before do
Spree::Config.set track_inventory_levels: false
product.master.update_column(:track_inventory, true)
product.master.stock_items.first.update_column(:backorderable, true)
product.master.stock_items.first.update_column(:count_on_hand, 0)
wait_for_ajax

within(".line-items") do
expect(page).to have_content(tote.name)
end
end
end

it "adds variant to order just fine" do
select2_search product.name, from: Spree.t(:name_or_sku)
within("table.stock-levels") do
fill_in "variant_quantity", with: 1
click_icon :add
context "site doesn't track inventory" do
before do
Spree::Config[:track_inventory_levels] = false
tote.master.update_column(:track_inventory, true)
# make sure there's no stock level for any item
tote.master.stock_items.update_all count_on_hand: 0, backorderable: true
end

within(".line-items") do
expect(page).to have_content(product.name)
it "adds variant to order just fine" do
select2_search tote.name, from: Spree.t(:name_or_sku)
within("table.stock-levels") do
fill_in "variant_quantity", with: 1
click_icon :add
end

wait_for_ajax

within(".line-items") do
expect(page).to have_content(tote.name)
end
end

after { Spree::Config[:track_inventory_levels] = true }
end
end

Expand Down Expand Up @@ -301,7 +313,7 @@

context 'A shipment has shipped' do

it 'should not show or let me back to the cart page, nor show the shipment edit buttons' do
it 'should not show or let me back to the cart page, nor show the shipment edit buttons', js: false do
order = create(:order, state: 'payment')
order.shipments.create!(stock_location_id: stock_location.id, state: 'shipped')

Expand Down Expand Up @@ -376,27 +388,54 @@
end
end

context "site doesn't track inventory" do
before do
Spree::Config.set track_inventory_levels: false
product.master.update_column(:track_inventory, true)
product.master.stock_items.first.update_column(:backorderable, true)
product.master.stock_items.first.update_column(:count_on_hand, 0)
context 'when not tracking inventory' do
let(:tote) { create(:product, name: "Tote", price: 15.00) }

context "variant doesn't track inventory" do
before do
tote.master.update_column :track_inventory, false
# make sure there's no stock level for any item
tote.master.stock_items.update_all count_on_hand: 0, backorderable: false
end

it "adds variant to order just fine" do
select2_search tote.name, from: Spree.t(:name_or_sku)
within("table.stock-levels") do
fill_in "stock_item_quantity", with: 1
click_icon :add
end

wait_for_ajax

within("[data-hook=admin_order_form_fields]") do
expect(page).to have_content(tote.name)
end
end
end

it "adds variant to order just fine" do
select2_search product.name, from: Spree.t(:name_or_sku)
within("table.stock-levels") do
fill_in "stock_item_quantity", with: 1
click_icon :add
context "site doesn't track inventory" do
before do
Spree::Config[:track_inventory_levels] = false
tote.master.update_column(:track_inventory, true)
# make sure there's no stock level for any item
tote.master.stock_items.update_all count_on_hand: 0, backorderable: true
end

wait_for_ajax
order.reload
it "adds variant to order just fine" do
select2_search tote.name, from: Spree.t(:name_or_sku)
within("table.stock-levels") do
fill_in "stock_item_quantity", with: 1
click_icon :add
end

within(".stock-contents") do
expect(page).to have_content(product.name)
wait_for_ajax

within("[data-hook=admin_order_form_fields]") do
expect(page).to have_content(tote.name)
end
end

after { Spree::Config[:track_inventory_levels] = true }
end
end

Expand Down Expand Up @@ -571,7 +610,7 @@
and_return(Spree.user_class.new)
end

it 'should not display order tabs or edit buttons without ability' do
it 'should not display order tabs or edit buttons without ability', js: false do
visit spree.edit_admin_order_path(order)

# Order Form
Expand Down
10 changes: 5 additions & 5 deletions backend/spec/features/admin/orders/payments_spec.rb
Expand Up @@ -62,7 +62,7 @@ def refresh_page
end
end

it 'lists and create payments for an order', js: true do
it 'lists and create payments for an order' do
within_row(1) do
expect(column_text(3)).to eq('$150.00')
expect(column_text(4)).to eq('Credit Card')
Expand Down Expand Up @@ -91,7 +91,7 @@ def refresh_page
end

# Regression test for #1269
it 'cannot create a payment for an order with no payment methods' do
it 'cannot create a payment for an order with no payment methods', js: false do
Spree::PaymentMethod.delete_all
order.payments.delete_all

Expand All @@ -101,7 +101,7 @@ def refresh_page
end

%w[checkout pending].each do |state|
context "payment is #{state.inspect}", js: true do
context "payment is #{state.inspect}" do
let(:state) { state }

it 'allows the amount to be edited by clicking on the edit button then saving' do
Expand Down Expand Up @@ -152,7 +152,7 @@ def refresh_page
end
end

context 'payment is completed' do
context 'payment is completed', js: false do
let(:state) { 'completed' }

it 'does not allow the amount to be edited' do
Expand Down Expand Up @@ -204,7 +204,7 @@ def refresh_page

before { visit spree.admin_order_payments_path(order) }

it "is able to reuse customer payment source" do
it "is able to reuse customer payment source", js: false do
expect(find("#card_#{cc.id}")).to be_checked
click_button "Continue"
expect(page).to have_content("Payment has been successfully created!")
Expand Down
4 changes: 2 additions & 2 deletions backend/spec/features/admin/products/edit/images_spec.rb
Expand Up @@ -40,7 +40,7 @@
end

# Regression test for #2228
it "should see variant images" do
it "should see variant images", js: false do
variant = create(:variant)
variant.images.create!(attachment: File.open(file_path))
visit spree.admin_product_images_path(variant.product)
Expand All @@ -64,7 +64,7 @@
end
end

it "should not see variant column when product has no variants" do
it "should not see variant column when product has no variants", js: false do
product = create(:product)
product.images.create!(attachment: File.open(file_path))
visit spree.admin_product_images_path(product)
Expand Down
9 changes: 5 additions & 4 deletions backend/spec/features/admin/products/properties_spec.rb
Expand Up @@ -42,7 +42,7 @@
end

context "creating a property" do
it "should allow an admin to create a new product property", js: true do
it "should allow an admin to create a new product property" do
click_link "Products"
click_link "Properties"
click_link "new_property_link"
Expand Down Expand Up @@ -126,9 +126,10 @@ def fill_in_property
end

def delete_product_property
page.evaluate_script('window.confirm = function() { return true; }')
click_icon :delete
wait_for_ajax # delete action must finish before reloading
accept_alert do
click_icon :delete
wait_for_ajax # delete action must finish before reloading
end
end

def check_property_row_count(expected_row_count)
Expand Down

0 comments on commit bd1b8b4

Please sign in to comment.