|
1 | | -import { expect, fixture, html } from '@open-wc/testing'; |
| 1 | +import { clickOnElement } from '../../internal/test'; |
| 2 | +import { expect, fixture, html, oneEvent } from '@open-wc/testing'; |
| 3 | +import type SlAnimatedImage from './animated-image'; |
2 | 4 |
|
3 | 5 | describe('<sl-animated-image>', () => { |
4 | 6 | it('should render a component', async () => { |
5 | | - const el = await fixture(html` <sl-animated-image></sl-animated-image> `); |
| 7 | + const animatedImage = await fixture(html` <sl-animated-image></sl-animated-image> `); |
6 | 8 |
|
7 | | - expect(el).to.exist; |
| 9 | + expect(animatedImage).to.exist; |
| 10 | + }); |
| 11 | + |
| 12 | + it('should render be accessible', async () => { |
| 13 | + const animatedImage = await fixture(html` <sl-animated-image></sl-animated-image> `); |
| 14 | + |
| 15 | + await expect(animatedImage).to.be.accessible(); |
| 16 | + }); |
| 17 | + |
| 18 | + const files = ['docs/assets/images/walk.gif', 'docs/assets/images/tie.webp']; |
| 19 | + |
| 20 | + files.forEach((file: string) => { |
| 21 | + it(`should load a ${file} without errors`, async () => { |
| 22 | + const animatedImage = await fixture<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `); |
| 23 | + let errorCount = 0; |
| 24 | + oneEvent(animatedImage, 'sl-error').then(() => errorCount++); |
| 25 | + await loadImage(animatedImage, file); |
| 26 | + |
| 27 | + expect(errorCount).to.be.equal(0); |
| 28 | + }); |
| 29 | + |
| 30 | + it(`should play ${file} on click`, async () => { |
| 31 | + const animatedImage = await fixture<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `); |
| 32 | + await loadImage(animatedImage, file); |
| 33 | + |
| 34 | + expect(animatedImage.play).not.to.be.true; |
| 35 | + |
| 36 | + await clickOnElement(animatedImage); |
| 37 | + |
| 38 | + expect(animatedImage.play).to.be.true; |
| 39 | + }); |
| 40 | + |
| 41 | + it(`should pause and resume ${file} on click`, async () => { |
| 42 | + const animatedImage = await fixture<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `); |
| 43 | + await loadImage(animatedImage, file); |
| 44 | + |
| 45 | + animatedImage.play = true; |
| 46 | + |
| 47 | + await clickOnElement(animatedImage); |
| 48 | + |
| 49 | + expect(animatedImage.play).to.be.false; |
| 50 | + |
| 51 | + await clickOnElement(animatedImage); |
| 52 | + |
| 53 | + expect(animatedImage.play).to.be.true; |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should emit an error event on invalid url', async () => { |
| 58 | + const animatedImage = await fixture<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `); |
| 59 | + |
| 60 | + const errorPromise = oneEvent(animatedImage, 'sl-error'); |
| 61 | + animatedImage.src = 'completelyWrong'; |
| 62 | + |
| 63 | + await errorPromise; |
8 | 64 | }); |
9 | 65 | }); |
| 66 | +async function loadImage(animatedImage: SlAnimatedImage, file: string) { |
| 67 | + const loadingPromise = oneEvent(animatedImage, 'sl-load'); |
| 68 | + animatedImage.src = file; |
| 69 | + await loadingPromise; |
| 70 | +} |
0 commit comments