From 8398d8b663fc4555bb0be87c0973c47c44e8cac0 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 19 Jun 2014 14:21:38 -0300 Subject: [PATCH] Karma test for send Controller. Added another test for check handle of addressBook. --- test/mocks/FakeWallet.js | 7 +++ test/test.Wallet.js | 21 ++++++++ test/unit/controllers/controllersSpec.js | 61 ++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 4 deletions(-) diff --git a/test/mocks/FakeWallet.js b/test/mocks/FakeWallet.js index 50a26262b..cfa81371d 100644 --- a/test/mocks/FakeWallet.js +++ b/test/mocks/FakeWallet.js @@ -6,6 +6,13 @@ var FakeWallet = function() { '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000 }; this.name = 'myTESTwullet'; + this.addressBook = { + '2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ' : { + label: 'John', + copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03', + createdTs: 1403102115, + } + }; }; FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) { diff --git a/test/test.Wallet.js b/test/test.Wallet.js index d59f80855..9d1b5401a 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -646,4 +646,25 @@ describe('Wallet model', function() { 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); + }); + }); diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 9ec356896..736cb2cac 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -21,11 +21,9 @@ describe("Unit: Controllers", function() { totalCopayers: 5, spendUnconfirmed: 1, reconnectDelay: 100, - networkName: 'testnet', + networkName: 'testnet' }; - - describe('Backup Controller', function() { var ctrl; beforeEach(inject(function($controller, $rootScope) { @@ -79,7 +77,7 @@ describe("Unit: Controllers", function() { }); describe('Transactions Controller', function() { - var transactionCtrl; + var transactionsCtrl; beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); 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( + '
' + + '' + + '' + + '
' + ); + 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() { var scope, $httpBackendOut; var GH = 'https://api.github.com/repos/bitpay/copay/tags';