add tests and fix some minor issues
This commit is contained in:
parent
433f1570de
commit
8b25b5932f
3 changed files with 29 additions and 6 deletions
|
|
@ -1,20 +1,18 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('UriPaymentController', function($rootScope, $scope, $routeParams) {
|
angular.module('copayApp.controllers').controller('UriPaymentController', function($rootScope, $scope, $routeParams) {
|
||||||
var data = $routeParams.data;
|
var data = decodeURIComponent($routeParams.data);
|
||||||
var splitDots = data.split(':');
|
var splitDots = data.split(':');
|
||||||
$scope.protocol = splitDots[0];
|
$scope.protocol = splitDots[0];
|
||||||
data = splitDots[1];
|
data = splitDots[1];
|
||||||
var splitQuestion = data.split('?');
|
var splitQuestion = data.split('?');
|
||||||
$scope.address = splitQuestion[0];
|
$scope.address = splitQuestion[0];
|
||||||
data = decodeURIComponent(splitQuestion[1]);
|
|
||||||
var search = splitQuestion[1];
|
var search = splitQuestion[1];
|
||||||
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
|
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
|
||||||
function(key, value) {
|
function(key, value) {
|
||||||
return key === "" ? value : decodeURIComponent(value);
|
return key === "" ? value : decodeURIComponent(value);
|
||||||
});
|
});
|
||||||
$scope.amount = data.amount;
|
$scope.amount = parseInt(data.amount);
|
||||||
$scope.message = data.message;
|
$scope.message = data.message;
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ var UriHandler = function() {};
|
||||||
UriHandler.prototype.register = function() {
|
UriHandler.prototype.register = function() {
|
||||||
var base = window.location.origin + '/';
|
var base = window.location.origin + '/';
|
||||||
var url = base + '#/uri_payment/%s';
|
var url = base + '#/uri_payment/%s';
|
||||||
console.log(url);
|
|
||||||
navigator.registerProtocolHandler('bitcoin',
|
navigator.registerProtocolHandler('bitcoin',
|
||||||
url, 'Copay');
|
url, 'Copay');
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ describe("Unit: Controllers", function() {
|
||||||
'<form name="form">' +
|
'<form name="form">' +
|
||||||
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||||
'</form>'
|
'</form>'
|
||||||
);
|
);
|
||||||
scope.model = {
|
scope.model = {
|
||||||
amount: null
|
amount: null
|
||||||
};
|
};
|
||||||
|
|
@ -368,4 +368,30 @@ describe("Unit: Controllers", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('UriPayment Controller', function() {
|
||||||
|
var what;
|
||||||
|
beforeEach(inject(function($controller, $rootScope) {
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
var routeParams = {
|
||||||
|
data: 'bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8%3Famount=1&message=a%20bitcoin%20donation'
|
||||||
|
};
|
||||||
|
what = $controller('UriPaymentController', {
|
||||||
|
$scope: scope,
|
||||||
|
$routeParams: routeParams
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should exist', function() {
|
||||||
|
should.exist(what);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse url correctly', function() {
|
||||||
|
should.exist(what);
|
||||||
|
scope.protocol.should.equal('bitcoin');
|
||||||
|
scope.address.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8');
|
||||||
|
scope.amount.should.equal(1);
|
||||||
|
scope.message.should.equal('a bitcoin donation');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue