describe('Component vnDialog', () => { let $componentController; let $element; let controller; beforeEach(() => { angular.mock.module('client'); }); beforeEach(angular.mock.inject(_$componentController_ => { $componentController = _$componentController_; $element = angular.element(''); controller = $componentController('vnDialog', {$element: $element, $transclude: null}); })); describe('show()', () => { it(`should handle escape keypress event, define element.style.display to not none and call onOpen function`, () => { window.innerHeight = 600; window.innerWidth = 800; controller.dialog = {style: {display: 'none'}}; controller.onOpen = () => {}; spyOn(controller, 'onOpen'); controller.show(); expect(controller.element.style.display).not.toEqual('none'); expect(controller.onOpen).toHaveBeenCalledWith(); }); }); describe('hide()', () => { it(`should call onResponse()`, () => { controller.onResponse = () => {}; spyOn(controller, 'onResponse'); controller.hide(); expect(controller.onResponse).toHaveBeenCalled(); }); }); describe('fireResponse()', () => { it(`should call onResponse()`, () => { let responseRes; controller.onResponse = response => { responseRes = response; return false; }; let responseRet = controller.fireResponse('answer'); expect(responseRes).toEqual({response: 'answer'}); expect(responseRet).toEqual(false); }); }); });