kopia lustrzana https://github.com/shoelace-style/shoelace
118 wiersze
4.0 KiB
TypeScript
118 wiersze
4.0 KiB
TypeScript
![]() |
import { expect, fixture, html, waitUntil } from '@open-wc/testing';
|
||
|
import sinon from 'sinon';
|
||
|
|
||
|
import '../../../dist/shoelace.js';
|
||
|
import type SlTooltip from './tooltip';
|
||
|
|
||
|
describe('<sl-tooltip>', () => {
|
||
|
it('should be visible with the open attribute', async () => {
|
||
|
const el = await fixture(html`
|
||
|
<sl-tooltip content="This is a tooltip" open>
|
||
|
<sl-button>Hover Me</sl-button>
|
||
|
</sl-tooltip>
|
||
|
`);
|
||
|
const base = el.shadowRoot?.querySelector('[part="base"]') as HTMLElement;
|
||
|
|
||
|
expect(base.hidden).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('should not be visible without the open attribute', async () => {
|
||
|
const el = await fixture(html`
|
||
|
<sl-tooltip content="This is a tooltip">
|
||
|
<sl-button>Hover Me</sl-button>
|
||
|
</sl-tooltip>
|
||
|
`);
|
||
|
const base = el.shadowRoot?.querySelector('[part="base"]') as HTMLElement;
|
||
|
|
||
|
expect(base.hidden).to.be.true;
|
||
|
});
|
||
|
|
||
|
it('should emit sl-show and sl-after-show when calling show()', async () => {
|
||
|
const el = (await fixture(html`
|
||
|
<sl-tooltip content="This is a tooltip">
|
||
|
<sl-button>Hover Me</sl-button>
|
||
|
</sl-tooltip>
|
||
|
`)) as SlTooltip;
|
||
|
const base = el.shadowRoot?.querySelector('[part="base"]') as HTMLElement;
|
||
|
const showHandler = sinon.spy();
|
||
|
const afterShowHandler = sinon.spy();
|
||
|
|
||
|
el.addEventListener('sl-show', showHandler);
|
||
|
el.addEventListener('sl-after-show', afterShowHandler);
|
||
|
el.show();
|
||
|
|
||
|
await waitUntil(() => showHandler.calledOnce);
|
||
|
await waitUntil(() => afterShowHandler.calledOnce);
|
||
|
|
||
|
expect(showHandler).to.have.been.calledOnce;
|
||
|
expect(afterShowHandler).to.have.been.calledOnce;
|
||
|
expect(base.hidden).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('should emit sl-hide and sl-after-hide when calling hide()', async () => {
|
||
|
const el = (await fixture(html`
|
||
|
<sl-tooltip content="This is a tooltip" open>
|
||
|
<sl-button>Hover Me</sl-button>
|
||
|
</sl-tooltip>
|
||
|
`)) as SlTooltip;
|
||
|
const base = el.shadowRoot?.querySelector('[part="base"]') as HTMLElement;
|
||
|
const hideHandler = sinon.spy();
|
||
|
const afterHideHandler = sinon.spy();
|
||
|
|
||
|
el.addEventListener('sl-hide', hideHandler);
|
||
|
el.addEventListener('sl-after-hide', afterHideHandler);
|
||
|
el.hide();
|
||
|
|
||
|
await waitUntil(() => hideHandler.calledOnce);
|
||
|
await waitUntil(() => afterHideHandler.calledOnce);
|
||
|
|
||
|
expect(hideHandler).to.have.been.calledOnce;
|
||
|
expect(afterHideHandler).to.have.been.calledOnce;
|
||
|
expect(base.hidden).to.be.true;
|
||
|
});
|
||
|
|
||
|
it('should emit sl-show and sl-after-show when setting open = true', async () => {
|
||
|
const el = (await fixture(html`
|
||
|
<sl-tooltip content="This is a tooltip">
|
||
|
<sl-button>Hover Me</sl-button>
|
||
|
</sl-tooltip>
|
||
|
`)) as SlTooltip;
|
||
|
const base = el.shadowRoot?.querySelector('[part="base"]') as HTMLElement;
|
||
|
const showHandler = sinon.spy();
|
||
|
const afterShowHandler = sinon.spy();
|
||
|
|
||
|
el.addEventListener('sl-show', showHandler);
|
||
|
el.addEventListener('sl-after-show', afterShowHandler);
|
||
|
el.open = true;
|
||
|
|
||
|
await waitUntil(() => showHandler.calledOnce);
|
||
|
await waitUntil(() => afterShowHandler.calledOnce);
|
||
|
|
||
|
expect(showHandler).to.have.been.calledOnce;
|
||
|
expect(afterShowHandler).to.have.been.calledOnce;
|
||
|
expect(base.hidden).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('should emit sl-hide and sl-after-hide when setting open = false', async () => {
|
||
|
const el = (await fixture(html`
|
||
|
<sl-tooltip content="This is a tooltip" open>
|
||
|
<sl-button>Hover Me</sl-button>
|
||
|
</sl-tooltip>
|
||
|
`)) as SlTooltip;
|
||
|
const base = el.shadowRoot?.querySelector('[part="base"]') as HTMLElement;
|
||
|
const hideHandler = sinon.spy();
|
||
|
const afterHideHandler = sinon.spy();
|
||
|
|
||
|
el.addEventListener('sl-hide', hideHandler);
|
||
|
el.addEventListener('sl-after-hide', afterHideHandler);
|
||
|
el.open = false;
|
||
|
|
||
|
await waitUntil(() => hideHandler.calledOnce);
|
||
|
await waitUntil(() => afterHideHandler.calledOnce);
|
||
|
|
||
|
expect(hideHandler).to.have.been.calledOnce;
|
||
|
expect(afterHideHandler).to.have.been.calledOnce;
|
||
|
expect(base.hidden).to.be.true;
|
||
|
});
|
||
|
});
|