2022-03-26 00:31:40 +08:00
|
|
|
/*
|
2024-09-09 21:57:16 +08:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-03-26 00:31:40 +08:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 21:57:16 +08:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-03-26 00:31:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
|
|
|
|
|
|
|
import { blobIsAnimated, mayBeAnimated } from "../src/utils/Image";
|
|
|
|
|
|
|
|
describe("Image", () => {
|
|
|
|
describe("mayBeAnimated", () => {
|
|
|
|
it("image/gif", async () => {
|
|
|
|
expect(mayBeAnimated("image/gif")).toBeTruthy();
|
|
|
|
});
|
|
|
|
it("image/webp", async () => {
|
|
|
|
expect(mayBeAnimated("image/webp")).toBeTruthy();
|
|
|
|
});
|
|
|
|
it("image/png", async () => {
|
2022-03-28 16:38:54 +08:00
|
|
|
expect(mayBeAnimated("image/png")).toBeTruthy();
|
|
|
|
});
|
|
|
|
it("image/apng", async () => {
|
|
|
|
expect(mayBeAnimated("image/apng")).toBeTruthy();
|
2022-03-26 00:31:40 +08:00
|
|
|
});
|
|
|
|
it("image/jpeg", async () => {
|
|
|
|
expect(mayBeAnimated("image/jpeg")).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("blobIsAnimated", () => {
|
|
|
|
it("Animated GIF", async () => {
|
2022-03-28 16:38:54 +08:00
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "animated-logo.gif"))]);
|
|
|
|
expect(await blobIsAnimated("image/gif", img)).toBeTruthy();
|
2022-03-26 00:31:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Static GIF", async () => {
|
2022-03-28 16:38:54 +08:00
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "static-logo.gif"))]);
|
|
|
|
expect(await blobIsAnimated("image/gif", img)).toBeFalsy();
|
2022-03-26 00:31:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Animated WEBP", async () => {
|
2022-03-28 16:38:54 +08:00
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "animated-logo.webp"))]);
|
|
|
|
expect(await blobIsAnimated("image/webp", img)).toBeTruthy();
|
2022-03-26 00:31:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Static WEBP", async () => {
|
2022-03-28 16:38:54 +08:00
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "static-logo.webp"))]);
|
|
|
|
expect(await blobIsAnimated("image/webp", img)).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Animated PNG", async () => {
|
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "animated-logo.apng"))]);
|
|
|
|
expect(await blobIsAnimated("image/png", img)).toBeTruthy();
|
|
|
|
expect(await blobIsAnimated("image/apng", img)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Static PNG", async () => {
|
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "static-logo.png"))]);
|
|
|
|
expect(await blobIsAnimated("image/png", img)).toBeFalsy();
|
|
|
|
expect(await blobIsAnimated("image/apng", img)).toBeFalsy();
|
2022-03-26 00:31:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|