86 lines
2.7 KiB
JavaScript
86 lines
2.7 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');
|
|
});
|
|
|
|
// #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();
|
|
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');
|
|
});
|
|
});
|
|
});
|
|
|