2018-09-26 12:15:00 +00:00
|
|
|
import './tooltip';
|
|
|
|
|
2019-11-21 10:16:10 +00:00
|
|
|
describe('Component vnTooltip', () => {
|
2018-09-26 12:15:00 +00:00
|
|
|
let $element;
|
2018-11-06 13:27:16 +00:00
|
|
|
let controller;
|
2018-10-19 07:33:12 +00:00
|
|
|
let $parent;
|
|
|
|
let element;
|
|
|
|
let window;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2018-10-19 07:33:12 +00:00
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(inject(($componentController, $compile, $templateRequest, $document) => {
|
|
|
|
$element = angular.element(`<vn-tooltip class="text">test</span></vn-tooltip>`);
|
2018-10-19 07:33:12 +00:00
|
|
|
$document.find('body').append($element);
|
2019-09-13 14:09:14 +00:00
|
|
|
controller = $componentController('vnTooltip', {$document, $compile, $templateRequest, $element});
|
2018-10-19 07:33:12 +00:00
|
|
|
element = $element[0];
|
2018-11-06 13:27:16 +00:00
|
|
|
window = controller.window;
|
2018-10-19 07:33:12 +00:00
|
|
|
|
|
|
|
$parent = angular.element('<div/>');
|
|
|
|
$parent.css({
|
|
|
|
backgroundColor: 'red',
|
|
|
|
position: 'absolute',
|
2019-11-21 10:16:10 +00:00
|
|
|
width: '100px',
|
|
|
|
height: '100px',
|
2018-10-19 07:33:12 +00:00
|
|
|
top: '0',
|
|
|
|
left: '0'
|
|
|
|
});
|
|
|
|
$document.find('body').append($parent);
|
2018-09-26 12:15:00 +00:00
|
|
|
}));
|
|
|
|
|
2018-10-19 07:33:12 +00:00
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
$parent.remove();
|
|
|
|
});
|
|
|
|
|
2018-09-26 12:15:00 +00:00
|
|
|
describe('show()', () => {
|
2018-10-15 10:46:56 +00:00
|
|
|
it(`should check that tooltip is visible into the screen`, () => {
|
2019-11-21 10:16:10 +00:00
|
|
|
expect(element.classList).not.toContain('show');
|
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.show($parent[0]);
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2018-10-19 07:33:12 +00:00
|
|
|
let rect = element.getBoundingClientRect();
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2019-11-21 10:16:10 +00:00
|
|
|
expect(element.classList).toContain('show');
|
2018-10-15 10:46:56 +00:00
|
|
|
|
2018-10-19 07:33:12 +00:00
|
|
|
expect(0).toBeLessThanOrEqual(rect.top);
|
|
|
|
expect(0).toBeLessThanOrEqual(rect.left);
|
|
|
|
expect(window.innerHeight).toBeGreaterThan(rect.bottom);
|
|
|
|
expect(window.innerWidth).toBeGreaterThan(rect.right);
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hide()', () => {
|
2018-10-15 10:46:56 +00:00
|
|
|
it(`should check that tooltip is not visible`, () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.show($parent[0]);
|
2019-11-21 10:16:10 +00:00
|
|
|
|
|
|
|
expect(element.classList).toContain('show');
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.hide();
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2019-11-21 10:16:10 +00:00
|
|
|
expect(element.classList).not.toContain('show');
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-21 10:16:10 +00:00
|
|
|
// #1892 reparar unitarios front tooltip.js
|
|
|
|
xdescribe('relocate()', () => {
|
2018-10-15 10:46:56 +00:00
|
|
|
it(`should reallocate tooltip on top-left`, () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.show($parent[0]);
|
2018-10-19 07:33:12 +00:00
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.margin).toBeLessThan(rect.top);
|
|
|
|
expect(controller.margin).toEqual(rect.left);
|
2018-10-15 10:46:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it(`should reallocate tooltip on bottom-left`, () => {
|
2018-10-19 07:33:12 +00:00
|
|
|
$parent.css({
|
|
|
|
top: `${window.innerHeight}px`
|
|
|
|
});
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.show($parent[0]);
|
2018-10-19 07:33:12 +00:00
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
|
|
|
|
expect(window.innerHeight).toBeGreaterThan(rect.top);
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.margin).toEqual(rect.left);
|
2018-10-15 10:46:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it(`should reallocate tooltip on bottom-right`, () => {
|
2018-10-19 07:33:12 +00:00
|
|
|
$parent.css({
|
|
|
|
top: `${window.innerHeight}px`,
|
|
|
|
left: `${window.innerWidth}px`
|
|
|
|
});
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.show($parent[0]);
|
2018-10-19 07:33:12 +00:00
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
|
|
|
|
expect(window.innerWidth).toBeGreaterThan(rect.left);
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(window.innerWidth - controller.margin).toEqual(rect.right);
|
2018-10-15 10:46:56 +00:00
|
|
|
});
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2018-10-15 10:46:56 +00:00
|
|
|
it(`should reallocate tooltip on top-right`, () => {
|
2018-10-19 07:33:12 +00:00
|
|
|
$parent.css({
|
|
|
|
left: `${window.innerWidth}px`
|
|
|
|
});
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.show($parent[0]);
|
2018-10-19 07:33:12 +00:00
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.margin).toBeLessThan(rect.top);
|
|
|
|
expect(window.innerWidth - controller.margin).toEqual(rect.right);
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
|
2018-10-15 10:46:56 +00:00
|
|
|
it(`should reallocate tooltip on center`, () => {
|
2018-10-19 07:33:12 +00:00
|
|
|
$parent.css({
|
|
|
|
top: `${window.window.innerHeight / 2}px`,
|
|
|
|
left: `${window.window.innerWidth / 2}px`
|
|
|
|
});
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.show($parent[0]);
|
2018-10-19 07:33:12 +00:00
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
|
|
|
|
expect(window.innerHeight / 2).toBeLessThan(rect.top);
|
|
|
|
expect(window.innerWidth / 2).toBeGreaterThan(rect.left);
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|