mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-03 06:59:14 +00:00
Merge pull request #9634 from binarygit/remove-angular-from-shipping-methods
Remove shipping methods controller
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
angular.module("admin.enterprises")
|
||||
.controller "enterpriseCtrl", ($scope, $http, $window, NavigationCheck, enterprise, Enterprises, EnterprisePaymentMethods, EnterpriseShippingMethods, SideMenu, StatusMessage, RequestMonitor) ->
|
||||
.controller "enterpriseCtrl", ($scope, $http, $window, NavigationCheck, enterprise, Enterprises, EnterprisePaymentMethods, SideMenu, StatusMessage, RequestMonitor) ->
|
||||
$scope.Enterprise = enterprise
|
||||
$scope.Enterprises = Enterprises
|
||||
$scope.PaymentMethods = EnterprisePaymentMethods.paymentMethods
|
||||
$scope.ShippingMethods = EnterpriseShippingMethods.shippingMethods
|
||||
$scope.navClear = NavigationCheck.clear
|
||||
$scope.menu = SideMenu
|
||||
$scope.newManager = { id: null, email: (t('add_manager')) }
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
angular.module("admin.enterprises")
|
||||
.factory "EnterpriseShippingMethods", (enterprise, ShippingMethods) ->
|
||||
new class EnterpriseShippingMethods
|
||||
shippingMethods: ShippingMethods.all
|
||||
|
||||
constructor: ->
|
||||
for shipping_method in @shippingMethods
|
||||
shipping_method.selected = shipping_method.id in enterprise.shipping_method_ids
|
||||
|
||||
displayColor: ->
|
||||
if @shippingMethods.length > 0 && @selectedCount() > 0
|
||||
"blue"
|
||||
else
|
||||
"red"
|
||||
|
||||
selectedCount: ->
|
||||
@shippingMethods.reduce (count, shipping_method) ->
|
||||
count++ if shipping_method.selected
|
||||
count
|
||||
, 0
|
||||
@@ -1,3 +0,0 @@
|
||||
angular.module("admin.shippingMethods").controller "shippingMethodsCtrl", ($scope, ShippingMethods) ->
|
||||
$scope.findShippingMethodByID = (id) ->
|
||||
$scope.ShippingMethod = ShippingMethods.byID[id]
|
||||
@@ -9,9 +9,9 @@
|
||||
%th
|
||||
%tbody
|
||||
- @shipping_methods.each do |shipping_method|
|
||||
%tr{ ng: { controller: 'shippingMethodsCtrl', init: "findShippingMethodByID(#{shipping_method.id})" } }
|
||||
%tr
|
||||
%td= shipping_method.name
|
||||
%td= f.check_box :shipping_method_ids, { :multiple => true, 'ng-model' => 'ShippingMethod.selected' }, shipping_method.id, nil
|
||||
%td= f.check_box :shipping_method_ids, { :multiple => true }, shipping_method.id, nil
|
||||
%td= link_to t(:edit), edit_admin_shipping_method_path(shipping_method)
|
||||
%br
|
||||
.row
|
||||
|
||||
@@ -3,7 +3,6 @@ describe "enterpriseCtrl", ->
|
||||
scope = null
|
||||
enterprise = null
|
||||
PaymentMethods = null
|
||||
ShippingMethods = null
|
||||
Enterprises = null
|
||||
StatusMessage = null
|
||||
|
||||
@@ -16,15 +15,13 @@ describe "enterpriseCtrl", ->
|
||||
id: 98
|
||||
PaymentMethods =
|
||||
paymentMethods: "payment methods"
|
||||
ShippingMethods =
|
||||
shippingMethods: "shipping methods"
|
||||
receivesNotifications = 99
|
||||
|
||||
inject ($rootScope, $controller, _Enterprises_, _StatusMessage_) ->
|
||||
scope = $rootScope
|
||||
Enterprises = _Enterprises_
|
||||
StatusMessage = _StatusMessage_
|
||||
ctrl = $controller "enterpriseCtrl", {$scope: scope, enterprise: enterprise, EnterprisePaymentMethods: PaymentMethods, EnterpriseShippingMethods: ShippingMethods, Enterprises: Enterprises, StatusMessage: StatusMessage, receivesNotifications: receivesNotifications}
|
||||
ctrl = $controller "enterpriseCtrl", {$scope: scope, enterprise: enterprise, EnterprisePaymentMethods: PaymentMethods, Enterprises: Enterprises, StatusMessage: StatusMessage, receivesNotifications: receivesNotifications}
|
||||
|
||||
describe "initialisation", ->
|
||||
it "stores enterprise", ->
|
||||
@@ -33,9 +30,6 @@ describe "enterpriseCtrl", ->
|
||||
it "stores payment methods", ->
|
||||
expect(scope.PaymentMethods).toBe PaymentMethods.paymentMethods
|
||||
|
||||
it "stores shipping methods", ->
|
||||
expect(scope.ShippingMethods).toBe ShippingMethods.shippingMethods
|
||||
|
||||
describe "removing logo", ->
|
||||
deferred = null
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
describe "EnterpriseShippingMethods service", ->
|
||||
enterprise = null
|
||||
ShippingMethods = null
|
||||
EnterpriseShippingMethods = null
|
||||
|
||||
beforeEach ->
|
||||
enterprise =
|
||||
shipping_method_ids: [ 1, 3 ]
|
||||
ShippingMethods =
|
||||
all: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
|
||||
|
||||
module 'admin.enterprises'
|
||||
module ($provide) ->
|
||||
$provide.value 'ShippingMethods', ShippingMethods
|
||||
$provide.value 'enterprise', enterprise
|
||||
null
|
||||
|
||||
inject (_EnterpriseShippingMethods_) ->
|
||||
EnterpriseShippingMethods = _EnterpriseShippingMethods_
|
||||
|
||||
describe "selecting shipping methods", ->
|
||||
it "sets the selected property of each shipping method", ->
|
||||
expect(ShippingMethods.all[0].selected).toBe true
|
||||
expect(ShippingMethods.all[1].selected).toBe false
|
||||
expect(ShippingMethods.all[2].selected).toBe true
|
||||
expect(ShippingMethods.all[3].selected).toBe false
|
||||
|
||||
describe "determining shipping method colour", ->
|
||||
it "returns 'blue' when at least one shipping method is selected", ->
|
||||
spyOn(EnterpriseShippingMethods, "selectedCount").and.returnValue 1
|
||||
expect(EnterpriseShippingMethods.displayColor()).toBe "blue"
|
||||
|
||||
it "returns 'red' when no shipping methods are selected", ->
|
||||
spyOn(EnterpriseShippingMethods, "selectedCount").and.returnValue 0
|
||||
expect(EnterpriseShippingMethods.displayColor()).toBe "red"
|
||||
|
||||
it "returns 'red' when no shipping methods exist", ->
|
||||
EnterpriseShippingMethods.shippingMethods = []
|
||||
spyOn(EnterpriseShippingMethods, "selectedCount").and.returnValue 1
|
||||
expect(EnterpriseShippingMethods.displayColor()).toBe "red"
|
||||
|
||||
describe "counting selected shipping methods", ->
|
||||
it "counts only shipping methods with selected: true", ->
|
||||
expect(EnterpriseShippingMethods.selectedCount()).toBe 2
|
||||
Reference in New Issue
Block a user