describe('Component vnPopover', () => { let $element; let $parent; let controller; beforeEach(angular.mock.module('vnCore', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(inject(($compile, $rootScope, $document) => { $element = $compile(`test`)($rootScope); $document.find('body').append($element); controller = $element.controller('vnPopover'); $parent = angular.element('
'); $document.find('body').append($parent); })); afterEach(() => { $element.remove(); $parent.remove(); }); describe('show()', () => { it(`should enable the shown property and emit the open event`, () => { spyOn(controller, 'emit'); controller.show(); expect(controller.shown).toBeTruthy(); expect(controller.emit).toHaveBeenCalledWith('open'); }); it(`should do nothing if it's already shown`, () => { controller.shown = true; spyOn(controller, 'emit'); controller.show(); expect(controller.emit).not.toHaveBeenCalledWith('open'); }); //#1615 migrar karma a jest (this doesn't work anymore, needs fixing) xit(`should check that popover is visible into the screen`, () => { $parent.css({ backgroundColor: 'red', position: 'absolute', width: '50px', height: '50px', top: '0', left: '100px' }); controller.show($parent[0]); let rect = controller.popover.getBoundingClientRect(); let style = controller.window.getComputedStyle(controller.element); expect(style.visibility).toEqual('visible'); expect(style.display).not.toEqual('none'); expect(0).toBeLessThanOrEqual(rect.top); expect(0).toBeLessThanOrEqual(rect.left); expect(controller.window.innerHeight).toBeGreaterThan(rect.bottom); expect(controller.window.innerWidth).toBeGreaterThan(rect.right); }); }); describe('hide()', () => { it(`should disable the shown property and emit the close event`, inject($timeout => { controller.show(); spyOn(controller, 'emit'); controller.hide(); $timeout.flush(); expect(controller.shown).toBeFalsy(); expect(controller.emit).toHaveBeenCalledWith('close'); })); it(`should do nothing if it's already hidden`, () => { controller.shown = false; spyOn(controller, 'emit'); controller.hide(); expect(controller.emit).not.toHaveBeenCalledWith('close'); }); }); });