Spaces:
Sleeping
Sleeping
File size: 2,337 Bytes
3530df7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import { expect, test, describe } from "vitest";
import { makeTestImage } from "@jimp/test-utils";
import { HorizontalAlign, VerticalAlign, createJimp } from "@jimp/core";
import { methods } from "./index.js";
const jimp = createJimp({ plugins: [methods] });
describe("All align combinations for contain", () => {
const vertical = jimp.fromBitmap(
makeTestImage(
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▴▴▴▴▸▸▸▸",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
"▾▾▾▾◆◆◆◆",
),
);
// stores the Jimp instances of the JGD images above.
const horizontal = jimp.fromBitmap(
makeTestImage(
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▴▴▴▴▴▴▸▸▸▸▸▸",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
"▾▾▾▾▾▾◆◆◆◆◆◆",
),
);
const tests: Array<
[keyof typeof HorizontalAlign, keyof typeof VerticalAlign]
> = [
["LEFT", "TOP"],
["CENTER", "TOP"],
["RIGHT", "TOP"],
["LEFT", "MIDDLE"],
["CENTER", "MIDDLE"],
["RIGHT", "MIDDLE"],
["LEFT", "BOTTOM"],
["CENTER", "BOTTOM"],
["RIGHT", "BOTTOM"],
];
tests.forEach(([horizontalAlign, verticalAlign]) => {
const align = horizontalAlign + " " + verticalAlign;
const alignValue =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(HorizontalAlign as any)[horizontalAlign] |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(VerticalAlign as any)[verticalAlign];
test("vertical contain aligned to " + align, () => {
expect(
vertical.clone().contain({ w: 6, h: 6, align: alignValue }),
).toMatchSnapshot();
});
test("horizontal contain aligned to " + align, () => {
expect(
horizontal.clone().contain({ w: 6, h: 6, align: alignValue }),
).toMatchSnapshot();
});
});
});
|