2017-10-05 12:28:57 +00:00
|
|
|
describe('Component vnDialog', () => {
|
|
|
|
let $componentController;
|
|
|
|
let $element;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2017-10-05 12:28:57 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('client');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(_$componentController_ => {
|
|
|
|
$componentController = _$componentController_;
|
2018-02-20 09:00:19 +00:00
|
|
|
$element = angular.element('<vn-dialog></vn-dialog>');
|
|
|
|
controller = $componentController('vnDialog', {$element: $element, $transclude: null});
|
2017-10-05 12:28:57 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('show()', () => {
|
2018-02-20 09:00:19 +00:00
|
|
|
it(`should handle escape keypress event, define element.style.display to not none and call onOpen function`, () => {
|
2017-10-05 12:28:57 +00:00
|
|
|
window.innerHeight = 600;
|
|
|
|
window.innerWidth = 800;
|
2018-02-20 09:00:19 +00:00
|
|
|
controller.dialog = {style: {display: 'none'}};
|
2017-10-17 12:24:40 +00:00
|
|
|
controller.onOpen = () => {};
|
2017-10-05 12:28:57 +00:00
|
|
|
spyOn(controller, 'onOpen');
|
|
|
|
controller.show();
|
|
|
|
|
2018-02-20 09:00:19 +00:00
|
|
|
expect(controller.element.style.display).not.toEqual('none');
|
2017-10-05 12:28:57 +00:00
|
|
|
expect(controller.onOpen).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hide()', () => {
|
2018-02-20 09:00:19 +00:00
|
|
|
it(`should call onResponse()`, () => {
|
|
|
|
controller.onResponse = () => {};
|
|
|
|
spyOn(controller, 'onResponse');
|
2017-10-05 12:28:57 +00:00
|
|
|
controller.hide();
|
|
|
|
|
2018-02-20 09:00:19 +00:00
|
|
|
expect(controller.onResponse).toHaveBeenCalled();
|
2017-10-05 12:28:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fireResponse()', () => {
|
2018-02-20 09:00:19 +00:00
|
|
|
it(`should call onResponse()`, () => {
|
|
|
|
let resposneRes;
|
|
|
|
controller.onResponse = response => {
|
|
|
|
resposneRes = response;
|
|
|
|
return false;
|
2017-10-17 12:24:40 +00:00
|
|
|
};
|
2018-02-20 09:00:19 +00:00
|
|
|
let responseRet = controller.fireResponse('answer');
|
2017-10-09 12:30:23 +00:00
|
|
|
|
2018-02-20 09:00:19 +00:00
|
|
|
expect(resposneRes).toEqual({response: 'answer'});
|
|
|
|
expect(responseRet).toEqual(false);
|
2017-10-09 12:30:23 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-05 12:28:57 +00:00
|
|
|
});
|