Add controller tests (#4205)

* add walletHome test template

* add create test

* add fixtures

* do not mock parseSecret

* better hash

* use fixtures for create controller test

* add import test

* stubs reset

* add more controller tests

* Remove $state dependency

* refactore fixtures + profiles

* add backup.js test

* update bwc

* rm log
This commit is contained in:
Matias Alejo Garcia 2016-05-20 11:50:55 -03:00
commit aec2aac47b
20 changed files with 2265 additions and 28 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('backupController',
function($rootScope, $scope, $timeout, $log, $state, $compile, go, lodash, profileService, gettext, bwcService, bwsError, walletService) {
function($rootScope, $scope, $timeout, $document, $log, $state, $compile, go, lodash, profileService, gettext, bwcService, bwsError, walletService) {
var self = this;
var fc = profileService.focusedClient;
@ -101,15 +101,15 @@ angular.module('copayApp.controllers').controller('backupController',
}
function resetAllButtons() {
document.getElementById('addWord').innerHTML = '';
var nodes = document.getElementById("buttons").getElementsByTagName('button');
$document.getElementById('addWord').innerHTML = '';
var nodes = $document.getElementById("buttons").getElementsByTagName('button');
lodash.each(nodes, function(n) {
document.getElementById(n.id).disabled = false;
$document.getElementById(n.id).disabled = false;
});
}
self.enableButton = function(word) {
document.getElementById(word).disabled = false;
$document.getElementById(word).disabled = false;
lodash.remove(customWords, function(v) {
return v == word;
});
@ -120,7 +120,7 @@ angular.module('copayApp.controllers').controller('backupController',
index: index,
word: word
};
document.getElementById(index + word).disabled = true;
$document.getElementById(index + word).disabled = true;
customWords.push(element);
self.addButton(index, word);
}
@ -129,13 +129,13 @@ angular.module('copayApp.controllers').controller('backupController',
var btnhtml = '<button class="button radius tiny words" ng-disabled="wordsC.disableButtons"' +
'data-ng-click="wordsC.removeButton($event)" id="_' + index + word + '" > ' + word + ' </button>';
var temp = $compile(btnhtml)($scope);
angular.element(document.getElementById('addWord')).append(temp);
angular.element($document.getElementById('addWord')).append(temp);
self.shouldContinue();
}
self.removeButton = function(event) {
var id = (event.target.id);
document.getElementById(id).remove();
$document.getElementById(id).remove();
self.enableButton(id.substring(1));
lodash.remove(customWords, function(d) {
return d.index == id.substring(1, 3);

View file

@ -96,6 +96,7 @@ angular.module('copayApp.controllers').controller('createController',
myName: $scope.totalCopayers > 1 ? $scope.myName : null,
networkName: $scope.isTestnet ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl,
walletPrivKey: $scope._walletPrivKey, // Only for testing
};
var setSeed = self.seedSourceId == 'set';
if (setSeed) {
@ -159,6 +160,7 @@ angular.module('copayApp.controllers').controller('createController',
this._create = function(opts) {
self.loading = true;
$timeout(function() {
profileService.createWallet(opts, function(err, walletId) {
self.loading = false;
if (err) {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, latestReleaseService, bwcService, pushNotificationsService, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, nodeWebkit, addonManager, isChromeApp, bwsError, txFormatService, uxLanguage, $state, glideraService, coinbaseService, isMobile, addressbookService, walletService) {
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, latestReleaseService, bwcService, pushNotificationsService, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, nodeWebkit, addonManager, isChromeApp, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, isMobile, addressbookService, walletService) {
var self = this;
var SOFT_CONFIRMATION_LIMIT = 12;
var errors = bwcService.getErrors();
@ -156,7 +156,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$log.debug('Wallet not complete BEFORE update... redirecting');
go.path('copayers');
} else {
if ($state.is('copayers')) {
if (go.is('copayers')) {
$log.debug('Wallet Complete BEFORE update... redirect to home');
go.walletHome();
}
@ -169,7 +169,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$log.debug('Wallet not complete after update... redirecting');
go.path('copayers');
} else {
if ($state.is('copayers')) {
if (go.is('copayers')) {
$log.debug('Wallet Complete after update... redirect to home');
go.walletHome();
}
@ -211,7 +211,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, 300);
}
if (!self.tab || !$state.is('walletHome'))
if (!self.tab || go.is('walletHome'))
self.tab = 'walletHome';
var changeTab = function() {
@ -235,7 +235,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$emit('Local/TabChanged', tab);
};
if (switchState && !$state.is('walletHome')) {
if (switchState && go.is('walletHome')) {
go.path('walletHome', function() {
changeTab();
});

View file

@ -84,7 +84,9 @@ angular.module('copayApp.controllers').controller('joinController',
opts.passphrase = form.createPassphrase.$modelValue;
}
if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
this.error = gettext('Please enter the wallet recovery phrase');
return;
}
@ -93,6 +95,7 @@ angular.module('copayApp.controllers').controller('joinController',
var account = $scope.account;
if (!account || account < 1) {
this.error = gettext('Invalid account number');
return;
}
@ -114,6 +117,7 @@ angular.module('copayApp.controllers').controller('joinController',
self._join(opts);
});
} else {
self._join(opts);
}
};
@ -121,6 +125,8 @@ angular.module('copayApp.controllers').controller('joinController',
this._join = function(opts) {
self.loading = true;
$timeout(function() {
console.log('[join.js.124]', opts); //TODO
profileService.joinWallet(opts, function(err) {
if (err) {
self.loading = false;

View file

@ -38,6 +38,10 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
}
};
root.is = function(name) {
return $state.is(name);
};
root.path = function(path, cb) {
$state.transitionTo(path)
.then(function() {

View file

@ -148,9 +148,8 @@ angular.module('copayApp.services')
root.isDisclaimerAccepted(function(val) {
if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
} else {
return cb();
}
}
return cb();
});
});
});
@ -306,7 +305,8 @@ angular.module('copayApp.services')
if (err) return cb(err);
walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, {
network: opts.networkName
network: opts.networkName,
walletPrivKey: opts.walletPrivKey,
}, function(err, secret) {
if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb);
@ -571,6 +571,7 @@ angular.module('copayApp.services')
if (err) return cb(err);
root.bindProfile(p, function(err) {
// ignore NONAGREEDDISCLAIMER
storageService.storeNewProfile(p, function(err) {
return cb(err);
});
@ -588,7 +589,6 @@ angular.module('copayApp.services')
root.isDisclaimerAccepted = function(cb) {
var disclaimerAccepted = root.profile && root.profile.disclaimerAccepted;
if (disclaimerAccepted)
return cb(true);