From 7302d0552e813f31f2da5b50d78f0c41337c4d94 Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 21 Mar 2014 13:11:04 +1100 Subject: [PATCH] Fixing js specs --- .../admin/bulk_order_management.js.coffee | 6 +++--- .../unit/bulk_order_management_spec.js.coffee | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_order_management.js.coffee b/app/assets/javascripts/admin/bulk_order_management.js.coffee index 918711f415..9fcb38b527 100644 --- a/app/assets/javascripts/admin/bulk_order_management.js.coffee +++ b/app/assets/javascripts/admin/bulk_order_management.js.coffee @@ -117,7 +117,7 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [ $scope.endDate = formatDate end $scope.pendingChanges = pendingChanges $scope.quickSearch = "" - $scope.bulkActions = [ { name: "Delete", callback: $scope.deleteSelected } ] + $scope.bulkActions = [ { name: "Delete", callback: $scope.deleteLineItems } ] $scope.selectedBulkAction = $scope.bulkActions[0] $scope.selectedUnitsVariant = {}; $scope.predicate = "" @@ -213,10 +213,10 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [ ).success (data) -> $scope.lineItems.splice $scope.lineItems.indexOf(lineItem), 1 - $scope.deleteSelected = -> + $scope.deleteLineItems = (lineItems) -> existingState = $scope.confirmDelete $scope.confirmDelete = false - $scope.deleteLineItem lineItem for lineItem in $scope.filteredLineItems when lineItem.checked + $scope.deleteLineItem lineItem for lineItem in lineItems when lineItem.checked $scope.confirmDelete = existingState $scope.allBoxesChecked = -> diff --git a/spec/javascripts/unit/bulk_order_management_spec.js.coffee b/spec/javascripts/unit/bulk_order_management_spec.js.coffee index 7256a3143e..1f15efb2cd 100644 --- a/spec/javascripts/unit/bulk_order_management_spec.js.coffee +++ b/spec/javascripts/unit/bulk_order_management_spec.js.coffee @@ -220,7 +220,7 @@ describe "AdminOrderMgmtCtrl", -> it "calls deletedLineItem for each 'checked' line item", -> spyOn(scope, "deleteLineItem") - scope.deleteSelected() + scope.deleteLineItems(scope.lineItems) expect(scope.deleteLineItem).toHaveBeenCalledWith(line_item2) expect(scope.deleteLineItem).toHaveBeenCalledWith(line_item4) expect(scope.deleteLineItem).not.toHaveBeenCalledWith(line_item1) @@ -232,9 +232,9 @@ describe "AdminOrderMgmtCtrl", -> beforeEach -> line_item1 = { name: "line item 1", checked: false } line_item2 = { name: "line item 2", checked: false } - scope.lineItems = [ line_item1, line_item2 ] + scope.filteredLineItems = [ line_item1, line_item2 ] - it "keeps track of whether all lines items are 'checked' or not", -> + it "keeps track of whether all filtered lines items are 'checked' or not", -> expect(scope.allBoxesChecked()).toEqual false line_item1.checked = true expect(scope.allBoxesChecked()).toEqual false @@ -261,18 +261,24 @@ describe "AdminOrderMgmtCtrl", -> it "returns '' if selectedUnitsVariant has no property 'variant_unit'", -> expect(scope.fulfilled()).toEqual '' + it "returns '' if selectedUnitsVariant has no property 'group_buy_unit_size' or group_buy_unit_size is 0", -> + scope.selectedUnitsVariant = { variant_unit: "weight", group_buy_unit_size: 0 } + expect(scope.fulfilled()).toEqual '' + scope.selectedUnitsVariant = { variant_unit: "weight" } + expect(scope.fulfilled()).toEqual '' + it "returns '', and does not call Math.round if variant_unit is 'items'", -> spyOn(Math,"round") - scope.selectedUnitsVariant = { variant_unit: "items" } + scope.selectedUnitsVariant = { variant_unit: "items", group_buy_unit_size: 10 } expect(scope.fulfilled()).toEqual '' expect(Math.round).not.toHaveBeenCalled() it "calls Math.round() if variant_unit is 'weight' or 'volume'", -> spyOn(Math,"round") - scope.selectedUnitsVariant = { variant_unit: "weight" } + scope.selectedUnitsVariant = { variant_unit: "weight", group_buy_unit_size: 10 } scope.fulfilled() expect(Math.round).toHaveBeenCalled() - scope.selectedUnitsVariant = { variant_unit: "volume" } + scope.selectedUnitsVariant = { variant_unit: "volume", group_buy_unit_size: 10 } scope.fulfilled() expect(Math.round).toHaveBeenCalled()