mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Remplace ouf of stock alert by Flash message
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user