describe('Component vnPopover', () => {
let $element;
let $parent;
let controller;
beforeEach(ngModule('vnCore'));
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`, () => {
jest.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;
jest.spyOn(controller, 'emit');
controller.show();
expect(controller.emit).not.toHaveBeenCalledWith('open');
});
});
describe('hide()', () => {
it(`should disable the shown property and emit the close event`, inject($timeout => {
controller.show();
jest.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;
jest.spyOn(controller, 'emit');
controller.hide();
expect(controller.emit).not.toHaveBeenCalledWith('close');
});
});
});