Remplace ouf of stock alert by Flash message

This commit is contained in:
Jean-Baptiste Bellet
2023-01-16 11:32:01 +01:00
parent 1e3f754f96
commit f5aae5f8b9
2 changed files with 9 additions and 15 deletions

View File

@@ -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()

View File

@@ -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