Files
MagicMirror/tests/e2e/animateCSS_spec.js
T

108 lines
3.8 KiB
JavaScript
Raw Normal View History

const { expect } = require("playwright/test");
2024-01-01 15:38:08 +01:00
const helpers = require("./helpers/global-setup");
2023-10-01 20:13:41 +02:00
2025-09-15 23:58:55 +02:00
// Validate Animate.css integration for compliments module using class toggling.
// We intentionally ignore computed animation styles (jsdom doesn't simulate real animations).
2023-10-01 20:13:41 +02:00
describe("AnimateCSS integration Test", () => {
let page;
2025-09-15 23:58:55 +02:00
// Config variants under test
const TEST_CONFIG_ANIM = "tests/configs/modules/compliments/compliments_animateCSS.js";
const TEST_CONFIG_FALLBACK = "tests/configs/modules/compliments/compliments_animateCSS_fallbackToDefault.js"; // invalid animation names
const TEST_CONFIG_INVERTED = "tests/configs/modules/compliments/compliments_animateCSS_invertedAnimationName.js"; // in/out swapped
const TEST_CONFIG_NONE = "tests/configs/modules/compliments/compliments_anytime.js"; // no animations defined
2023-10-01 20:13:41 +02:00
/**
2025-09-15 23:58:55 +02:00
* Get the compliments container element (waits until available).
* @returns {Promise<void>}
2023-10-01 20:13:41 +02:00
*/
2025-09-15 23:58:55 +02:00
async function getComplimentsElement () {
2023-10-01 20:13:41 +02:00
await helpers.getDocument();
page = helpers.getPage();
await expect(page.locator(".compliments")).toBeVisible();
2025-09-15 23:58:55 +02:00
}
2023-10-01 20:13:41 +02:00
2025-09-15 23:58:55 +02:00
/**
* Wait for an Animate.css class to appear and persist briefly.
* @param {string} cls Animation class name without leading dot (e.g. animate__flipInX)
* @param {{timeout?: number}} [options] Poll timeout in ms (default 6000)
* @returns {Promise<void>}
2025-09-15 23:58:55 +02:00
*/
async function waitForAnimationClass (cls, { timeout = 6000 } = {}) {
const locator = page.locator(`.compliments.animate__animated.${cls}`);
await locator.waitFor({ state: "attached", timeout });
// small stability wait
await new Promise((r) => setTimeout(r, 50));
await expect(locator).toBeAttached();
2025-09-15 23:58:55 +02:00
}
2023-10-01 20:13:41 +02:00
2025-09-15 23:58:55 +02:00
/**
* Assert that no Animate.css animation class is applied within a time window.
* @param {number} [ms] Observation period in ms (default 2000)
* @returns {Promise<void>}
*/
async function assertNoAnimationWithin (ms = 2000) {
const start = Date.now();
const locator = page.locator(".compliments.animate__animated");
2025-09-15 23:58:55 +02:00
while (Date.now() - start < ms) {
const count = await locator.count();
if (count > 0) {
2025-09-15 23:58:55 +02:00
throw new Error("Unexpected animate__animated class present in non-animation scenario");
}
await new Promise((r) => setTimeout(r, 100));
}
}
/**
* Run one animation test scenario.
* @param {string} [animationIn] Expected animate-in name
* @param {string} [animationOut] Expected animate-out name
* @returns {Promise<void>} Throws on assertion failure
2025-09-15 23:58:55 +02:00
*/
async function runAnimationTest (animationIn, animationOut) {
await getComplimentsElement();
if (!animationIn && !animationOut) {
await assertNoAnimationWithin(2000);
return;
2025-09-15 23:58:55 +02:00
}
if (animationIn) await waitForAnimationClass(`animate__${animationIn}`);
if (animationOut) {
// Wait just beyond one update cycle (updateInterval=2000ms) before expecting animateOut.
await new Promise((r) => setTimeout(r, 2100));
await waitForAnimationClass(`animate__${animationOut}`);
2023-10-01 20:13:41 +02:00
}
2025-09-15 23:58:55 +02:00
}
2023-10-01 20:13:41 +02:00
afterEach(async () => {
await helpers.stopApplication();
});
describe("animateIn and animateOut Test", () => {
it("with flipInX and flipOutX animation", async () => {
2025-09-15 23:58:55 +02:00
await helpers.startApplication(TEST_CONFIG_ANIM);
await runAnimationTest("flipInX", "flipOutX");
2023-10-01 20:13:41 +02:00
});
});
describe("use animateOut name for animateIn (vice versa) Test", () => {
2025-09-15 23:58:55 +02:00
it("without animation (inverted names)", async () => {
await helpers.startApplication(TEST_CONFIG_INVERTED);
await runAnimationTest();
2023-10-01 20:13:41 +02:00
});
});
describe("false Animation name test", () => {
2025-09-15 23:58:55 +02:00
it("without animation (invalid names)", async () => {
await helpers.startApplication(TEST_CONFIG_FALLBACK);
await runAnimationTest();
2023-10-01 20:13:41 +02:00
});
});
describe("no Animation defined test", () => {
2025-09-15 23:58:55 +02:00
it("without animation (no config)", async () => {
await helpers.startApplication(TEST_CONFIG_NONE);
await runAnimationTest();
2023-10-01 20:13:41 +02:00
});
});
});