kibana-with-account
Version:
kibana-with-account is develop based kibana project
165 lines (130 loc) • 4.77 kB
JavaScript
describe('Notifier', function () {
var _ = require('lodash');
var ngMock = require('ngMock');
var expect = require('expect.js');
var Notifier = require('ui/notify/notifier');
var message = 'Oh, the humanity!';
var notifier;
var params;
var version = window.__KBN__.version;
var buildNum = window.__KBN__.buildNum;
beforeEach(ngMock.module('kibana'));
beforeEach(function () {
params = { location: 'foo' };
while (Notifier.prototype._notifs.pop()); // clear global notifications
notifier = new Notifier(params);
});
describe('#constructor()', function () {
it('sets #from from given location', function () {
expect(notifier.from).to.equal(params.location);
});
});
describe('#error', function () {
testVersionInfo('error');
it('prepends location to message for content', function () {
expect(notify('error').content).to.equal(params.location + ': ' + message);
});
it('sets type to "danger"', function () {
expect(notify('error').type).to.equal('danger');
});
it('sets icon to "warning"', function () {
expect(notify('error').icon).to.equal('warning');
});
it('sets title to "Error"', function () {
expect(notify('error').title).to.equal('Error');
});
it('sets lifetime to Infinity', function () {
expect(notify('error').lifetime).to.equal(Infinity);
});
it('allows reporting', function () {
var includesReport = _.includes(notify('error').actions, 'report');
expect(includesReport).to.true;
});
it('allows accepting', function () {
var includesAccept = _.includes(notify('error').actions, 'accept');
expect(includesAccept).to.true;
});
it('includes stack', function () {
expect(notify('error').stack).to.be.defined;
});
});
describe('#warning', function () {
testVersionInfo('warning');
it('prepends location to message for content', function () {
expect(notify('warning').content).to.equal(params.location + ': ' + message);
});
it('sets type to "warning"', function () {
expect(notify('warning').type).to.equal('warning');
});
it('sets icon to "warning"', function () {
expect(notify('warning').icon).to.equal('warning');
});
it('sets title to "Warning"', function () {
expect(notify('warning').title).to.equal('Warning');
});
it('sets lifetime to 10000', function () {
expect(notify('warning').lifetime).to.equal(10000);
});
it('does not allow reporting', function () {
var includesReport = _.includes(notify('warning').actions, 'report');
expect(includesReport).to.false;
});
it('allows accepting', function () {
var includesAccept = _.includes(notify('warning').actions, 'accept');
expect(includesAccept).to.true;
});
it('does not include stack', function () {
expect(notify('warning').stack).not.to.be.defined;
});
});
describe('#info', function () {
testVersionInfo('info');
it('prepends location to message for content', function () {
expect(notify('info').content).to.equal(params.location + ': ' + message);
});
it('sets type to "info"', function () {
expect(notify('info').type).to.equal('info');
});
it('sets icon to "info-circle"', function () {
expect(notify('info').icon).to.equal('info-circle');
});
it('sets title to "Debug"', function () {
expect(notify('info').title).to.equal('Debug');
});
it('sets lifetime to 5000', function () {
expect(notify('info').lifetime).to.equal(5000);
});
it('does not allow reporting', function () {
var includesReport = _.includes(notify('info').actions, 'report');
expect(includesReport).to.false;
});
it('allows accepting', function () {
var includesAccept = _.includes(notify('info').actions, 'accept');
expect(includesAccept).to.true;
});
it('does not include stack', function () {
expect(notify('info').stack).not.to.be.defined;
});
});
function notify(fnName) {
notifier[fnName](message);
return latestNotification();
}
function latestNotification() {
return _.last(notifier._notifs);
}
function testVersionInfo(fnName) {
context('when version is configured', function () {
it('adds version to notification', function () {
var notification = notify(fnName);
expect(notification.info.version).to.equal(version);
});
});
context('when build number is configured', function () {
it('adds buildNum to notification', function () {
var notification = notify(fnName);
expect(notification.info.buildNum).to.equal(buildNum);
});
});
}
});