Files
docx-js/src/file/media/media.spec.ts

66 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-11-02 00:42:49 +00:00
// tslint:disable:object-literal-key-quotes
2023-06-05 00:33:43 +01:00
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2018-11-01 02:22:32 +00:00
import * as convenienceFunctions from "@util/convenience-functions";
2018-11-01 02:22:32 +00:00
import { Media } from "./media";
describe("Media", () => {
2023-06-05 00:33:43 +01:00
beforeEach(() => {
vi.spyOn(convenienceFunctions, "uniqueId").mockReturnValue("test");
2021-03-12 03:58:05 +00:00
});
2023-06-05 00:33:43 +01:00
afterEach(() => {
vi.resetAllMocks();
2021-03-12 03:58:05 +00:00
});
2023-03-17 00:20:55 +00:00
describe("#Array", () => {
it("Get images as array", () => {
2018-11-01 02:22:32 +00:00
const media = new Media();
media.addImage("test2.png", {
type: "png",
data: Buffer.from(""),
2023-03-17 00:54:29 +00:00
fileName: "test.png",
transformation: {
pixels: {
2023-03-17 00:54:29 +00:00
x: Math.round(100),
y: Math.round(100),
},
flip: {
vertical: true,
horizontal: true,
},
emus: {
x: Math.round(1 * 9525),
y: Math.round(1 * 9525),
},
2023-03-17 00:54:29 +00:00
rotation: 90,
2018-11-01 02:22:32 +00:00
},
});
const array = media.Array;
expect(array).to.be.an.instanceof(Array);
expect(array.length).to.equal(1);
const image = array[0];
expect(image.fileName).to.equal("test.png");
2021-03-15 02:41:37 +00:00
expect(image.transformation).to.deep.equal({
2018-11-01 02:22:32 +00:00
pixels: {
x: 100,
y: 100,
},
2021-03-15 02:41:37 +00:00
flip: {
vertical: true,
horizontal: true,
},
2018-11-01 02:22:32 +00:00
emus: {
2023-03-17 00:54:29 +00:00
x: 9525,
y: 9525,
2018-11-01 02:22:32 +00:00
},
2023-03-17 00:54:29 +00:00
rotation: 90,
2018-11-01 02:22:32 +00:00
});
});
});
});