diff --git a/app/views/spree/orders/form/_cart_links.html.haml b/app/views/spree/orders/form/_cart_links.html.haml index d63d9395ac..798a428f7c 100644 --- a/app/views/spree/orders/form/_cart_links.html.haml +++ b/app/views/spree/orders/form/_cart_links.html.haml @@ -1,5 +1,5 @@ .row.links{'data-hook' => "cart_buttons"} - %a.button.large.secondary{href: current_shop_products_path, "ng-disabled" => "#{@insufficient_stock_lines.any?}", "disable-dynamically" => true} + %a.continue-shopping.button.large.secondary{href: current_shop_products_path, "ng-disabled" => "#{@insufficient_stock_lines.any?}", "disable-dynamically" => true} = t :orders_edit_continue %a#checkout-link.button.large.primary.right{href: main_app.checkout_path, "ng-disabled" => "#{@insufficient_stock_lines.any?}", "disable-dynamically" => true} = t :orders_edit_checkout diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index 6a02206e1d..b032bdee01 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -201,6 +201,40 @@ feature "full-page cart", js: true do expect(page).to have_content "Insufficient stock available, only 2 remaining" expect(page).to have_field "order_line_items_attributes_0_quantity", with: '1' end + + describe "full UX for correcting selected quantities with insufficient stock" do + before do + add_product_to_cart order, product_with_tax, quantity: 5 + variant.update_attributes! on_hand: 4, on_demand: false + end + + it "gives clear user feedback during the correcting process" do + visit main_app.cart_path + + # shows a relevant Flash message + expect(page).to have_selector ".alert-box", text: I18n.t('spree.orders.error_flash_for_unavailable_items') + + # "Continue Shopping" and "Checkout" buttons are disabled + expect(page).to have_selector "a.continue-shopping[disabled=disabled]" + expect(page).to have_selector "a#checkout-link[disabled=disabled]" + + # Quantity field clearly marked as invalid and "Update" button is not highlighted + expect(page).to have_selector "#order_line_items_attributes_0_quantity.ng-invalid-stock" + expect(page).to_not have_selector "#update-button.alert" + + fill_in "order_line_items_attributes_0_quantity", with: 4 + + # Quantity field not marked as invalid and "Update" button is highlighted after correction + expect(page).to_not have_selector "#order_line_items_attributes_0_quantity.ng-invalid-stock" + expect(page).to have_selector "#update-button.alert" + + click_button I18n.t("update") + + # "Continue Shopping" and "Checkout" buttons are not disabled after cart is updated + expect(page).to_not have_selector "a.continue-shopping[disabled=disabled]" + expect(page).to_not have_selector "a#checkout-link[disabled=disabled]" + end + end end end