'use strict'; // // test/unit/directives/directivesSpec.js // describe("Unit: Testing Directives", function() { var $scope, form; beforeEach(module('copayApp.directives')); beforeEach(inject(function($rootScope) { var w = {}; w.isComplete = sinon.stub().returns(true); w.privateKey = {}; w.settings = { unitToSatoshi: 100, unitDecimals: 2, alternativeName: 'US Dollar', alternativeIsoCode: 'USD', }; w.addressBook = { 'juan': '1', }; w.totalCopayers = 2; w.getMyCopayerNickname = sinon.stub().returns('nickname'); w.getMyCopayerId = sinon.stub().returns('id'); w.privateKey.toObj = sinon.stub().returns({ wallet: 'mock' }); w.getSecret = sinon.stub().returns('secret'); w.getName = sinon.stub().returns('fakeWallet'); w.exportEncrypted = sinon.stub().returns('1234567'); w.getTransactionHistory = sinon.stub().yields({}); w.getNetworkName = sinon.stub().returns('testnet'); w.createTx = sinon.stub().yields(null); w.sendTx = sinon.stub().yields(null); w.requiresMultipleSignatures = sinon.stub().returns(true); w.getTxProposals = sinon.stub().returns([1,2,3]); $rootScope.wallet = w; })); describe('Validate Address', function() { beforeEach(inject(function($compile, $rootScope) { $scope = $rootScope; var element = angular.element( '
' ); $scope.model = { address: null }; $compile(element)($scope); $scope.$digest(); form = $scope.form; })); it('should validate with network', inject(function($rootScope) { $rootScope.wallet.getNetworkName = sinon.stub().returns('testnet'); form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); expect(form.address.$invalid).to.equal(false); })); it('should not validate with other network', inject(function($rootScope) { $rootScope.wallet.getNetworkName = sinon.stub().returns('livenet'); form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); expect(form.address.$invalid).to.equal(true); })); it('should not validate random', function() { form.address.$setViewValue('thisisaninvalidaddress'); expect(form.address.$invalid).to.equal(true); }); }); describe('Validate Amount', function() { describe('Unit: bits', function() { beforeEach(inject(function($compile, $rootScope) { $scope = $rootScope; var element = angular.element( '' ); $scope.model = { amount: null }; $compile(element)($scope); $scope.$digest(); form = $scope.form; })); it('should validate', function() { form.amount.$setViewValue(100); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(800); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(900); }); it('should not validate', function() { form.amount.$setViewValue(0); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(999999999999); expect(form.amount.$invalid).to.equal(true); }); }); describe('Unit: BTC', function() { beforeEach(inject(function($compile, $rootScope) { $scope = $rootScope; var w = $rootScope.wallet; w.settings.unitToSatoshi = 100000000; w.settings.unitName = 'BTC'; w.settings.unitDecimals = 8; $rootScope.availableBalance = 0.04; var element = angular.element( '' ); $scope.model = { amount: null }; $compile(element)($scope); $scope.$digest(); form = $scope.form; })); it('should validate', function() { form.amount.$setViewValue(0.01); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(0.039); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(100292.039); expect(form.amount.$invalid).to.equal(false); }); it('should not validate', function() { form.amount.$setViewValue(0.039998888888888); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(0); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(0.0); expect(form.amount.$invalid).to.equal(true); }); }); }); describe('Contact directive', function() { var element1, element2; beforeEach(inject(function($compile, $rootScope) { $rootScope.wallet = { addressBook: { '2MtBXKLtZuXGDshUcyH6yq7aZ33Snbb49pT': { label: ':)' } } } element1 = angular.element( '