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