2022-03-25 16:31:40 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-03-25 16:31:40 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00: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-25 16:31:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import { blobIsAnimated, mayBeAnimated } from "../../src/utils/Image";
|
2022-03-25 16:31:40 +00:00
|
|
|
|
|
|
|
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 08:38:54 +00:00
|
|
|
expect(mayBeAnimated("image/png")).toBeTruthy();
|
|
|
|
});
|
|
|
|
it("image/apng", async () => {
|
|
|
|
expect(mayBeAnimated("image/apng")).toBeTruthy();
|
2022-03-25 16:31:40 +00:00
|
|
|
});
|
|
|
|
it("image/jpeg", async () => {
|
|
|
|
expect(mayBeAnimated("image/jpeg")).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("blobIsAnimated", () => {
|
|
|
|
it("Animated GIF", async () => {
|
2022-03-28 08:38:54 +00:00
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "animated-logo.gif"))]);
|
|
|
|
expect(await blobIsAnimated("image/gif", img)).toBeTruthy();
|
2022-03-25 16:31:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Static GIF", async () => {
|
2022-03-28 08:38:54 +00:00
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "static-logo.gif"))]);
|
|
|
|
expect(await blobIsAnimated("image/gif", img)).toBeFalsy();
|
2022-03-25 16:31:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Animated WEBP", async () => {
|
2022-03-28 08:38:54 +00:00
|
|
|
const img = new Blob([fs.readFileSync(path.resolve(__dirname, "images", "animated-logo.webp"))]);
|
|
|
|
expect(await blobIsAnimated("image/webp", img)).toBeTruthy();
|
2022-03-25 16:31:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Static WEBP", async () => {
|
2022-03-28 08:38:54 +00: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-25 16:31:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|