Transpec spec/features/consumer/shopping/shopping_spec

This commit is contained in:
luisramos0
2019-09-20 10:16:08 +01:00
parent 49f7b4c8e2
commit a004822019

View File

@@ -26,9 +26,9 @@ feature "As a consumer I want to shop with a distributor", js: true do
# Then we should see the distributor and its logo
visit shop_path
page.should have_text distributor.name
expect(page).to have_text distributor.name
find("#tab_about a").click
first("distributor img")['src'].should include distributor.logo.url(:thumb)
expect(first("distributor img")['src']).to include distributor.logo.url(:thumb)
end
it "shows the producers for a distributor" do
@@ -37,7 +37,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
visit shop_path
find("#tab_producers a").click
page.should have_content supplier.name
expect(page).to have_content supplier.name
end
describe "selecting an order cycle" do
@@ -46,7 +46,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
it "selects an order cycle if only one is open" do
exchange1.update_attribute :pickup_time, "turtles"
visit shop_path
page.should have_selector "option[selected]", text: 'turtles'
expect(page).to have_selector "option[selected]", text: 'turtles'
end
describe "with multiple order cycles" do
@@ -59,9 +59,9 @@ feature "As a consumer I want to shop with a distributor", js: true do
it "shows a select with all order cycles, but doesn't show the products by default" do
visit shop_path
page.should have_selector "option", text: 'frogs'
page.should have_selector "option", text: 'turtles'
page.should_not have_selector("input.button.right", visible: true)
expect(page).to have_selector "option", text: 'frogs'
expect(page).to have_selector "option", text: 'turtles'
expect(page).not_to have_selector("input.button.right", visible: true)
end
it "shows products after selecting an order cycle" do
@@ -69,16 +69,16 @@ feature "As a consumer I want to shop with a distributor", js: true do
variant.update_attribute(:display_as, "rabbit")
add_variant_to_order_cycle(exchange1, variant)
visit shop_path
page.should_not have_content product.name
Spree::Order.last.order_cycle.should.nil?
expect(page).not_to have_content product.name
expect(Spree::Order.last.order_cycle).to.nil?
select "frogs", from: "order_cycle_id"
page.should have_selector "products"
page.should have_content "Next order closing in 2 days"
Spree::Order.last.order_cycle.should == oc1
page.should have_content product.name
page.should have_content variant.display_name
page.should have_content variant.display_as
expect(page).to have_selector "products"
expect(page).to have_content "Next order closing in 2 days"
expect(Spree::Order.last.order_cycle).to eq(oc1)
expect(page).to have_content product.name
expect(page).to have_content variant.display_name
expect(page).to have_content variant.display_as
open_product_modal product
modal_should_be_open_for product
@@ -94,26 +94,26 @@ feature "As a consumer I want to shop with a distributor", js: true do
# -- Selecting an order cycle
visit shop_path
select "turtles", from: "order_cycle_id"
page.should have_content with_currency(1020.99)
expect(page).to have_content with_currency(1020.99)
# -- Cart shows correct price
fill_in "variants[#{variant.id}]", with: 1
show_cart
within("li.cart") { page.should have_content with_currency(1020.99) }
within("li.cart") { expect(page).to have_content with_currency(1020.99) }
# -- Changing order cycle
accept_alert do
select "frogs", from: "order_cycle_id"
end
page.should have_content with_currency(19.99)
expect(page).to have_content with_currency(19.99)
# -- Cart should be cleared
# ng-animate means that the old product row is likely to be present, so we ensure
# that we are not filling in the quantity on the outgoing row
page.should_not have_selector "tr.product-cart"
expect(page).not_to have_selector "tr.product-cart"
within('product:not(.ng-leave)') { fill_in "variants[#{variant.id}]", with: 1 }
show_cart
within("li.cart") { page.should have_content with_currency(19.99) }
within("li.cart") { expect(page).to have_content with_currency(19.99) }
end
describe "declining to clear the cart" do
@@ -130,11 +130,11 @@ feature "As a consumer I want to shop with a distributor", js: true do
handle_js_confirm(false) do
select "frogs", from: "order_cycle_id"
show_cart
page.should have_selector "tr.product-cart"
page.should have_selector 'li.cart', text: '1'
expect(page).to have_selector "tr.product-cart"
expect(page).to have_selector 'li.cart', text: '1'
# The order cycle choice should not have changed
page.should have_select 'order_cycle_id', selected: 'turtles'
expect(page).to have_select 'order_cycle_id', selected: 'turtles'
end
end
end
@@ -192,15 +192,15 @@ feature "As a consumer I want to shop with a distributor", js: true do
visit shop_path
# Page should not have product.price (with or without fee)
page.should_not have_price with_currency(10.00)
page.should_not have_price with_currency(33.00)
expect(page).not_to have_price with_currency(10.00)
expect(page).not_to have_price with_currency(33.00)
# Page should have variant prices (with fee)
page.should have_price with_currency(43.00)
page.should have_price with_currency(53.00)
expect(page).to have_price with_currency(43.00)
expect(page).to have_price with_currency(53.00)
# Product price should be listed as the lesser of these
page.should have_price with_currency(43.00)
expect(page).to have_price with_currency(43.00)
end
it "filters search results properly" do
@@ -208,12 +208,12 @@ feature "As a consumer I want to shop with a distributor", js: true do
select "frogs", from: "order_cycle_id"
fill_in "search", with: "74576345634XXXXXX"
page.should have_content "Sorry, no results found"
page.should_not have_content product2.name
expect(page).to have_content "Sorry, no results found"
expect(page).not_to have_content product2.name
fill_in "search", with: "Meer" # For product named "Meercats"
page.should have_content product2.name
page.should_not have_content product.name
expect(page).to have_content product2.name
expect(page).not_to have_content product.name
fill_in "search", with: "Dome" # For product with meta_keywords "Domestic"
expect(page).to have_content product.name
@@ -227,10 +227,10 @@ feature "As a consumer I want to shop with a distributor", js: true do
fill_in "search", with: "Badg" # For variant with display_name "Badgers"
within('div.pad-top') do
page.should have_content product.name
page.should have_content variant2.display_name
page.should_not have_content product2.name
page.should_not have_content variant3.display_name
expect(page).to have_content product.name
expect(page).to have_content variant2.display_name
expect(page).not_to have_content product2.name
expect(page).not_to have_content variant3.display_name
end
end
end
@@ -252,23 +252,23 @@ feature "As a consumer I want to shop with a distributor", js: true do
it "should save group buy data to the cart and display it on shopfront reload" do
# -- Quantity
fill_in "variants[#{variant.id}]", with: 6
page.should have_in_cart product.name
expect(page).to have_in_cart product.name
wait_until { !cart_dirty }
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.quantity.should == 6
expect(li.quantity).to eq(6)
# -- Max quantity
fill_in "variant_attributes[#{variant.id}][max_quantity]", with: 7
wait_until { !cart_dirty }
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.max_quantity.should == 7
expect(li.max_quantity).to eq(7)
# -- Reload
visit shop_path
page.should have_field "variants[#{variant.id}]", with: 6
page.should have_field "variant_attributes[#{variant.id}][max_quantity]", with: 7
expect(page).to have_field "variants[#{variant.id}]", with: 6
expect(page).to have_field "variant_attributes[#{variant.id}][max_quantity]", with: 7
end
end
end
@@ -288,16 +288,16 @@ feature "As a consumer I want to shop with a distributor", js: true do
it "lets us add and remove products from our cart" do
fill_in "variants[#{variant.id}]", with: '1'
page.should have_in_cart product.name
expect(page).to have_in_cart product.name
wait_until { !cart_dirty }
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.quantity.should == 1
expect(li.quantity).to eq(1)
fill_in "variants[#{variant.id}]", with: '0'
within('li.cart') { page.should_not have_content product.name }
within('li.cart') { expect(page).not_to have_content product.name }
wait_until { !cart_dirty }
Spree::LineItem.where(id: li).should be_empty
expect(Spree::LineItem.where(id: li)).to be_empty
end
it "lets us add a quantity greater than on_hand value if product is on_demand" do
@@ -306,7 +306,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
fill_in "variants[#{variant.id}]", with: '10'
page.should have_field "variants[#{variant.id}]", with: '10'
expect(page).to have_field "variants[#{variant.id}]", with: '10'
end
it "alerts us when we enter a quantity greater than the stock available" do
@@ -317,7 +317,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
fill_in "variants[#{variant.id}]", with: '10'
end
page.should have_field "variants[#{variant.id}]", with: '5'
expect(page).to have_field "variants[#{variant.id}]", with: '5'
end
describe "when a product goes out of stock just before it's added to the cart" do
@@ -332,20 +332,20 @@ feature "As a consumer I want to shop with a distributor", js: true do
wait_until { !cart_dirty }
within(".out-of-stock-modal") do
page.should have_content "stock levels for one or more of the products in your cart have reduced"
page.should have_content "#{product.name} - #{variant.unit_to_display} is now out of stock."
expect(page).to have_content "stock levels for one or more of the products in your cart have reduced"
expect(page).to have_content "#{product.name} - #{variant.unit_to_display} is now out of stock."
end
# -- Page updates
# Update amount in cart
page.should have_field "variants[#{variant.id}]", with: '0', disabled: true
page.should have_field "variants[#{variant2.id}]", with: ''
expect(page).to have_field "variants[#{variant.id}]", with: '0', disabled: true
expect(page).to have_field "variants[#{variant2.id}]", with: ''
# Update amount available in product list
# If amount falls to zero, variant should be greyed out and input disabled
page.should have_selector "#variant-#{variant.id}.out-of-stock"
page.should have_selector "#variants_#{variant.id}[ofn-on-hand='0']"
page.should have_selector "#variants_#{variant.id}[disabled='disabled']"
expect(page).to have_selector "#variant-#{variant.id}.out-of-stock"
expect(page).to have_selector "#variants_#{variant.id}[ofn-on-hand='0']"
expect(page).to have_selector "#variants_#{variant.id}[disabled='disabled']"
end
it 'does not show out of stock modal if product is on_demand' do
@@ -374,18 +374,18 @@ feature "As a consumer I want to shop with a distributor", js: true do
wait_until { !cart_dirty }
within(".out-of-stock-modal") do
page.should have_content "stock levels for one or more of the products in your cart have reduced"
page.should have_content "#{product.name} - #{variant.unit_to_display} is now out of stock."
expect(page).to have_content "stock levels for one or more of the products in your cart have reduced"
expect(page).to have_content "#{product.name} - #{variant.unit_to_display} is now out of stock."
end
# -- Page updates
# Update amount in cart
page.should have_field "variant_attributes[#{variant.id}][max_quantity]", with: '0', disabled: true
expect(page).to have_field "variant_attributes[#{variant.id}][max_quantity]", with: '0', disabled: true
# Update amount available in product list
# If amount falls to zero, variant should be greyed out and input disabled
page.should have_selector "#variant-#{variant.id}.out-of-stock"
page.should have_selector "#variants_#{variant.id}_max[disabled='disabled']"
expect(page).to have_selector "#variant-#{variant.id}.out-of-stock"
expect(page).to have_selector "#variants_#{variant.id}_max[disabled='disabled']"
end
end
@@ -400,8 +400,8 @@ feature "As a consumer I want to shop with a distributor", js: true do
wait_until { !cart_dirty }
within(".out-of-stock-modal") do
page.should have_content "stock levels for one or more of the products in your cart have reduced"
page.should have_content "#{product.name} - #{variant.unit_to_display} now only has 1 remaining"
expect(page).to have_content "stock levels for one or more of the products in your cart have reduced"
expect(page).to have_content "#{product.name} - #{variant.unit_to_display} now only has 1 remaining"
end
end
@@ -418,12 +418,12 @@ feature "As a consumer I want to shop with a distributor", js: true do
wait_until { !cart_dirty }
within(".out-of-stock-modal") do
page.should have_content "stock levels for one or more of the products in your cart have reduced"
page.should have_content "#{product.name} - #{variant.unit_to_display} now only has 1 remaining"
expect(page).to have_content "stock levels for one or more of the products in your cart have reduced"
expect(page).to have_content "#{product.name} - #{variant.unit_to_display} now only has 1 remaining"
end
page.should have_field "variants[#{variant.id}]", with: '1'
page.should have_field "variant_attributes[#{variant.id}][max_quantity]", with: '3'
expect(page).to have_field "variants[#{variant.id}]", with: '1'
expect(page).to have_field "variant_attributes[#{variant.id}][max_quantity]", with: '3'
end
end
end
@@ -433,17 +433,17 @@ feature "As a consumer I want to shop with a distributor", js: true do
context "when no order cycles are available" do
it "tells us orders are closed" do
visit shop_path
page.should have_content "Orders are closed"
expect(page).to have_content "Orders are closed"
end
it "shows the last order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 17.days.ago, orders_close_at: 10.days.ago)
visit shop_path
page.should have_content "The last cycle closed 10 days ago"
expect(page).to have_content "The last cycle closed 10 days ago"
end
it "shows the next order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 17.days.from_now)
visit shop_path
page.should have_content "The next cycle opens in 10 days"
expect(page).to have_content "The next cycle opens in 10 days"
end
end