salix/front/core/components/popover/index.spec.js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-08-23 11:53:29 +00:00
describe('Component vnPopover', () => {
let $element;
2018-10-18 18:48:21 +00:00
let $parent;
2018-11-06 13:27:16 +00:00
let controller;
2018-08-23 11:53:29 +00:00
beforeEach(ngModule('vnCore'));
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
beforeEach(inject(($compile, $rootScope, $document) => {
2018-10-19 07:33:12 +00:00
$element = $compile(`<vn-popover>test</vn-popover>`)($rootScope);
2018-10-18 18:48:21 +00:00
$document.find('body').append($element);
2018-11-06 13:27:16 +00:00
controller = $element.controller('vnPopover');
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
$parent = angular.element('<div/>');
$document.find('body').append($parent);
}));
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
afterEach(() => {
$element.remove();
$parent.remove();
});
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
describe('show()', () => {
it(`should enable the shown property and emit the open event`, () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.show();
2018-08-23 11:53:29 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.shown).toBeTruthy();
expect(controller.emit).toHaveBeenCalledWith('open');
2018-08-23 11:53:29 +00:00
});
2018-10-18 18:48:21 +00:00
it(`should do nothing if it's already shown`, () => {
2018-11-06 13:27:16 +00:00
controller.shown = true;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.show();
2018-08-23 11:53:29 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.emit).not.toHaveBeenCalledWith('open');
2018-08-23 11:53:29 +00:00
});
2020-02-26 12:22:52 +00:00
// #1615 migrar karma a jest (this doesn't work anymore, needs fixing)
2019-09-13 14:09:14 +00:00
xit(`should check that popover is visible into the screen`, () => {
2018-10-18 18:48:21 +00:00
$parent.css({
backgroundColor: 'red',
position: 'absolute',
width: '50px',
height: '50px',
top: '0',
left: '100px'
});
2018-11-06 13:27:16 +00:00
controller.show($parent[0]);
2018-10-18 18:48:21 +00:00
2018-11-06 13:27:16 +00:00
let rect = controller.popover.getBoundingClientRect();
let style = controller.window.getComputedStyle(controller.element);
2018-10-18 18:48:21 +00:00
expect(style.visibility).toEqual('visible');
expect(style.display).not.toEqual('none');
expect(0).toBeLessThanOrEqual(rect.top);
expect(0).toBeLessThanOrEqual(rect.left);
2018-11-06 13:27:16 +00:00
expect(controller.window.innerHeight).toBeGreaterThan(rect.bottom);
expect(controller.window.innerWidth).toBeGreaterThan(rect.right);
2018-08-23 11:53:29 +00:00
});
});
describe('hide()', () => {
2018-10-18 18:48:21 +00:00
it(`should disable the shown property and emit the close event`, inject($timeout => {
2018-11-06 13:27:16 +00:00
controller.show();
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.hide();
2018-08-23 11:53:29 +00:00
$timeout.flush();
2018-11-06 13:27:16 +00:00
expect(controller.shown).toBeFalsy();
expect(controller.emit).toHaveBeenCalledWith('close');
2018-10-18 18:48:21 +00:00
}));
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
it(`should do nothing if it's already hidden`, () => {
2018-11-06 13:27:16 +00:00
controller.shown = false;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.hide();
2018-08-23 11:53:29 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.emit).not.toHaveBeenCalledWith('close');
2018-08-23 11:53:29 +00:00
});
});
});