Merge pull request #752 from matiu/bug/balance-update
fix address event subscription
This commit is contained in:
commit
7e3477d03f
4 changed files with 101 additions and 64 deletions
|
|
@ -70,72 +70,108 @@ describe("Unit: Walletfactory Service", function() {
|
|||
});
|
||||
|
||||
describe("Unit: controllerUtils", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
|
||||
it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) {
|
||||
expect(controllerUtils.updateBalance).not.to.equal(null);
|
||||
scope = $rootScope.$new();
|
||||
it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) {
|
||||
expect(controllerUtils.updateBalance).not.to.equal(null);
|
||||
scope = $rootScope.$new();
|
||||
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC';
|
||||
var a = {};
|
||||
a[addr] = 100;
|
||||
//SATs
|
||||
$rootScope.wallet.set(100000001, 90000002, a);
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
|
||||
var a = {};
|
||||
a[Waddr] = 100;
|
||||
//SATs
|
||||
$rootScope.wallet.set(100000001, 90000002, a);
|
||||
|
||||
//retuns values in DEFAULT UNIT(bits)
|
||||
controllerUtils.updateBalance(function() {
|
||||
expect($rootScope.totalBalanceBTC).to.be.equal('1.0000');
|
||||
expect($rootScope.availableBalanceBTC).to.be.equal('0.9000');
|
||||
expect($rootScope.totalBalance).to.be.equal(1000000.01);
|
||||
expect($rootScope.availableBalance).to.be.equal(900000.02);
|
||||
expect($rootScope.addrInfos).not.to.equal(null);
|
||||
expect($rootScope.addrInfos[0].address).to.equal(addr);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should set the rootScope', inject(function(controllerUtils, $rootScope) {
|
||||
controllerUtils.setupRootVariables(function() {
|
||||
expect($rootScope.txAlertCount).to.be.equal(0);
|
||||
expect($rootScope.insightError).to.be.equal(0);
|
||||
expect($rootScope.isCollapsed).to.be.equal(0);
|
||||
expect($rootScope.unitName).to.be.equal('bits');
|
||||
});
|
||||
}));
|
||||
//retuns values in DEFAULT UNIT(bits)
|
||||
controllerUtils.updateBalance(function() {
|
||||
expect($rootScope.totalBalanceBTC).to.be.equal('1.0000');
|
||||
expect($rootScope.availableBalanceBTC).to.be.equal('0.9000');
|
||||
expect($rootScope.totalBalance).to.be.equal(1000000.01);
|
||||
expect($rootScope.availableBalance).to.be.equal(900000.02);
|
||||
expect($rootScope.addrInfos).not.to.equal(null);
|
||||
expect($rootScope.addrInfos[0].address).to.equal(Waddr);
|
||||
});
|
||||
}));
|
||||
|
||||
describe("Unit: Notification Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a notification service', inject(function(notification) {
|
||||
expect(notification).not.to.equal(null);
|
||||
}));
|
||||
});
|
||||
it('should set the rootScope', inject(function(controllerUtils, $rootScope) {
|
||||
controllerUtils.setupRootVariables(function() {
|
||||
expect($rootScope.txAlertCount).to.be.equal(0);
|
||||
expect($rootScope.insightError).to.be.equal(0);
|
||||
expect($rootScope.isCollapsed).to.be.equal(0);
|
||||
expect($rootScope.unitName).to.be.equal('bits');
|
||||
});
|
||||
}));
|
||||
describe("Unit: controllerUtils #setSocketHandlers", function() {
|
||||
|
||||
describe("Unit: Backup Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a backup service', inject(function(backupService) {
|
||||
expect(backupService).not.to.equal(null);
|
||||
}));
|
||||
it('should backup in file', inject(function(backupService) {
|
||||
var mock = sinon.mock(window);
|
||||
var expectation = mock.expects('saveAs');
|
||||
backupService.download(new FakeWallet());
|
||||
expectation.once();
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Unit: isMobile Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a isMobile service', inject(function(isMobile) {
|
||||
expect(isMobile).not.to.equal(null);
|
||||
it(' should call updateAddressList ', inject(function(controllerUtils, $rootScope) {
|
||||
var spy = sinon.spy(controllerUtils, 'updateAddressList');
|
||||
controllerUtils.setSocketHandlers();
|
||||
sinon.assert.callCount(spy, 1);
|
||||
}));
|
||||
it('should not detect mobile by default', inject(function(isMobile) {
|
||||
isMobile.any().should.equal(false);
|
||||
|
||||
it('should update addresses', inject(function(controllerUtils, $rootScope) {
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
|
||||
controllerUtils.setSocketHandlers();
|
||||
expect($rootScope.addrInfos[0].address).to.be.equal(Waddr);;
|
||||
}));
|
||||
it('should detect mobile if user agent is Android', inject(function(isMobile) {
|
||||
navigator.__defineGetter__('userAgent', function() {
|
||||
return 'Android 2.2.3';
|
||||
|
||||
it('should set System Event Handlers', inject(function(controllerUtils, $rootScope, Socket) {
|
||||
var spy = sinon.spy(Socket, 'sysOn');
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
controllerUtils.setSocketHandlers();
|
||||
sinon.assert.callCount(spy, 5);
|
||||
['error', 'reconnect_error', 'reconnect_failed', 'connect', 'reconnect'].forEach(function(e) {
|
||||
sinon.assert.calledWith(spy, e);
|
||||
});
|
||||
isMobile.any().should.equal(true);
|
||||
}));
|
||||
|
||||
it('should set Address Event Handlers', inject(function(controllerUtils, $rootScope, Socket) {
|
||||
var spy = sinon.spy(Socket, 'on');
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
|
||||
controllerUtils.setSocketHandlers();
|
||||
sinon.assert.calledWith(spy, Waddr);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe("Unit: Notification Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a notification service', inject(function(notification) {
|
||||
expect(notification).not.to.equal(null);
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Unit: Backup Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a backup service', inject(function(backupService) {
|
||||
expect(backupService).not.to.equal(null);
|
||||
}));
|
||||
it('should backup in file', inject(function(backupService) {
|
||||
var mock = sinon.mock(window);
|
||||
var expectation = mock.expects('saveAs');
|
||||
backupService.download(new FakeWallet());
|
||||
expectation.once();
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Unit: isMobile Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a isMobile service', inject(function(isMobile) {
|
||||
expect(isMobile).not.to.equal(null);
|
||||
}));
|
||||
it('should not detect mobile by default', inject(function(isMobile) {
|
||||
isMobile.any().should.equal(false);
|
||||
}));
|
||||
it('should detect mobile if user agent is Android', inject(function(isMobile) {
|
||||
navigator.__defineGetter__('userAgent', function() {
|
||||
return 'Android 2.2.3';
|
||||
});
|
||||
isMobile.any().should.equal(true);
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue