2017-10-05 12:28:57 +00:00
|
|
|
describe('Component vnDialog', () => {
|
|
|
|
let $element;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2017-10-05 12:28:57 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2017-10-05 12:28:57 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject($componentController => {
|
2018-02-20 09:00:19 +00:00
|
|
|
$element = angular.element('<vn-dialog></vn-dialog>');
|
2018-08-30 06:16:50 +00:00
|
|
|
controller = $componentController('vnDialog', {$element, $transclude: null});
|
2019-06-26 11:35:38 +00:00
|
|
|
controller.emit = jasmine.createSpy('emit');
|
2017-10-05 12:28:57 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('show()', () => {
|
2018-08-30 06:16:50 +00:00
|
|
|
it(`should do nothing if controller.shown is defined`, () => {
|
|
|
|
controller.element = {style: {display: 'none'}};
|
|
|
|
controller.shown = true;
|
2017-10-05 12:28:57 +00:00
|
|
|
controller.show();
|
|
|
|
|
2018-08-30 06:16:50 +00:00
|
|
|
expect(controller.element.style.display).toEqual('none');
|
2019-06-26 11:35:38 +00:00
|
|
|
expect(controller.emit).not.toHaveBeenCalledWith('open');
|
2018-08-30 06:16:50 +00:00
|
|
|
});
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
it(`should set shown on the controller, set style.display on the element and emit onOpen() event`, () => {
|
2018-08-30 06:16:50 +00:00
|
|
|
controller.show();
|
|
|
|
|
|
|
|
expect(controller.element.style.display).toEqual('flex');
|
|
|
|
expect(controller.shown).toBeTruthy();
|
2019-06-26 11:35:38 +00:00
|
|
|
expect(controller.emit).toHaveBeenCalledWith('open');
|
2017-10-05 12:28:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hide()', () => {
|
2018-08-30 06:16:50 +00:00
|
|
|
describe('fireResponse()', () => {
|
|
|
|
it(`should call onResponse() if it's defined in the controller`, () => {
|
|
|
|
controller.onResponse = () => {};
|
|
|
|
spyOn(controller, 'onResponse');
|
|
|
|
controller.hide();
|
|
|
|
|
|
|
|
expect(controller.onResponse).toHaveBeenCalledWith(jasmine.any(Object));
|
|
|
|
});
|
2017-10-05 12:28:57 +00:00
|
|
|
|
2018-08-30 06:16:50 +00:00
|
|
|
it(`should call onResponse() with a response`, () => {
|
|
|
|
let responseRes;
|
|
|
|
controller.onResponse = response => {
|
|
|
|
responseRes = response;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
let responseRet = controller.fireResponse('answer');
|
|
|
|
|
|
|
|
expect(responseRes).toEqual({response: 'answer'});
|
|
|
|
expect(responseRet).toEqual(false);
|
|
|
|
});
|
2017-10-05 12:28:57 +00:00
|
|
|
});
|
|
|
|
|
2018-08-30 06:16:50 +00:00
|
|
|
describe('realHide()', () => {
|
|
|
|
it(`should do nothing if controller.shown is not defined`, () => {
|
|
|
|
controller.element = {style: {display: 'not none'}};
|
|
|
|
controller.hide();
|
|
|
|
|
|
|
|
expect(controller.element.style.display).toEqual('not none');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set lastEvent, shown and element.style.display to their expected values`, () => {
|
|
|
|
controller.shown = true;
|
|
|
|
controller.hide();
|
|
|
|
|
|
|
|
expect(controller.lastEvent).toBeFalsy();
|
|
|
|
expect(controller.shown).toBeFalsy();
|
|
|
|
expect(controller.element.style.display).toEqual('none');
|
|
|
|
});
|
2017-10-09 12:30:23 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-05 12:28:57 +00:00
|
|
|
});
|