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()`, () => {
|
2018-02-23 12:04:44 +00:00
|
|
|
let responseRes;
|
2018-02-20 09:00:19 +00:00
|
|
|
controller.onResponse = response => {
|
2018-02-23 12:04:44 +00:00
|
|
|
responseRes = response;
|
2018-02-20 09:00:19 +00:00
|
|
|
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-23 12:04:44 +00:00
|
|
|
expect(responseRes).toEqual({response: 'answer'});
|
2018-02-20 09:00:19 +00:00
|
|
|
expect(responseRet).toEqual(false);
|
2017-10-09 12:30:23 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-05 12:28:57 +00:00
|
|
|
});
|