mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-07 07:36:58 +00:00
Line item delete button works
This commit is contained in:
@@ -67,6 +67,18 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
if angular.equals(distributor, order.distributor)
|
||||
order.distributor = distributor
|
||||
break
|
||||
|
||||
$scope.deleteLineItem = (lineItem) ->
|
||||
#if confirm("Are you sure?")
|
||||
$http(
|
||||
method: "DELETE"
|
||||
url: "/api/orders/" + lineItem.order.number + "/line_items/" + lineItem.id
|
||||
).success (data) ->
|
||||
$scope.lineItems.splice $scope.lineItems.indexOf(lineItem), 1
|
||||
lineItem.order.line_items.splice lineItem.order.line_items.indexOf(lineItem), 1
|
||||
#delete $scope.dirtyProducts[product.id] if $scope.dirtyProducts.hasOwnProperty(product.id)
|
||||
#$scope.displayDirtyProducts()
|
||||
|
||||
]
|
||||
|
||||
orderManagementModule.filter "selectFilter", [
|
||||
|
||||
@@ -36,4 +36,4 @@
|
||||
%td.quantity {{ line_item.quantity }}
|
||||
%td.max {{ line_item.max }}
|
||||
%td.actions
|
||||
%a{ :class => "delete-line-item icon-trash no-text" }
|
||||
%a{ 'ng-click' => "deleteLineItem(line_item)", :class => "delete-line-item icon-trash no-text" }
|
||||
@@ -155,6 +155,14 @@ feature %q{
|
||||
it "shows a delete button for each line item" do
|
||||
page.should have_selector "a.delete-line-item", :count => 2
|
||||
end
|
||||
|
||||
it "removes a line item when the relavent delete button is clicked" do
|
||||
first("a.delete-line-item").click
|
||||
page.should_not have_selector "a.delete-line-item", :count => 2
|
||||
page.should have_selector "a.delete-line-item", :count => 1
|
||||
visit '/admin/orders/bulk_management'
|
||||
page.should have_selector "a.delete-line-item", :count => 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -133,4 +133,29 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
distributor: distributor1_order
|
||||
|
||||
scope.matchDistributor order
|
||||
expect(order.distributor is distributor1_list).toEqual true
|
||||
expect(order.distributor is distributor1_list).toEqual true
|
||||
|
||||
describe "deleting a line item", ->
|
||||
order = line_item1 = line_item2 = null
|
||||
beforeEach ->
|
||||
order = { number: "R12345678", line_items: [] }
|
||||
line_item1 = { id: 1, order: order }
|
||||
line_item2 = { id: 2, order: order }
|
||||
order.line_items = [ line_item1, line_item2 ]
|
||||
|
||||
it "sends a delete request via the API", ->
|
||||
httpBackend.expectDELETE("/api/orders/#{line_item1.order.number}/line_items/#{line_item1.id}").respond "nothing"
|
||||
scope.deleteLineItem line_item1
|
||||
httpBackend.flush()
|
||||
|
||||
it "removes line_item from the line_items array of the relevant order object when request is 204", ->
|
||||
httpBackend.expectDELETE("/api/orders/#{line_item1.order.number}/line_items/#{line_item1.id}").respond 204, "NO CONTENT"
|
||||
scope.deleteLineItem line_item1
|
||||
httpBackend.flush()
|
||||
expect(order.line_items).toEqual [line_item2]
|
||||
|
||||
it "does not remove line_item from the line_items array when request is not successful", ->
|
||||
httpBackend.expectDELETE("/api/orders/#{line_item1.order.number}/line_items/#{line_item1.id}").respond 404, "NO CONTENT"
|
||||
scope.deleteLineItem line_item1
|
||||
httpBackend.flush()
|
||||
expect(order.line_items).toEqual [line_item1, line_item2]
|
||||
Reference in New Issue
Block a user