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';