From f5aae5f8b930ca62943b91fad98c8f78ec11aa08 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 16 Jan 2023 11:32:01 +0100 Subject: [PATCH] Remplace ouf of stock `alert` by Flash message --- .../darkswarm/directives/on_hand.js.coffee | 4 ++-- spec/system/consumer/shopping/cart_spec.rb | 20 +++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee b/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee index 0edae73c22..ad9bd9e9c8 100644 --- a/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee @@ -1,4 +1,4 @@ -angular.module('Darkswarm').directive "ofnOnHand", (StockQuantity) -> +angular.module('Darkswarm').directive "ofnOnHand", (StockQuantity, Messages) -> restrict: 'A' require: "ngModel" scope: true @@ -16,7 +16,7 @@ angular.module('Darkswarm').directive "ofnOnHand", (StockQuantity) -> ngModel.$parsers.push (viewValue) -> available_quantity = scope.available_quantity() if parseInt(viewValue) > available_quantity - alert t("js.insufficient_stock", {on_hand: available_quantity}) + Messages.flash({error: t("js.insufficient_stock", {on_hand: available_quantity})}) viewValue = available_quantity ngModel.$setViewValue viewValue ngModel.$render() diff --git a/spec/system/consumer/shopping/cart_spec.rb b/spec/system/consumer/shopping/cart_spec.rb index 068a31019e..6e371dd953 100644 --- a/spec/system/consumer/shopping/cart_spec.rb +++ b/spec/system/consumer/shopping/cart_spec.rb @@ -203,18 +203,16 @@ describe "full-page cart", js: true do variant2.update!(on_hand: 3, on_demand: false) visit main_app.cart_path - accept_alert 'Insufficient stock available, only 2 remaining' do - within "tr.variant-#{variant.id}" do - fill_in "order_line_items_attributes_0_quantity", with: '4' - end + within "tr.variant-#{variant.id}" do + fill_in "order_line_items_attributes_0_quantity", with: '4' end + expect(page).to have_content "Insufficient stock available, only 2 remaining" expect(page).to have_field "order_line_items_attributes_0_quantity", with: '2' - accept_alert 'Insufficient stock available, only 3 remaining' do - within "tr.variant-#{variant2.id}" do - fill_in "order_line_items_attributes_1_quantity", with: '4' - end + within "tr.variant-#{variant2.id}" do + fill_in "order_line_items_attributes_1_quantity", with: '4' end + expect(page).to have_content "Insufficient stock available, only 3 remaining" expect(page).to have_field "order_line_items_attributes_1_quantity", with: '3' end @@ -225,12 +223,8 @@ describe "full-page cart", js: true do visit main_app.cart_path variant.update! on_hand: 2 - accept_alert do - fill_in "order_line_items_attributes_0_quantity", with: '4' - end + fill_in "order_line_items_attributes_0_quantity", with: '4' click_button 'Update' - - 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