import { expect, fixture, html } from '@open-wc/testing';
import '../../button/lion-button.js';
import '../lion-tooltip-arrow.js';
import '../lion-tooltip.js';
describe('lion-tooltip-arrow', () => {
it('has a visual "arrow" element inside the content node', async () => {
const el = await fixture(html`
Tooltip button
Hey there
`);
const arrowEl = el.querySelector('lion-tooltip-arrow');
expect(arrowEl).dom.to.equal(``, {
ignoreAttributes: ['slot', 'placement', 'x-arrow', 'style'],
});
});
it('reflects popper placement in its own placement property and attribute', async () => {
const el = await fixture(html`
Tooltip button
Hey there
`);
el.opened = true;
const arrowElement = el.querySelector('lion-tooltip-arrow');
await el.repositionComplete;
expect(arrowElement.getAttribute('placement')).to.equal('right');
el.config = { popperConfig: { placement: 'bottom' } };
// TODO: Remove this once changing configurations no longer closes your overlay
// Currently it closes your overlay but doesn't set opened to false >:(
el.opened = false;
el.opened = true;
await el.repositionComplete;
expect(arrowElement.getAttribute('placement')).to.equal('bottom');
});
it('makes sure positioning of the arrow is correct', async () => {
const el = await fixture(html`
Hey there
Tooltip button
`);
const arrowElement = el.querySelector('lion-tooltip-arrow');
el.opened = true;
await el.repositionComplete;
expect(getComputedStyle(arrowElement).getPropertyValue('top')).to.equal(
'12px',
'30px (content height) - 6px (arrow width) = 24px, divided by 2 = 12px offset --> arrow is in the middle',
);
expect(
getComputedStyle(el.querySelector('lion-tooltip-arrow')).getPropertyValue('left'),
).to.equal(
'-6px',
'arrow width is 6px so this offset should be taken into account to align the arrow properly',
);
});
});