diff --git a/app/assets/javascripts/admin/bulk_order_management.js.coffee b/app/assets/javascripts/admin/bulk_order_management.js.coffee index 3953c64f1d..33a4c2552d 100644 --- a/app/assets/javascripts/admin/bulk_order_management.js.coffee +++ b/app/assets/javascripts/admin/bulk_order_management.js.coffee @@ -202,18 +202,18 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [ $scope.deleteSelected = -> existingState = $scope.confirmDelete $scope.confirmDelete = false - $scope.deleteLineItem lineItem for lineItem in $scope.lineItems when lineItem.checked + $scope.deleteLineItem lineItem for lineItem in $scope.filteredLineItems when lineItem.checked $scope.confirmDelete = existingState $scope.allBoxesChecked = -> - checkedCount = $scope.lineItems.reduce (count,lineItem) -> + checkedCount = $scope.filteredLineItems.reduce (count,lineItem) -> count + (if lineItem.checked then 1 else 0 ) , 0 - checkedCount == $scope.lineItems.length + checkedCount == $scope.filteredLineItems.length $scope.toggleAllCheckboxes = -> changeTo = !$scope.allBoxesChecked() - lineItem.checked = changeTo for lineItem in $scope.lineItems + lineItem.checked = changeTo for lineItem in $scope.filteredLineItems $scope.setSelectedUnitsVariant = (unitsVariant) -> $scope.selectedUnitsVariant = unitsVariant diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 3316523fe2..1f44877cc7 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -392,6 +392,27 @@ feature %q{ page.should_not have_selector "tr#li_#{li2.id}", visible: true end end + + context "when a filter has been applied" do + it "only toggles checkboxes which are in filteredLineItems" do + fill_in "quick_search", with: o1.number + check "toggle_bulk" + fill_in "quick_search", with: '' + find("tr#li_#{li1.id} input[type='checkbox'][name='bulk']").checked?.should == true + find("tr#li_#{li2.id} input[type='checkbox'][name='bulk']").checked?.should == false + find("input[type='checkbox'][name='toggle_bulk']").checked?.should == false + end + + it "only applies the delete action to filteredLineItems" do + check "toggle_bulk" + fill_in "quick_search", with: o1.number + select "Delete", :from => "bulk_actions" + click_button "bulk_execute" + fill_in "quick_search", with: '' + page.should_not have_selector "tr#li_#{li1.id}", visible: true + page.should have_selector "tr#li_#{li2.id}", visible: true + end + end end context "using action buttons" do @@ -409,7 +430,7 @@ feature %q{ page.should have_selector "a.delete-line-item", :count => 2 end - it "removes a line item when the relavent delete button is clicked" do + it "removes a line item when the relevant 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