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;
|
2020-05-18 08:05:54 +00:00
|
|
|
let tooltip;
|
|
|
|
let tooltipCtrl;
|
2018-10-19 07:33:12 +00:00
|
|
|
let $parent;
|
|
|
|
let window;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2018-10-19 07:33:12 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
beforeEach(inject(($rootScope, $compile, $document) => {
|
|
|
|
let scope = $rootScope.$new();
|
|
|
|
$element = $compile(`<vn-tooltip class="text">test</span></vn-tooltip>`)(scope);
|
2018-10-19 07:33:12 +00:00
|
|
|
$document.find('body').append($element);
|
2020-05-18 08:05:54 +00:00
|
|
|
tooltip = $element[0];
|
|
|
|
tooltipCtrl = tooltip.$ctrl;
|
|
|
|
window = tooltipCtrl.window;
|
|
|
|
$parent = angular.element('<div/>');
|
|
|
|
|
2018-10-19 07:33:12 +00:00
|
|
|
$document.find('body').append($parent);
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
$parent[0].getBoundingClientRect = () => {};
|
|
|
|
|
|
|
|
jest.spyOn(tooltip, 'getBoundingClientRect').mockReturnValue({bottom: 0, height: 40, left: 0, right: 0, top: 0, width: 40});
|
|
|
|
}));
|
2018-10-19 07:33:12 +00:00
|
|
|
|
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`, () => {
|
2020-05-18 08:05:54 +00:00
|
|
|
jest.spyOn($parent[0], 'getBoundingClientRect').mockReturnValue({
|
|
|
|
height: window.innerHeight - 120,
|
|
|
|
width: window.innerWidth - 120,
|
|
|
|
top: 60,
|
|
|
|
left: 60,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(tooltip.classList).not.toContain('show');
|
|
|
|
|
|
|
|
tooltipCtrl.show($parent[0]);
|
2019-11-21 10:16:10 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
let tooltipStyle = tooltip.style;
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
let tooltipTop = parseInt(tooltipStyle['top']);
|
|
|
|
let tooltipLeft = parseInt(tooltipStyle['left']);
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
expect(tooltip.classList).toContain('show');
|
2018-10-15 10:46:56 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
expect(tooltipTop).toBeLessThanOrEqual(window.innerHeight);
|
|
|
|
expect(tooltipTop).toBeGreaterThanOrEqual(0);
|
|
|
|
expect(tooltipLeft).toBeLessThanOrEqual(window.innerWidth);
|
|
|
|
expect(tooltipLeft).toBeGreaterThanOrEqual(0);
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hide()', () => {
|
2020-05-18 08:05:54 +00:00
|
|
|
it('should check that tooltip is not visible', () => {
|
|
|
|
jest.spyOn($parent[0], 'getBoundingClientRect').mockReturnValue({
|
|
|
|
height: window.innerHeight,
|
|
|
|
width: window.innerWidth - 80,
|
|
|
|
top: 0,
|
|
|
|
left: 60,
|
|
|
|
});
|
|
|
|
tooltipCtrl.show($parent[0]);
|
2019-11-21 10:16:10 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
expect(tooltip.classList).toContain('show');
|
|
|
|
tooltipCtrl.hide();
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
expect(tooltip.classList).not.toContain('show');
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-31 07:51:10 +00:00
|
|
|
describe('relocate()', () => {
|
2020-05-18 08:05:54 +00:00
|
|
|
it('should reallocate tooltip to the left', () => {
|
|
|
|
jest.spyOn($parent[0], 'getBoundingClientRect').mockReturnValue({
|
|
|
|
height: window.innerHeight,
|
|
|
|
width: window.innerWidth - 80,
|
|
|
|
top: 0,
|
|
|
|
left: 60,
|
|
|
|
});
|
2018-10-19 07:33:12 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
tooltipCtrl.position = 'left';
|
|
|
|
tooltipCtrl.show($parent[0]);
|
2018-10-15 10:46:56 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
let tooltipStyle = tooltip.style;
|
|
|
|
|
|
|
|
let tooltipTop = parseInt(tooltipStyle['top']);
|
|
|
|
let tooltipLeft = parseInt(tooltipStyle['left']);
|
2018-10-19 07:33:12 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
expect(tooltipTop).toEqual((window.innerHeight / 2) - (tooltipCtrl.margin * 2));
|
|
|
|
expect(tooltipLeft).toEqual(tooltipCtrl.margin);
|
2018-10-15 10:46:56 +00:00
|
|
|
});
|
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
it('should reallocate tooltip on bottom', () => {
|
|
|
|
let parentHeight = window.innerHeight - 80;
|
|
|
|
jest.spyOn($parent[0], 'getBoundingClientRect').mockReturnValue({
|
|
|
|
height: parentHeight,
|
|
|
|
width: window.innerWidth,
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2018-10-19 07:33:12 +00:00
|
|
|
});
|
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
tooltipCtrl.position = 'bottom';
|
|
|
|
tooltipCtrl.show($parent[0]);
|
|
|
|
|
|
|
|
let tooltipStyle = tooltip.style;
|
|
|
|
|
|
|
|
let tooltipTop = parseInt(tooltipStyle['top']);
|
|
|
|
let tooltipLeft = parseInt(tooltipStyle['left']);
|
|
|
|
|
|
|
|
expect(tooltipLeft).toEqual((window.innerWidth / 2) - (tooltipCtrl.margin * 2));
|
|
|
|
expect(tooltipTop).toEqual(parentHeight + tooltipCtrl.margin);
|
2018-10-15 10:46:56 +00:00
|
|
|
});
|
2018-09-26 12:15:00 +00:00
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
it(`should reallocate tooltip on right`, () => {
|
|
|
|
let parentWidth = window.innerWidth - 80;
|
|
|
|
jest.spyOn($parent[0], 'getBoundingClientRect').mockReturnValue({
|
|
|
|
height: window.innerHeight,
|
|
|
|
width: parentWidth,
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2018-10-19 07:33:12 +00:00
|
|
|
});
|
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
tooltipCtrl.position = 'right';
|
|
|
|
tooltipCtrl.show($parent[0]);
|
|
|
|
|
|
|
|
let tooltipStyle = tooltip.style;
|
|
|
|
|
|
|
|
let tooltipTop = parseInt(tooltipStyle['top']);
|
|
|
|
let tooltipLeft = parseInt(tooltipStyle['left']);
|
|
|
|
|
|
|
|
expect(tooltipLeft).toEqual(parentWidth + tooltipCtrl.margin);
|
|
|
|
expect(tooltipTop).toEqual((window.innerHeight / 2) - (tooltipCtrl.margin * 2));
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
it(`should reallocate tooltip on top`, () => {
|
|
|
|
jest.spyOn($parent[0], 'getBoundingClientRect').mockReturnValue({
|
|
|
|
height: window.innerHeight - 80,
|
|
|
|
width: window.innerWidth,
|
|
|
|
top: 60,
|
|
|
|
left: 0,
|
2018-10-19 07:33:12 +00:00
|
|
|
});
|
|
|
|
|
2020-05-18 08:05:54 +00:00
|
|
|
tooltipCtrl.position = 'top';
|
|
|
|
tooltipCtrl.show($parent[0]);
|
|
|
|
|
|
|
|
let tooltipStyle = tooltip.style;
|
|
|
|
|
|
|
|
let tooltipTop = parseInt(tooltipStyle['top']);
|
|
|
|
let tooltipLeft = parseInt(tooltipStyle['left']);
|
|
|
|
|
|
|
|
expect(tooltipLeft).toEqual((window.innerWidth / 2) - (tooltipCtrl.margin * 2));
|
|
|
|
expect(tooltipTop).toEqual(tooltipCtrl.margin);
|
2018-09-26 12:15:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|