codify-node
Version:
Generates 1D, 2D, and composite barcodes in png, svg, or eps formats.
73 lines • 2.76 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const pngjs_1 = require("pngjs");
const png_1 = __importDefault(require("../png"));
describe('PNG Functions', () => {
afterEach(() => jest.resetAllMocks());
describe('blobToBase64()', () => {
it('should return a base-64 image string', async () => {
const image = new pngjs_1.PNG({ width: 1, height: 1 });
const base64 = await png_1.default.blobToBase64(image);
expect(base64).toMatch(/^data:image\/png;base64,[a-z0-9\-+/]+=*$/i);
});
});
describe('getRgbaColor()', () => {
it('should parse the alpha channel for an 8-digit hex color', () => {
const color = png_1.default.getRgbaColor('ff00ff00');
expect(color).toEqual({
red: 255,
green: 0,
blue: 255,
alpha: 0
});
});
it('should parse a 6-digit hex color, with alpha channel falling back to 255', () => {
const color = png_1.default.getRgbaColor('ff00ff');
expect(color).toEqual({
red: 255,
green: 0,
blue: 255,
alpha: 255
});
});
it('should default to solid black if an invalid hex is passed in', () => {
const color = png_1.default.getRgbaColor('red');
expect(color).toEqual({
red: 0,
green: 0,
blue: 0,
alpha: 255
});
});
it('should default to solid black if no color is specified', () => {
const color = png_1.default.getRgbaColor();
expect(color).toEqual({
red: 0,
green: 0,
blue: 0,
alpha: 255
});
});
});
describe('render()', () => {
const bitmap = [
...Array(3).fill(0),
...Array(3).fill(255)
];
it('should fill in each pixel color from the given bitmap array', () => {
const result = png_1.default.render(bitmap, 1, 2, '00000000', 'ffffffff');
expect(result.data[0]).toEqual(0);
expect(result.data[1]).toEqual(0);
expect(result.data[2]).toEqual(0);
expect(result.data[3]).toEqual(0);
expect(result.data[4]).toEqual(255);
expect(result.data[5]).toEqual(255);
expect(result.data[6]).toEqual(255);
expect(result.data[7]).toEqual(255);
});
});
});
//# sourceMappingURL=png.test.js.map