diff --git a/src/components/animation/animation.test.ts b/src/components/animation/animation.test.ts new file mode 100644 index 00000000..270a5ab6 --- /dev/null +++ b/src/components/animation/animation.test.ts @@ -0,0 +1,81 @@ +import { aTimeout, expect, fixture, html, oneEvent } from '@open-wc/testing'; +import type SlAnimation from './animation'; + +describe('', () => { + const boxToAnimate = html`
`; + + it('renders', async () => { + const animationContainer = await fixture(html`${boxToAnimate}`); + + expect(animationContainer).to.exist; + }); + + it('is accessible', async () => { + const animationContainer = await fixture(html`${boxToAnimate}`); + + await expect(animationContainer).to.be.accessible(); + }); + + describe('animation start', () => { + it('does not start the animation by default', async () => { + const animationContainer = await fixture( + html`${boxToAnimate}` + ); + await aTimeout(0); + + expect(animationContainer.play).to.be.false; + }); + + it('emits the correct event on animation start', async () => { + const animationContainer = await fixture( + html`${boxToAnimate}` + ); + + const startPromise = oneEvent(animationContainer, 'sl-start'); + animationContainer.play = true; + return startPromise; + }); + }); + + it('emits the correct event on animation end', async () => { + const animationContainer = await fixture( + html`${boxToAnimate}` + ); + + const endPromise = oneEvent(animationContainer, 'sl-finish'); + animationContainer.iterations = 1; + animationContainer.play = true; + return endPromise; + }); + + it('can be finished by hand', async () => { + const animationContainer = await fixture( + html`${boxToAnimate}` + ); + + const endPromise = oneEvent(animationContainer, 'sl-finish'); + animationContainer.iterations = 1; + animationContainer.play = true; + + await aTimeout(0); + + animationContainer.finish(); + return endPromise; + }); + + it('can be cancelled', async () => { + const animationContainer = await fixture( + html`${boxToAnimate}` + ); + let animationHasFinished = false; + oneEvent(animationContainer, 'sl-finish').then(() => (animationHasFinished = true)); + const cancelPromise = oneEvent(animationContainer, 'sl-cancel'); + animationContainer.play = true; + + await aTimeout(0); + animationContainer.cancel(); + + await cancelPromise; + expect(animationHasFinished).to.be.false; + }); +});