From 459e53f43d93cf6b404d9536289e329e3faa9e87 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 22 May 2020 15:39:10 +0200 Subject: [PATCH] Adjust specs for new cart display --- app/views/shared/menu/_cart_sidebar.html.haml | 4 ++-- spec/features/consumer/shopping/shopping_spec.rb | 16 +++++++++------- .../consumer/shopping/variant_overrides_spec.rb | 13 ++++++------- .../darkswarm/services/variants_spec.js.coffee | 16 ---------------- spec/support/request/shop_workflow.rb | 8 ++++---- spec/support/request/ui_component_helper.rb | 6 +++--- 6 files changed, 24 insertions(+), 39 deletions(-) diff --git a/app/views/shared/menu/_cart_sidebar.html.haml b/app/views/shared/menu/_cart_sidebar.html.haml index 1bfde559f8..bb00e88b91 100644 --- a/app/views/shared/menu/_cart_sidebar.html.haml +++ b/app/views/shared/menu/_cart_sidebar.html.haml @@ -33,7 +33,7 @@ \: {{ Cart.total() | localizeCurrency }} - %a.button.large.dark.left{href: main_app.cart_path, "ng-disabled" => "Cart.dirty || Cart.empty()", "ng-class" => "{ dirty: Cart.dirty }"} + %a.edit-cart.button.large.dark.left{href: main_app.cart_path, "ng-disabled" => "Cart.dirty || Cart.empty()", "ng-class" => "{ dirty: Cart.dirty }"} = "{{ Cart.dirty ? '#{t(:cart_updating)}' : (Cart.empty() ? '#{t(:cart_empty)}' : '#{t('.edit_cart')}' ) }}" - %a.button.large.bright.right{href: main_app.checkout_path, "ng-disabled" => "Cart.dirty || Cart.empty()"} + %a.checkout.button.large.bright.right{href: main_app.checkout_path, "ng-disabled" => "Cart.dirty || Cart.empty()"} = t '.checkout' diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index e1679791d4..85b0a92873 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -105,8 +105,9 @@ feature "As a consumer I want to shop with a distributor", js: true do # -- Cart shows correct price fill_in "variants[#{variant.id}]", with: 1 - show_cart - within("li.cart") { expect(page).to have_content with_currency(1020.99) } + toggle_cart + within(".cart-sidebar") { expect(page).to have_content with_currency(1020.99) } + toggle_cart # -- Changing order cycle accept_alert do @@ -119,8 +120,9 @@ feature "As a consumer I want to shop with a distributor", js: true do # that we are not filling in the quantity on the outgoing row 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") { expect(page).to have_content with_currency(19.99) } + + toggle_cart + within(".cart-sidebar") { expect(page).to have_content with_currency(19.99) } end describe "declining to clear the cart" do @@ -136,9 +138,9 @@ feature "As a consumer I want to shop with a distributor", js: true do it "leaves the cart untouched when the user declines" do handle_js_confirm(false) do select "frogs", from: "order_cycle_id" - show_cart + toggle_cart expect(page).to have_selector "tr.product-cart" - expect(page).to have_selector 'li.cart', text: '1' + expect(page).to have_selector '.cart-sidebar', text: '1' # The order cycle choice should not have changed expect(page).to have_select 'order_cycle_id', selected: 'turtles' @@ -294,7 +296,7 @@ feature "As a consumer I want to shop with a distributor", js: true do expect(li.quantity).to eq(1) fill_in "variants[#{variant.id}]", with: '0' - within('li.cart') { expect(page).not_to have_content product.name } + within('.cart-sidebar') { expect(page).not_to have_content product.name } wait_until { !cart_dirty } expect(Spree::LineItem.where(id: li)).to be_empty diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb index a4279786da..6dfed074a7 100644 --- a/spec/features/consumer/shopping/variant_overrides_spec.rb +++ b/spec/features/consumer/shopping/variant_overrides_spec.rb @@ -67,8 +67,8 @@ feature "shopping with variant overrides defined", js: true do it "shows the correct prices when products are in the cart" do fill_in "variants[#{product1_variant1.id}]", with: "2" - show_cart - wait_until_enabled 'li.cart a.button' + toggle_cart + wait_until_enabled '.cart-sidebar a.edit-cart' visit shop_path expect(page).to have_price with_currency(61.11) end @@ -78,9 +78,8 @@ feature "shopping with variant overrides defined", js: true do it "shows the overridden price with fees in the quick cart" do fill_in "variants[#{product1_variant1.id}]", with: "2" - show_cart + toggle_cart expect(page).to have_selector "#cart-variant-#{product1_variant1.id} .quantity", text: '2' - expect(page).to have_selector "#cart-variant-#{product1_variant1.id} .price", text: with_currency(61.11) expect(page).to have_selector "#cart-variant-#{product1_variant1.id} .total-price", text: with_currency(122.22) end @@ -202,8 +201,8 @@ feature "shopping with variant overrides defined", js: true do end def click_checkout - show_cart - wait_until_enabled 'li.cart a.button' - first(:link, 'Checkout now').click + toggle_cart + wait_until_enabled '.cart-sidebar a.edit-cart' + first(:link, I18n.t('shared.menu.cart_sidebar.checkout')).click end end diff --git a/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee index 408fecf7ea..2d9d1452f3 100644 --- a/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee @@ -49,25 +49,9 @@ describe 'Variants service', -> variant = {product_name: 'product_name', name_to_display: 'product_name'} expect(Variants.extendedVariantName(variant)).toEqual "product_name" - it "includes the options text even if variant name is same as product", -> - variant = - product_name: 'product_name' - name_to_display: 'product_name' - options_text: 'options_text' - - expect(Variants.extendedVariantName(variant)).toEqual "product_name (options_text)" - describe "when the product name and the variant name differ", -> it "returns a combined name when there is no options text", -> variant = product_name: 'product_name' name_to_display: 'name_to_display' expect(Variants.extendedVariantName(variant)).toEqual "product_name - name_to_display" - - it "returns a combined name when there is some options text", -> - variant = - product_name: 'product_name' - name_to_display: 'name_to_display' - options_text: 'options_text' - - expect(Variants.extendedVariantName(variant)).toEqual "product_name - name_to_display (options_text)" diff --git a/spec/support/request/shop_workflow.rb b/spec/support/request/shop_workflow.rb index cde1437b04..e5123715e0 100644 --- a/spec/support/request/shop_workflow.rb +++ b/spec/support/request/shop_workflow.rb @@ -1,17 +1,17 @@ module ShopWorkflow def wait_for_cart first("#cart").click - within '.cart-dropdown' do + within '.cart-sidebar' do expect(page).to_not have_link "Updating cart..." end end def edit_cart wait_for_cart - within '.cart-dropdown' do - expect(page).to have_link "Edit your cart" + within '.cart-sidebar' do + expect(page).to have_link I18n.t('shared.menu.cart_sidebar.edit_cart') end - first("a.add_to_cart").click + first("a.edit-cart").click end def have_price(price) diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index 277d8ee88c..b23002e3d7 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -59,13 +59,13 @@ module UIComponentHelper end def have_in_cart(name) - show_cart - within "li.cart" do + toggle_cart + within ".cart-sidebar" do have_content name end end - def show_cart + def toggle_cart page.find("#cart").click end