mirror of https://github.com/BTCPrivate/copay.git
Karma test for send Controller. Added another test for check handle of addressBook.
This commit is contained in:
parent
f1b92ac67f
commit
8398d8b663
|
@ -6,6 +6,13 @@ var FakeWallet = function() {
|
||||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||||
};
|
};
|
||||||
this.name = 'myTESTwullet';
|
this.name = 'myTESTwullet';
|
||||||
|
this.addressBook = {
|
||||||
|
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ' : {
|
||||||
|
label: 'John',
|
||||||
|
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||||
|
createdTs: 1403102115,
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) {
|
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) {
|
||||||
|
|
|
@ -646,4 +646,25 @@ describe('Wallet model', function() {
|
||||||
w.addressBook[key].copayerId.should.equal(-1);
|
w.addressBook[key].copayerId.should.equal(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handle network addressBook correctly', function() {
|
||||||
|
var w = createW();
|
||||||
|
var data = {
|
||||||
|
walletId: w.id,
|
||||||
|
addressBook: {
|
||||||
|
'msj42CCGruhRsFrGATiUuh25dtxYtnpbTx' : {
|
||||||
|
label: 'Faucet',
|
||||||
|
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||||
|
createdTs: 1403102115,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type: 'addressbook'
|
||||||
|
};
|
||||||
|
Object.keys(w.addressBook).length.should.equal(2);
|
||||||
|
w._handleAddressBook('senderID', data, true);
|
||||||
|
Object.keys(w.addressBook).length.should.equal(3);
|
||||||
|
data.addressBook['msj42CCGruhRsFrGATiUuh25dtxYtnpbTx'].createdTs = 1403102215;
|
||||||
|
w._handleAddressBook('senderID', data, true);
|
||||||
|
Object.keys(w.addressBook).length.should.equal(3);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,11 +21,9 @@ describe("Unit: Controllers", function() {
|
||||||
totalCopayers: 5,
|
totalCopayers: 5,
|
||||||
spendUnconfirmed: 1,
|
spendUnconfirmed: 1,
|
||||||
reconnectDelay: 100,
|
reconnectDelay: 100,
|
||||||
networkName: 'testnet',
|
networkName: 'testnet'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('Backup Controller', function() {
|
describe('Backup Controller', function() {
|
||||||
var ctrl;
|
var ctrl;
|
||||||
beforeEach(inject(function($controller, $rootScope) {
|
beforeEach(inject(function($controller, $rootScope) {
|
||||||
|
@ -79,7 +77,7 @@ describe("Unit: Controllers", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Transactions Controller', function() {
|
describe('Transactions Controller', function() {
|
||||||
var transactionCtrl;
|
var transactionsCtrl;
|
||||||
beforeEach(inject(function($controller, $rootScope) {
|
beforeEach(inject(function($controller, $rootScope) {
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
transactionsCtrl = $controller('TransactionsController', {
|
transactionsCtrl = $controller('TransactionsController', {
|
||||||
|
@ -97,6 +95,61 @@ describe("Unit: Controllers", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Send Controller', function() {
|
||||||
|
var scope, form;
|
||||||
|
beforeEach(angular.mock.module('copayApp'));
|
||||||
|
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller){
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
$rootScope.wallet = new FakeWallet(config);
|
||||||
|
var element = angular.element(
|
||||||
|
'<form name="form">' +
|
||||||
|
'<input type="text" id="newaddress" name="newaddress" ng-disabled="loading" placeholder="Address" ng-model="newaddress" valid-address required>' +
|
||||||
|
'<input type="text" id="newlabel" name="newlabel" ng-disabled="loading" placeholder="Label" ng-model="newlabel" required>' +
|
||||||
|
'</form>'
|
||||||
|
);
|
||||||
|
scope.model = {
|
||||||
|
newaddress: null,
|
||||||
|
newlabel: null
|
||||||
|
};
|
||||||
|
$compile(element)(scope);
|
||||||
|
$controller('SendController', {$scope: scope});
|
||||||
|
scope.$digest();
|
||||||
|
form = scope.form;
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should have a SendController controller', function() {
|
||||||
|
expect(scope.loading).equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a title', function() {
|
||||||
|
expect(scope.title).equal('Send');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if wallet has addressBook', function() {
|
||||||
|
expect(scope.showAddressBook()).equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate address', function() {
|
||||||
|
form.newaddress.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||||
|
expect(form.newaddress.$invalid).to.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not validate address', function() {
|
||||||
|
form.newaddress.$setViewValue('thisisaninvalidaddress');
|
||||||
|
expect(form.newaddress.$invalid).to.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate label', function() {
|
||||||
|
form.newlabel.$setViewValue('John');
|
||||||
|
expect(form.newlabel.$invalid).to.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not validate label', function() {
|
||||||
|
expect(form.newlabel.$invalid).to.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe("Unit: Header Controller", function() {
|
describe("Unit: Header Controller", function() {
|
||||||
var scope, $httpBackendOut;
|
var scope, $httpBackendOut;
|
||||||
var GH = 'https://api.github.com/repos/bitpay/copay/tags';
|
var GH = 'https://api.github.com/repos/bitpay/copay/tags';
|
||||||
|
|
Loading…
Reference in New Issue