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, $transclude: null}); controller.onOpen = jasmine.createSpy('onOpen'); })); describe('show()', () => { it(`should do nothing if controller.shown is defined`, () => { controller.element = {style: {display: 'none'}}; controller.shown = true; controller.show(); expect(controller.element.style.display).toEqual('none'); expect(controller.onOpen).not.toHaveBeenCalledWith(); }); it(`should set shown on the controller, set style.display on the element and call onOpen()`, () => { controller.show(); expect(controller.element.style.display).toEqual('flex'); expect(controller.shown).toBeTruthy(); expect(controller.onOpen).toHaveBeenCalledWith(); }); }); describe('hide()', () => { 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)); }); 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); }); }); 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'); }); }); }); });