'use strict'; // // test/unit/directives/directivesSpec.js // describe("Unit: Testing Directives", function() { var $scope, form; beforeEach(module('copayApp.directives')); beforeEach(function() { config.unitToSatoshi = 100; config.unitName = 'bits'; }); describe('Check config', function() { it('unit should be set to BITS in config.js', function() { expect(config.unitToSatoshi).to.equal(100); expect(config.unitName).to.equal('bits'); }); }); 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', function() { config.networkName = 'testnet'; form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); expect(form.address.$invalid).to.equal(false); }); it('should not validate with other network', function() { config.networkName = '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; $rootScope.availableBalance = 1000; 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); expect($scope.notEnoughAmount).to.equal(null); }); it('should not validate', function() { form.amount.$setViewValue(0); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(9999999999); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(901); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(1000); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(901); expect($scope.notEnoughAmount).to.equal(true); }); }); describe('Unit: BTC', function() { beforeEach(inject(function($compile, $rootScope) { config.unitToSatoshi = 100000000; config.unitName = 'BTC'; $scope = $rootScope; $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($scope.notEnoughAmount).to.equal(null); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(0.039); expect($scope.notEnoughAmount).to.equal(null); expect(form.amount.$invalid).to.equal(false); }); it('should not validate', function() { form.amount.$setViewValue(0.03999); expect($scope.notEnoughAmount).to.equal(true); 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); form.amount.$setViewValue(0.05); expect($scope.notEnoughAmount).to.equal(true); 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( '' ); element2 = angular.element( '' ); $compile(element1)($rootScope); $compile(element2)($rootScope); $rootScope.$digest(); })); it('should replace the content', function() { expect(element1.html()).to.equal(':)'); expect(element2.html()).to.equal('2MvCKdnwEMiaexi247gi738U6pwUFZxbhXn'); }); }); describe('Password strength', function() { beforeEach(inject(function($compile, $rootScope) { $scope = $rootScope; var element = angular.element( '' ); $compile(element)($scope); $scope.$digest(); })); it('should check very weak password', function() { $scope.password = 'asd'; $scope.$digest(); expect($scope.passwordStrength).to.equal('Very Weak, that\'s short'); }); it('should check weak password', function() { $scope.password = 'asdasdASDASD'; $scope.$digest(); expect($scope.passwordStrength).to.equal('Weak, add numerals'); }); it('should check medium password', function() { $scope.password = 'asdasdA1'; $scope.$digest(); expect($scope.passwordStrength).to.equal('Medium, add punctuation'); }); it('should check strong password', function() { $scope.password = 'asdasdASDASD1{'; $scope.$digest(); expect($scope.passwordStrength).to.equal('Strong, add punctuation'); }); }); describe('Match Password Inputs', function() { beforeEach(inject(function($compile, $rootScope) { $scope = $rootScope; $rootScope.availableBalance = 1000; var element = angular.element( '
' + '' + '' + '
' ); $scope.model = { walletPassword: null, walletPasswordConfirm: null }; $compile(element)($scope); $scope.$digest(); form = $scope.form; })); it('should not validate', function() { form.walletPassword.$setViewValue('mysecretpassword'); form.walletPasswordConfirm.$setViewValue('mySecretPassword'); $scope.$digest(); expect(form.walletPasswordConfirm.$invalid).to.equal(true); }); it('should validate', function() { form.walletPassword.$setViewValue('mysecretpassword123'); form.walletPasswordConfirm.$setViewValue('mysecretpassword123'); $scope.$digest(); expect(form.walletPasswordConfirm.$invalid).to.equal(false); }); }); });