diff --git a/src/components/animated-image/animated-image.test.ts b/src/components/animated-image/animated-image.test.ts index eab5e699..af9edbca 100644 --- a/src/components/animated-image/animated-image.test.ts +++ b/src/components/animated-image/animated-image.test.ts @@ -1,9 +1,70 @@ -import { expect, fixture, html } from '@open-wc/testing'; +import { clickOnElement } from '../../internal/test'; +import { expect, fixture, html, oneEvent } from '@open-wc/testing'; +import type SlAnimatedImage from './animated-image'; describe('', () => { it('should render a component', async () => { - const el = await fixture(html` `); + const animatedImage = await fixture(html` `); - expect(el).to.exist; + expect(animatedImage).to.exist; + }); + + it('should render be accessible', async () => { + const animatedImage = await fixture(html` `); + + await expect(animatedImage).to.be.accessible(); + }); + + const files = ['docs/assets/images/walk.gif', 'docs/assets/images/tie.webp']; + + files.forEach((file: string) => { + it(`should load a ${file} without errors`, async () => { + const animatedImage = await fixture(html` `); + let errorCount = 0; + oneEvent(animatedImage, 'sl-error').then(() => errorCount++); + await loadImage(animatedImage, file); + + expect(errorCount).to.be.equal(0); + }); + + it(`should play ${file} on click`, async () => { + const animatedImage = await fixture(html` `); + await loadImage(animatedImage, file); + + expect(animatedImage.play).not.to.be.true; + + await clickOnElement(animatedImage); + + expect(animatedImage.play).to.be.true; + }); + + it(`should pause and resume ${file} on click`, async () => { + const animatedImage = await fixture(html` `); + await loadImage(animatedImage, file); + + animatedImage.play = true; + + await clickOnElement(animatedImage); + + expect(animatedImage.play).to.be.false; + + await clickOnElement(animatedImage); + + expect(animatedImage.play).to.be.true; + }); + }); + + it('should emit an error event on invalid url', async () => { + const animatedImage = await fixture(html` `); + + const errorPromise = oneEvent(animatedImage, 'sl-error'); + animatedImage.src = 'completelyWrong'; + + await errorPromise; }); }); +async function loadImage(animatedImage: SlAnimatedImage, file: string) { + const loadingPromise = oneEvent(animatedImage, 'sl-load'); + animatedImage.src = file; + await loadingPromise; +}