fix karma tests
This commit is contained in:
parent
aa43273f8d
commit
bfcd106b6f
4 changed files with 33 additions and 37 deletions
|
|
@ -5,10 +5,10 @@ var preconditions = require('preconditions').singleton();
|
|||
angular.module('copayApp.controllers').controller('SendController',
|
||||
function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService, txStatus) {
|
||||
|
||||
var satToUnit, unitToSat, w;
|
||||
var satToUnit;
|
||||
|
||||
$scope.init = function() {
|
||||
w = $rootScope.wallet;
|
||||
var w = $rootScope.wallet;
|
||||
preconditions.checkState(w);
|
||||
preconditions.checkState(w.settings.unitToSatoshi);
|
||||
|
||||
|
|
@ -16,7 +16,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
$scope.loading = false;
|
||||
$scope.error = $scope.success = null;
|
||||
|
||||
unitToSat = w.settings.unitToSatoshi;
|
||||
satToUnit = 1 / w.settings.unitToSatoshi;
|
||||
|
||||
$scope.alternativeName = w.settings.alternativeName;
|
||||
|
|
@ -32,7 +31,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
$timeout(function() {
|
||||
$scope.setFromUri($rootScope.pendingPayment)
|
||||
$rootScope.pendingPayment = null;
|
||||
},100);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
$scope.setInputs();
|
||||
|
|
@ -45,6 +44,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
|
||||
$scope.setInputs = function() {
|
||||
var w = $rootScope.wallet;
|
||||
var unitToSat = w.settings.unitToSatoshi;
|
||||
/**
|
||||
* Setting the two related amounts as properties prevents an infinite
|
||||
* recursion for watches while preserving the original angular updates
|
||||
|
|
@ -75,7 +76,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
set: function(newValue) {
|
||||
this.__amount = newValue;
|
||||
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
|
||||
|
||||
this.__alternative = parseFloat(
|
||||
(rateService.toFiat(newValue * unitToSat, $scope.alternativeIsoCode)).toFixed(2), 10);
|
||||
} else {
|
||||
|
|
@ -135,6 +135,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
$scope.submitForm = function(form) {
|
||||
var w = $rootScope.wallet;
|
||||
var unitToSat = w.settings.unitToSatoshi;
|
||||
|
||||
if (form.$invalid) {
|
||||
$scope.error = 'Unable to send transaction proposal';
|
||||
|
|
@ -161,9 +163,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
if (err)
|
||||
return $scope.setError(err);
|
||||
|
||||
|
||||
console.log('[send.js.162:status:]', status); //TODO
|
||||
|
||||
$scope.resetForm(status);
|
||||
});
|
||||
};
|
||||
|
|
@ -304,10 +303,13 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
|
||||
$scope.setTopAmount = function() {
|
||||
var w = $rootScope.wallet;
|
||||
var form = $scope.sendForm;
|
||||
form.amount.$setViewValue(w.balanceInfo.topAmount);
|
||||
form.amount.$render();
|
||||
form.amount.$isValid = true;
|
||||
if (form) {
|
||||
form.amount.$setViewValue(w.balanceInfo.topAmount);
|
||||
form.amount.$render();
|
||||
form.amount.$isValid = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.notifyStatus = function(status) {
|
||||
|
|
@ -324,12 +326,13 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
if (msg)
|
||||
$scope.openTxStatusModal(msg);
|
||||
else
|
||||
else
|
||||
$scope.error = status;
|
||||
};
|
||||
|
||||
|
||||
$scope.send = function(ntxid, cb) {
|
||||
var w = $rootScope.wallet;
|
||||
$scope.error = $scope.success = null;
|
||||
$scope.loading = true;
|
||||
$rootScope.txAlertCount = 0;
|
||||
|
|
@ -417,6 +420,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
|
||||
$scope.setFromPayPro = function(uri) {
|
||||
var w = $rootScope.wallet;
|
||||
$scope.fetchingURL = uri;
|
||||
$scope.loading = true;
|
||||
|
||||
|
|
@ -477,6 +481,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
$scope.openAddressBook = function() {
|
||||
var w = $rootScope.wallet;
|
||||
var modalInstance = $modal.open({
|
||||
templateUrl: 'views/modals/address-book.html',
|
||||
windowClass: 'large',
|
||||
|
|
|
|||
|
|
@ -189,16 +189,16 @@ describe("Unit: Controllers", function() {
|
|||
scope.model = {
|
||||
newaddress: null,
|
||||
newlabel: null,
|
||||
address: null,
|
||||
amount: null
|
||||
_address: null,
|
||||
_amount: null
|
||||
};
|
||||
$compile(element)(scope);
|
||||
|
||||
var element2 = angular.element(
|
||||
'<form name="form2">' +
|
||||
'<input type="text" id="address" name="address" ng-model="address" valid-address required>' +
|
||||
'<input type="number" id="amount" name="amount" ng-model="amount" min="1" max="10000000000" required>' +
|
||||
'<input type="number" id="alternative" name="alternative" ng-model="alternative">' +
|
||||
'<input type="text" id="address" name="address" ng-model="_address" valid-address required>' +
|
||||
'<input type="number" id="amount" name="amount" ng-model="_amount" min="1" max="10000000000" required>' +
|
||||
'<input type="number" id="alternative" name="alternative" ng-model="_alternative">' +
|
||||
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
|
||||
'</form>'
|
||||
);
|
||||
|
|
@ -207,7 +207,7 @@ describe("Unit: Controllers", function() {
|
|||
$scope: scope,
|
||||
$modal: {},
|
||||
});
|
||||
|
||||
scope.init();
|
||||
scope.$digest();
|
||||
form = scope.form;
|
||||
sendForm = scope.form2;
|
||||
|
|
@ -215,11 +215,11 @@ describe("Unit: Controllers", function() {
|
|||
}));
|
||||
|
||||
it('should have a SendController controller', function() {
|
||||
expect(scope.loading).equal(false);
|
||||
should.exist(scope.submitForm);
|
||||
});
|
||||
|
||||
it('should have a title', function() {
|
||||
expect(scope.title).equal('Create Transaction Proposal');
|
||||
expect(scope.title);
|
||||
});
|
||||
|
||||
it('should validate address with network', function() {
|
||||
|
|
@ -296,7 +296,8 @@ describe("Unit: Controllers", function() {
|
|||
scope.rateService.whenAvailable(function() {
|
||||
sendForm.amount.$setViewValue(1e6);
|
||||
scope.$digest();
|
||||
expect(scope.alternative).to.equal(2);
|
||||
expect(scope._amount).to.equal(1e6);
|
||||
expect(scope.__alternative).to.equal(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
@ -304,7 +305,8 @@ describe("Unit: Controllers", function() {
|
|||
scope.rateService.whenAvailable(function() {
|
||||
sendForm.alternative.$setViewValue(2);
|
||||
scope.$digest();
|
||||
expect(scope.amount).to.equal(1e6);
|
||||
expect(scope.__alternative).to.equal(2);
|
||||
expect(scope._amount).to.equal(1e6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
@ -511,7 +513,7 @@ describe("Unit: Controllers", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('UriPayment Controller', function() {
|
||||
describe('paymentUriController Controller', function() {
|
||||
var what;
|
||||
beforeEach(inject(function($controller, $rootScope, $location) {
|
||||
scope = $rootScope.$new();
|
||||
|
|
@ -522,7 +524,7 @@ describe("Unit: Controllers", function() {
|
|||
amount: 0.1,
|
||||
message: "a bitcoin donation"
|
||||
};
|
||||
what = $controller('UriPaymentController', {
|
||||
what = $controller('paymentUriController', {
|
||||
$scope: scope,
|
||||
$routeParams: routeParams,
|
||||
$location: {
|
||||
|
|
@ -540,9 +542,7 @@ describe("Unit: Controllers", function() {
|
|||
it('should parse url correctly', function() {
|
||||
should.exist(what);
|
||||
should.exist(scope.pendingPayment);
|
||||
scope.pendingPayment.address.data.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8');
|
||||
scope.pendingPayment.data.amount.should.equal(0.1);
|
||||
scope.pendingPayment.data.message.should.equal('a bitcoin donation');
|
||||
scope.pendingPayment.should.equal('bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8?amount=0.1&message=a bitcoin donation');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -94,9 +94,6 @@ describe("Unit: Testing Directives", function() {
|
|||
form.amount.$setViewValue(800);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(900);
|
||||
expect($scope.notValidAmount).to.equal(null);
|
||||
form.amount.$setViewValue(0.44);
|
||||
expect($scope.notValidAmount).to.equal(null);
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -105,8 +102,6 @@ describe("Unit: Testing Directives", function() {
|
|||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(999999999999);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(0.333);
|
||||
expect($scope.notValidAmount).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -134,19 +129,15 @@ describe("Unit: Testing Directives", function() {
|
|||
|
||||
it('should validate', function() {
|
||||
form.amount.$setViewValue(0.01);
|
||||
expect($scope.notValidAmount).to.equal(null);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(0.039);
|
||||
expect($scope.notValidAmount).to.equal(null);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(100292.039);
|
||||
expect($scope.notValidAmount).to.equal(null);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
});
|
||||
|
||||
it('should not validate', function() {
|
||||
form.amount.$setViewValue(0.039998888888888);
|
||||
expect($scope.notValidAmount).to.equal(true);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(0);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@
|
|||
</button>
|
||||
</form>
|
||||
|
||||
<div ng-if="usingLocalStorage" class="text-gray size-12">
|
||||
<div ng-if="usingLocalStorage" class="text-gray size-12 m10v">
|
||||
* Using this device storage. Change to cloud storage on 'settings'.
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue