2018-11-02 00:42:49 +00:00
|
|
|
// tslint:disable:object-literal-key-quotes
|
2018-11-01 02:22:32 +00:00
|
|
|
import { expect } from "chai";
|
2021-03-12 03:58:05 +00:00
|
|
|
import { SinonStub, stub } from "sinon";
|
2018-11-01 02:22:32 +00:00
|
|
|
|
2022-06-26 23:26:42 +01:00
|
|
|
import * as convenienceFunctions from "@util/convenience-functions";
|
2018-11-01 02:22:32 +00:00
|
|
|
|
|
|
|
import { Media } from "./media";
|
|
|
|
|
|
|
|
describe("Media", () => {
|
2021-03-12 03:58:05 +00:00
|
|
|
before(() => {
|
|
|
|
stub(convenienceFunctions, "uniqueId").callsFake(() => "test");
|
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
(convenienceFunctions.uniqueId as SinonStub).restore();
|
|
|
|
});
|
|
|
|
|
2018-11-01 02:22:32 +00:00
|
|
|
describe("#addMedia", () => {
|
|
|
|
it("should add media", () => {
|
2021-03-15 02:41:37 +00:00
|
|
|
const image = new Media().addMedia("", {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
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: undefined,
|
2018-11-01 02:22:32 +00:00
|
|
|
emus: {
|
|
|
|
x: 952500,
|
|
|
|
y: 952500,
|
|
|
|
},
|
2021-03-15 02:41:37 +00:00
|
|
|
rotation: undefined,
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return UInt8Array if atob is present", () => {
|
2021-03-13 22:43:21 +00:00
|
|
|
global.atob = () => "atob result";
|
2018-11-01 02:22:32 +00:00
|
|
|
|
2021-03-15 02:41:37 +00:00
|
|
|
const image = new Media().addMedia("", {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
expect(image.stream).to.be.an.instanceof(Uint8Array);
|
2021-03-13 22:43:21 +00:00
|
|
|
|
|
|
|
// tslint:disable-next-line: no-any
|
|
|
|
(global as any).atob = undefined;
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2019-09-29 04:17:21 +01:00
|
|
|
|
|
|
|
it("should use data as is if its not a string", () => {
|
2021-03-13 22:43:21 +00:00
|
|
|
global.atob = () => "atob result";
|
2019-09-29 04:17:21 +01:00
|
|
|
|
2021-03-15 02:41:37 +00:00
|
|
|
const image = new Media().addMedia(Buffer.from(""), {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
});
|
2019-09-29 04:17:21 +01:00
|
|
|
expect(image.stream).to.be.an.instanceof(Uint8Array);
|
2021-03-13 22:43:21 +00:00
|
|
|
|
|
|
|
// tslint:disable-next-line: no-any
|
|
|
|
(global as any).atob = undefined;
|
2019-09-29 04:17:21 +01:00
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
|
2021-03-18 02:48:37 +00:00
|
|
|
describe("#addImage", () => {
|
|
|
|
it("should add media", () => {
|
2018-11-01 02:22:32 +00:00
|
|
|
const media = new Media();
|
2021-03-15 02:41:37 +00:00
|
|
|
media.addMedia("", {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
|
2021-03-18 02:48:37 +00:00
|
|
|
media.addImage("test2.png", {
|
|
|
|
stream: Buffer.from(""),
|
|
|
|
fileName: "",
|
|
|
|
transformation: {
|
|
|
|
pixels: {
|
|
|
|
x: Math.round(1),
|
|
|
|
y: Math.round(1),
|
|
|
|
},
|
|
|
|
emus: {
|
|
|
|
x: Math.round(1 * 9525),
|
|
|
|
y: Math.round(1 * 9525),
|
|
|
|
},
|
2018-11-01 02:22:32 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-03-18 02:48:37 +00:00
|
|
|
expect(media.Array).to.be.lengthOf(2);
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#Array", () => {
|
|
|
|
it("Get images as array", () => {
|
|
|
|
const media = new Media();
|
2021-03-15 02:41:37 +00:00
|
|
|
media.addMedia("", {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
flip: {
|
|
|
|
vertical: true,
|
|
|
|
horizontal: true,
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
x: 952500,
|
|
|
|
y: 952500,
|
|
|
|
},
|
2021-03-15 02:41:37 +00:00
|
|
|
rotation: 5400000,
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|