62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
|
|
describe('Component vnPopover', () => {
|
|
let $element;
|
|
let $parent;
|
|
let controller;
|
|
|
|
beforeEach(ngModule('vnCore'));
|
|
|
|
beforeEach(inject(($compile, $rootScope, $document) => {
|
|
$element = $compile(`<vn-popover>test</vn-popover>`)($rootScope);
|
|
$document.find('body').append($element);
|
|
controller = $element.controller('vnPopover');
|
|
|
|
$parent = angular.element('<div/>');
|
|
$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');
|
|
});
|
|
});
|
|
});
|
|
|