import './tooltip';
describe('Component vnTooltip', () => {
let $element;
let controller;
let $parent;
let element;
let window;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($componentController, $compile, $templateRequest, $document) => {
$element = angular.element(`test`);
$document.find('body').append($element);
controller = $componentController('vnTooltip', {$document, $compile, $templateRequest, $element});
element = $element[0];
window = controller.window;
$parent = angular.element('
');
$parent.css({
backgroundColor: 'red',
position: 'absolute',
width: '100px',
height: '100px',
top: '0',
left: '0'
});
$document.find('body').append($parent);
}));
afterEach(() => {
$element.remove();
$parent.remove();
});
describe('show()', () => {
it(`should check that tooltip is visible into the screen`, () => {
expect(element.classList).not.toContain('show');
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(element.classList).toContain('show');
expect(0).toBeLessThanOrEqual(rect.top);
expect(0).toBeLessThanOrEqual(rect.left);
expect(window.innerHeight).toBeGreaterThan(rect.bottom);
expect(window.innerWidth).toBeGreaterThan(rect.right);
});
});
describe('hide()', () => {
it(`should check that tooltip is not visible`, () => {
controller.show($parent[0]);
expect(element.classList).toContain('show');
controller.hide();
expect(element.classList).not.toContain('show');
});
});
// #1892 reparar unitarios front tooltip.js
xdescribe('relocate()', () => {
it(`should reallocate tooltip on top-left`, () => {
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(controller.margin).toBeLessThan(rect.top);
expect(controller.margin).toEqual(rect.left);
});
it(`should reallocate tooltip on bottom-left`, () => {
$parent.css({
top: `${window.innerHeight}px`
});
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(window.innerHeight).toBeGreaterThan(rect.top);
expect(controller.margin).toEqual(rect.left);
});
it(`should reallocate tooltip on bottom-right`, () => {
$parent.css({
top: `${window.innerHeight}px`,
left: `${window.innerWidth}px`
});
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(window.innerWidth).toBeGreaterThan(rect.left);
expect(window.innerWidth - controller.margin).toEqual(rect.right);
});
it(`should reallocate tooltip on top-right`, () => {
$parent.css({
left: `${window.innerWidth}px`
});
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(controller.margin).toBeLessThan(rect.top);
expect(window.innerWidth - controller.margin).toEqual(rect.right);
});
it(`should reallocate tooltip on center`, () => {
$parent.css({
top: `${window.window.innerHeight / 2}px`,
left: `${window.window.innerWidth / 2}px`
});
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(window.innerHeight / 2).toBeLessThan(rect.top);
expect(window.innerWidth / 2).toBeGreaterThan(rect.left);
});
});
});