Skip to content

Commit

Permalink
Add tests for Notify factory
Browse files Browse the repository at this point in the history
  • Loading branch information
alepop committed May 24, 2017
1 parent e944e7b commit 19ac8f1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/services/notify.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');

const expect = chai.expect;
chai.use(sinonChai);

describe('Factory: Notify', () => {
let lsk;
let $window;
let notify;

beforeEach(angular.mock.module('app'));

beforeEach(inject((_Notify_, _lsk_, _$window_) => {
lsk = _lsk_;
$window = _$window_;
notify = _Notify_.init();
}));

describe('about(data)', () => {
const amount = 100000000;
const mockNotification = sinon.spy();

it('should call this.__deposite', () => {
const spy = sinon.spy(notify, '__deposite');
notify.isFocused = false;
notify.about('deposite', amount);
expect(spy).to.have.been.calledWith(amount);
});

it('should call $window.Notification', () => {
$window.Notification = mockNotification;
const msg = `You've received ${lsk.normalize(amount)} LSK.`;

notify.isFocused = false;
notify.about('deposite', amount);
expect(mockNotification).to.have.been.calledWith(
'LSK received', { body: msg },
);
mockNotification.reset();
});

it('should not call $window.Notification if app is focused', () => {
notify.about('deposite', amount);
expect(mockNotification).to.have.been.not.calledWith();
mockNotification.reset();
});

it('should not call $window.Notification if amount equal 0 or negative', () => {
notify.isFocused = false;
notify.about('deposite', 0);
notify.about('deposite', -1);
expect(mockNotification.callCount).to.have.been.equal(0);
});
});
});
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require('./components/delegateRegistration/delegateRegistration.spec.js');
require('./services/passphrase.spec');
require('./services/signVerify.spec');
require('./services/lsk.spec');
require('./services/notify.spec');
require('./services/api/peers.spec');
require('./services/api/delegateApi.spec');
require('./services/api/forgingApi.spec');
Expand Down

0 comments on commit 19ac8f1

Please sign in to comment.