2014-11-21 06:13:06 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
describe('Dialog Service unit test', function() {
|
2014-11-29 08:46:16 -05:00
|
|
|
var dialog, logErrorStub, timeout,
|
2014-11-21 06:13:06 -05:00
|
|
|
opt = {
|
|
|
|
foo: 'bar'
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
angular.module('dialog-test', ['woUtil']);
|
|
|
|
angular.mock.module('dialog-test');
|
2014-11-29 08:46:16 -05:00
|
|
|
angular.mock.inject(function($injector, $timeout, axe) {
|
2014-11-21 06:14:28 -05:00
|
|
|
logErrorStub = sinon.stub(axe, 'error');
|
2014-11-29 08:46:16 -05:00
|
|
|
timeout = $timeout;
|
2014-11-21 06:13:06 -05:00
|
|
|
dialog = $injector.get('dialog');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-21 06:14:28 -05:00
|
|
|
afterEach(function() {
|
|
|
|
logErrorStub.restore();
|
|
|
|
});
|
2014-11-21 06:13:06 -05:00
|
|
|
|
|
|
|
describe('info', function() {
|
2014-11-29 08:46:16 -05:00
|
|
|
it('should work', function() {
|
2014-11-21 06:13:06 -05:00
|
|
|
dialog.displayInfo = function() {};
|
|
|
|
var displayInfoStub = sinon.stub(dialog, 'displayInfo');
|
|
|
|
|
|
|
|
dialog.info(opt).then(function(result) {
|
|
|
|
expect(result).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2014-11-29 08:46:16 -05:00
|
|
|
timeout.flush();
|
2014-11-21 06:13:06 -05:00
|
|
|
expect(displayInfoStub.withArgs(opt).calledOnce).to.be.true;
|
2014-11-29 08:46:16 -05:00
|
|
|
});
|
|
|
|
it('should fail for no display function', function() {
|
|
|
|
dialog.info(opt);
|
2014-11-21 06:13:06 -05:00
|
|
|
|
2014-11-29 08:46:16 -05:00
|
|
|
timeout.flush();
|
|
|
|
expect(logErrorStub.calledOnce).to.be.true;
|
|
|
|
});
|
2014-11-21 06:13:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', function() {
|
2014-11-29 08:46:16 -05:00
|
|
|
it('should work', function() {
|
2014-11-21 06:13:06 -05:00
|
|
|
dialog.displayError = function() {};
|
|
|
|
var displayErrorStub = sinon.stub(dialog, 'displayError');
|
|
|
|
|
|
|
|
dialog.error(opt).then(function(result) {
|
|
|
|
expect(result).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2014-11-21 06:14:28 -05:00
|
|
|
expect(logErrorStub.calledOnce).to.be.true;
|
2014-11-29 08:46:16 -05:00
|
|
|
timeout.flush();
|
2014-11-21 06:13:06 -05:00
|
|
|
expect(displayErrorStub.withArgs(opt).calledOnce).to.be.true;
|
2014-11-29 08:46:16 -05:00
|
|
|
});
|
|
|
|
it('should fail for no display function', function() {
|
|
|
|
dialog.error(opt);
|
2014-11-21 06:13:06 -05:00
|
|
|
|
2014-11-21 06:14:28 -05:00
|
|
|
expect(logErrorStub.calledOnce).to.be.true;
|
2014-11-29 08:46:16 -05:00
|
|
|
timeout.flush();
|
|
|
|
expect(logErrorStub.calledTwice).to.be.true;
|
|
|
|
});
|
2014-11-21 06:13:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('confirm', function() {
|
2014-11-29 08:46:16 -05:00
|
|
|
it('should work', function() {
|
2014-11-21 06:13:06 -05:00
|
|
|
dialog.displayConfirm = function() {};
|
|
|
|
var displayConfirmStub = sinon.stub(dialog, 'displayConfirm');
|
|
|
|
|
|
|
|
dialog.confirm(opt).then(function(result) {
|
|
|
|
expect(result).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2014-11-29 08:46:16 -05:00
|
|
|
timeout.flush();
|
2014-11-21 06:13:06 -05:00
|
|
|
expect(displayConfirmStub.withArgs(opt).calledOnce).to.be.true;
|
2014-11-29 08:46:16 -05:00
|
|
|
});
|
|
|
|
it('should fail for no display function', function() {
|
|
|
|
dialog.confirm(opt);
|
2014-11-21 06:13:06 -05:00
|
|
|
|
2014-11-29 08:46:16 -05:00
|
|
|
timeout.flush();
|
|
|
|
expect(logErrorStub.calledOnce).to.be.true;
|
|
|
|
});
|
2014-11-21 06:13:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|