mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
Added tests to the sl-animated-images component (#1246)
Co-authored-by: Dominikus Hellgartner <dominikus.hellgartner@gmail.com>
This commit is contained in:
@@ -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('<sl-animated-image>', () => {
|
||||
it('should render a component', async () => {
|
||||
const el = await fixture(html` <sl-animated-image></sl-animated-image> `);
|
||||
const animatedImage = await fixture(html` <sl-animated-image></sl-animated-image> `);
|
||||
|
||||
expect(el).to.exist;
|
||||
expect(animatedImage).to.exist;
|
||||
});
|
||||
|
||||
it('should render be accessible', async () => {
|
||||
const animatedImage = await fixture(html` <sl-animated-image></sl-animated-image> `);
|
||||
|
||||
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<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `);
|
||||
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<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `);
|
||||
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<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `);
|
||||
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<SlAnimatedImage>(html` <sl-animated-image></sl-animated-image> `);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user