Added test on controllers

This commit is contained in:
Matias Pando 2015-02-12 17:26:30 -03:00 committed by Gustavo Maximiliano Cortez
parent 3696b383d4
commit b50b4e1aee
2 changed files with 137 additions and 16 deletions

View File

@ -3,6 +3,8 @@
angular.module('copayApp.controllers').controller('CopayersController',
function($scope, $rootScope, $timeout, go, identityService, notification, isCordova) {
var w = $rootScope.wallet;
$scope.init = function() {
$rootScope.title = 'Share this secret with your copayers';
$scope.loading = false;
@ -11,6 +13,7 @@ angular.module('copayApp.controllers').controller('CopayersController',
w.on('publicKeyRingUpdated', $scope.updateList);
w.on('ready', $scope.updateList);
$scope.updateList();
};
@ -36,7 +39,9 @@ angular.module('copayApp.controllers').controller('CopayersController',
$scope.loading = null;
$scope.error = err.message || err;
copay.logger.warn(err);
$timeout(function () { $scope.$digest(); });
$timeout(function() {
$scope.$digest();
});
} else {
$scope.loading = false;
if ($rootScope.wallet) {

View File

@ -328,6 +328,104 @@ describe("Unit: Controllers", function() {
});
});
describe('Profile Controller', function() {
var ctrl, bkpService, idenService;
beforeEach(inject(function($controller, $rootScope, backupService, identityService) {
scope = $rootScope.$new();
bkpService = backupService;
idenService = identityService;
ctrl = $controller('ProfileController', {
$scope: scope,
});
}));
it('should exist', function() {
should.exist(ctrl);
});
it('#downloadProfileBackup', function() {
var old = bkpService.profileDownload;
bkpService.profileDownload = sinon.stub().returns(null);
scope.downloadProfileBackup();
bkpService.profileDownload.calledOnce.should.be.true;
bkpService.profileDownload = old;
});
it('#viewProfileBackup', function() {
var old = bkpService.profileEncrypted;
bkpService.profileEncrypted = sinon.stub().returns(null);
scope.viewProfileBackup();
//bkpService.profileEncrypted.calledOnce.should.be.true;
bkpService.profileEncrypted = old;
});
it('#copyProfileBackup', function() {
var old = bkpService.profileEncrypted;
bkpService.profileEncrypted = sinon.stub().returns(null);
window.cordova = {
plugins: {
clipboard: {
copy: function(e) {
return e;
}
}
}
};
window.plugins = {
toast: {
showShortCenter: function(e) {
return e;
}
}
};
scope.copyProfileBackup();
bkpService.profileEncrypted.calledOnce.should.be.true;
bkpService.profileEncrypted = old;
});
it('#sendProfileBackup', function() {
var old = bkpService.profileEncrypted;
bkpService.profileEncrypted = sinon.stub().returns(null);
window.plugin = {
email: {
open: function(e) {
return e;
}
}
};
window.plugins = {
toast: {
showShortCenter: function(e) {
return e;
}
}
};
scope.sendProfileBackup();
bkpService.profileEncrypted.calledOnce.should.be.true;
bkpService.profileEncrypted = old;
});
it('#deleteProfile', function() {
var old = idenService.deleteProfile;
idenService.deleteProfile = sinon.stub().returns(null);
scope.deleteProfile();
idenService.deleteProfile.calledOnce.should.be.true;
idenService.deleteProfile = old;
});
});
describe('Send Controller', function() {
var scope, form, sendForm, sendCtrl, rootScope;
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller, rateService, notification) {
@ -658,16 +756,16 @@ describe("Unit: Controllers", function() {
});
describe('Import Controller', function() {
var what;
var ctrl;
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
what = $controller('ImportController', {
ctrl = $controller('ImportController', {
$scope: scope,
});
}));
it('should exist', function() {
should.exist(what);
should.exist(ctrl);
});
it('import status', function() {
expect(scope.importStatus).equal('Importing wallet - Reading backup...');
@ -676,16 +774,16 @@ describe("Unit: Controllers", function() {
// TODO: fix this test
describe.skip('Home Controller', function() {
var what;
var ctrl;
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
what = $controller('HomeController', {
ctrl = $controller('HomeController', {
$scope: scope,
});
}));
it('should exist', function() {
should.exist(what);
should.exist(ctrl);
});
describe('#open', function() {
it('should work with invalid form', function() {
@ -695,16 +793,16 @@ describe("Unit: Controllers", function() {
});
describe('SignOut Controller', function() {
var what;
var ctrl;
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
what = $controller('signOutController', {
ctrl = $controller('signOutController', {
$scope: scope,
});
}));
it('should exist', function() {
should.exist(what);
should.exist(ctrl);
});
});
@ -724,10 +822,11 @@ describe("Unit: Controllers", function() {
describe('Copayers Controller', function() {
var saveDownload = null;
var ctrl;
beforeEach(inject(function($controller, $rootScope) {
var ctrl, rootScope, idenService;
beforeEach(inject(function($controller, $rootScope, identityService) {
scope = $rootScope.$new();
rootScope = $rootScope;
idenService = identityService;
ctrl = $controller('CopayersController', {
$scope: scope,
$modal: {},
@ -746,19 +845,36 @@ describe("Unit: Controllers", function() {
scope.updateList = old;
});
it('#updateList', function() {
var old = rootScope.wallet.getRegisteredPeerIds;
rootScope.wallet.getRegisteredPeerIds = sinon.stub().returns(null);
rootScope.wallet.removeListener = sinon.stub().returns(null);
scope.updateList();
rootScope.wallet.getRegisteredPeerIds.callCount.should.be.equal(1);
rootScope.wallet.getRegisteredPeerIds = old;
});
it('#deleteWallet', function() {
var old = idenService.deleteWallet;
idenService.deleteWallet = sinon.stub().returns(null);
scope.deleteWallet();
idenService.deleteWallet.callCount.should.be.equal(1);
idenService.deleteWallet = old;
});
});
describe('Join Controller', function() {
var what;
var ctrl;
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
what = $controller('JoinController', {
ctrl = $controller('JoinController', {
$scope: scope,
});
}));
it('should exist', function() {
should.exist(what);
should.exist(ctrl);
});
describe('#join', function() {
it('should work with invalid form', function() {