Merge pull request #9506 from binarygit/remove-angular-from-payment-methods

Remove angular from payment methods
This commit is contained in:
Rachel Arnould
2022-10-11 13:13:26 +02:00
committed by GitHub
6 changed files with 3 additions and 76 deletions

View File

@@ -1,8 +1,7 @@
angular.module("admin.enterprises")
.controller "enterpriseCtrl", ($scope, $http, $window, NavigationCheck, enterprise, Enterprises, EnterprisePaymentMethods, SideMenu, StatusMessage, RequestMonitor) ->
.controller "enterpriseCtrl", ($scope, $http, $window, NavigationCheck, enterprise, Enterprises, SideMenu, StatusMessage, RequestMonitor) ->
$scope.Enterprise = enterprise
$scope.Enterprises = Enterprises
$scope.PaymentMethods = EnterprisePaymentMethods.paymentMethods
$scope.navClear = NavigationCheck.clear
$scope.menu = SideMenu
$scope.newManager = { id: null, email: (t('add_manager')) }

View File

@@ -1,20 +0,0 @@
angular.module("admin.enterprises")
.factory "EnterprisePaymentMethods", (enterprise, PaymentMethods) ->
new class EnterprisePaymentMethods
paymentMethods: PaymentMethods.all
constructor: ->
for payment_method in @paymentMethods
payment_method.selected = payment_method.id in enterprise.payment_method_ids
displayColor: ->
if @paymentMethods.length > 0 && @selectedCount() > 0
"blue"
else
"red"
selectedCount: ->
@paymentMethods.reduce (count, payment_method) ->
count++ if payment_method.selected
count
, 0

View File

@@ -1,3 +0,0 @@
angular.module("admin.paymentMethods").controller "paymentMethodsCtrl", ($scope, PaymentMethods) ->
$scope.findPaymentMethodByID = (id) ->
$scope.PaymentMethod = PaymentMethods.byID[id]

View File

@@ -10,9 +10,9 @@
%th
%tbody
- @payment_methods.each do |payment_method|
%tr{ ng: { controller: 'paymentMethodsCtrl', init: "findPaymentMethodByID(#{payment_method.id})" } }
%tr
%td= payment_method.name
%td= f.check_box :payment_method_ids, { multiple: true, 'ng-model' => 'PaymentMethod.selected' }, payment_method.id, nil
%td= f.check_box :payment_method_ids, { multiple: true }, payment_method.id, nil
%td= link_to t(:edit), edit_admin_payment_method_path(payment_method)
%br
.row

View File

@@ -13,8 +13,6 @@ describe "enterpriseCtrl", ->
sells: "none"
owner:
id: 98
PaymentMethods =
paymentMethods: "payment methods"
receivesNotifications = 99
inject ($rootScope, $controller, _Enterprises_, _StatusMessage_) ->
@@ -27,9 +25,6 @@ describe "enterpriseCtrl", ->
it "stores enterprise", ->
expect(scope.Enterprise).toEqual enterprise
it "stores payment methods", ->
expect(scope.PaymentMethods).toBe PaymentMethods.paymentMethods
describe "removing logo", ->
deferred = null

View File

@@ -1,44 +0,0 @@
describe "EnterprisePaymentMethods service", ->
enterprise = null
PaymentMethods = null
EnterprisePaymentMethods = null
beforeEach ->
enterprise =
payment_method_ids: [ 1, 3 ]
PaymentMethods =
all: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
module 'admin.enterprises'
module ($provide) ->
$provide.value 'PaymentMethods', PaymentMethods
$provide.value 'enterprise', enterprise
null
inject (_EnterprisePaymentMethods_) ->
EnterprisePaymentMethods = _EnterprisePaymentMethods_
describe "selecting payment methods", ->
it "sets the selected property of each payment method", ->
expect(PaymentMethods.all[0].selected).toBe true
expect(PaymentMethods.all[1].selected).toBe false
expect(PaymentMethods.all[2].selected).toBe true
expect(PaymentMethods.all[3].selected).toBe false
describe "determining payment method colour", ->
it "returns 'blue' when at least one payment method is selected", ->
spyOn(EnterprisePaymentMethods, "selectedCount").and.returnValue 1
expect(EnterprisePaymentMethods.displayColor()).toBe "blue"
it "returns 'red' when no payment methods are selected", ->
spyOn(EnterprisePaymentMethods, "selectedCount").and.returnValue 0
expect(EnterprisePaymentMethods.displayColor()).toBe "red"
it "returns 'red' when no payment methods exist", ->
EnterprisePaymentMethods.paymentMethods = []
spyOn(EnterprisePaymentMethods, "selectedCount").and.returnValue 1
expect(EnterprisePaymentMethods.displayColor()).toBe "red"
describe "counting selected payment methods", ->
it "counts only payment methods with selected: true", ->
expect(EnterprisePaymentMethods.selectedCount()).toBe 2