fix karma by @matiu

This commit is contained in:
Gustavo Maximiliano Cortez 2014-12-09 19:29:56 -03:00
commit 18034fd643
4 changed files with 41 additions and 15 deletions

View file

@ -57,7 +57,7 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
}); });
}; };
$scope.walletInfo = function(w) { $scope.showWalletInfo = function(w) {
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
if (!w) return; if (!w) return;
$scope.isSafari = isMobile.Safari(); $scope.isSafari = isMobile.Safari();
@ -66,6 +66,7 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
$scope.success = null; $scope.success = null;
$scope.deleteWallet = function() { $scope.deleteWallet = function() {
$scope.loading = true; $scope.loading = true;
identityService.deleteWallet($scope.item, function(err) { identityService.deleteWallet($scope.item, function(err) {
if (err) { if (err) {

View file

@ -120,7 +120,7 @@ angular.module('copayApp.services')
}; };
root.deleteWallet = function(w, cb) { root.deleteWallet = function(w, cb) {
$rootScope.iden.deleteWallet(w.id, cb); $rootScope.iden.deleteWallet(w.getId(), cb);
}; };
root.isFocused = function(wid) { root.isFocused = function(wid) {

View file

@ -16,7 +16,7 @@ describe("Unit: Controllers", function() {
config.plugins.LocalStorage = true; config.plugins.LocalStorage = true;
config.plugins.GoogleDrive = null; config.plugins.GoogleDrive = null;
config.plugins.InsightStorage = null; config.plugins.InsightStorage = null;
config.plugins.EncryptedInsightStorage= null; config.plugins.EncryptedInsightStorage = null;
var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'; var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy';
var anAmount = 1000; var anAmount = 1000;
@ -50,6 +50,10 @@ describe("Unit: Controllers", function() {
$rootScope.safeUnspentCount = 1; $rootScope.safeUnspentCount = 1;
$rootScope.pendingTxCount = 0; $rootScope.pendingTxCount = 0;
//
// TODO Use the REAL wallet, and stub only networking and DB components!
//
var w = {}; var w = {};
w.id = 1234; w.id = 1234;
w.isComplete = sinon.stub().returns(true); w.isComplete = sinon.stub().returns(true);
@ -92,7 +96,9 @@ describe("Unit: Controllers", function() {
'e': 'errmsg', 'e': 'errmsg',
'loading': false 'loading': false
}); });
w.sizes = sinon.stub().returns({tota:1234}); w.sizes = sinon.stub().returns({
tota: 1234
});
w.getBalance = sinon.stub().returns(10000); w.getBalance = sinon.stub().returns(10000);
w.publicKeyRing = sinon.stub().yields(null); w.publicKeyRing = sinon.stub().yields(null);
w.publicKeyRing.nicknameForCopayer = sinon.stub().returns('nickcopayer'); w.publicKeyRing.nicknameForCopayer = sinon.stub().returns('nickcopayer');
@ -103,11 +109,11 @@ describe("Unit: Controllers", function() {
}]); }]);
var iden = {}; var iden = {};
iden.deleteWallet = sinon.stub().yields(null);
iden.getLastFocusedWallet = sinon.stub().returns(null); iden.getLastFocusedWallet = sinon.stub().returns(null);
iden.listWallets = sinon.stub().returns([w]); iden.listWallets = sinon.stub().returns([w]);
iden.getWalletById = sinon.stub().returns(w); iden.getWalletById = sinon.stub().returns(w);
iden.getName = sinon.stub().returns('name'); iden.getName = sinon.stub().returns('name');
iden.deleteWallet = sinon.stub();
$rootScope.wallet = w; $rootScope.wallet = w;
$rootScope.iden = iden; $rootScope.iden = iden;
@ -561,20 +567,35 @@ describe("Unit: Controllers", function() {
}); });
describe('Profile Controller', function() { describe('Profile Controller', function() {
var ctrl, scope; var ctrl, inScope, modalCtrl;
beforeEach(inject(function($controller, $rootScope) { beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new(); scope = $rootScope.$new();
ctrl = $controller('ProfileController', { ctrl = $controller('ProfileController', {
$scope: scope, $scope: scope,
$modal: {}, $modal: {
open: function(opts) {
inScope = $rootScope.$new();
modalCtrl = opts.controller(inScope, {
close: sinon.stub(),
});
return {
result: {
then: sinon.stub(),
}
};
},
},
}); });
saveAsLastCall = null; saveAsLastCall = null;
})); }));
it('Backup Wallet controller #download', function() { it('Backup Wallet controller #download', function() {
var w = scope.wallet; var w = scope.wallet;
expect(saveAsLastCall).equal(null); expect(saveAsLastCall).equal(null);
scope.downloadWalletBackup(w); scope.showWalletInfo(w);
inScope.downloadWalletBackup();
expect(saveAsLastCall.blob.size).equal(7); expect(saveAsLastCall.blob.size).equal(7);
expect(saveAsLastCall.blob.type).equal('text/plain;charset=utf-8'); expect(saveAsLastCall.blob.type).equal('text/plain;charset=utf-8');
}); });
@ -582,7 +603,8 @@ describe("Unit: Controllers", function() {
it('Backup Wallet controller should name backup correctly for multiple copayers', function() { it('Backup Wallet controller should name backup correctly for multiple copayers', function() {
var w = scope.wallet; var w = scope.wallet;
expect(saveAsLastCall).equal(null); expect(saveAsLastCall).equal(null);
scope.downloadWalletBackup(w); scope.showWalletInfo(w);
inScope.downloadWalletBackup();
expect(saveAsLastCall.filename).equal('nickname-fakeWallet-keybackup.json.aes'); expect(saveAsLastCall.filename).equal('nickname-fakeWallet-keybackup.json.aes');
}); });
@ -590,16 +612,19 @@ describe("Unit: Controllers", function() {
var w = scope.wallet; var w = scope.wallet;
expect(saveAsLastCall).equal(null); expect(saveAsLastCall).equal(null);
scope.wallet.totalCopayers = 1; scope.wallet.totalCopayers = 1;
scope.downloadWalletBackup(w); scope.showWalletInfo(w);
inScope.downloadWalletBackup();
expect(saveAsLastCall.filename).equal('fakeWallet-keybackup.json.aes'); expect(saveAsLastCall.filename).equal('fakeWallet-keybackup.json.aes');
}); });
it('Delete a wallet', function() { it('Delete a wallet', function() {
var w = scope.wallet; var w = scope.wallet;
scope.deleteWallet(w, function() {
scope.$digest(); scope.showWalletInfo(w);
expect(scope.wallet).equal(null); inScope.deleteWallet();
}); scope.$digest();
scope.iden.deleteWallet.calledOnce.should.equal(true);
scope.iden.deleteWallet.getCall(0).args[0].should.equal(w.getId());
}); });
}); });

View file

@ -68,7 +68,7 @@
<tr <tr
data-ng-repeat="item in wallets | orderBy:'name'" data-ng-repeat="item in wallets | orderBy:'name'"
ng-init="isComplete = item.isComplete(); networkName = item.getNetworkName()" ng-init="isComplete = item.isComplete(); networkName = item.getNetworkName()"
ng-click="walletInfo(item)"> ng-click="showWalletInfo(item)">
<td> <td>
<span ng-show="loading == item.id"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span> <span ng-show="loading == item.id"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
<span ng-show="loading != item.id"> <span ng-show="loading != item.id">