First implementation of Plimi
This commit is contained in:
51
src/tools/qr-code-generator/run.test.ts
Normal file
51
src/tools/qr-code-generator/run.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { runQrCodeGenerator } from "./run";
|
||||
import type { ToolContext } from "../../core/plugins/plugin-types";
|
||||
|
||||
describe("QR Code Generator Plugin", () => {
|
||||
const mockContext: ToolContext = {
|
||||
signal: new AbortController().signal,
|
||||
reportProgress: vi.fn(),
|
||||
logger: {
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
it("should generate SVG QR Code successfully", async () => {
|
||||
const result = await runQrCodeGenerator(
|
||||
{ text: "https://plimi.app" },
|
||||
{ size: 256, margin: 4, errorCorrection: "M", format: "svg" },
|
||||
mockContext
|
||||
);
|
||||
expect(result.type).toBe("files");
|
||||
if (result.type === "files") {
|
||||
expect(result.files).toHaveLength(1);
|
||||
expect(result.files[0].name).toBe("qrcode.svg");
|
||||
expect(result.files[0].mimeType).toBe("image/svg+xml");
|
||||
expect(result.files[0].blob).toBeInstanceOf(Blob);
|
||||
}
|
||||
});
|
||||
|
||||
it("should generate PNG QR Code successfully", async () => {
|
||||
const result = await runQrCodeGenerator(
|
||||
{ text: "https://plimi.app" },
|
||||
{ size: 256, margin: 4, errorCorrection: "M", format: "png" },
|
||||
mockContext
|
||||
);
|
||||
expect(result.type).toBe("files");
|
||||
if (result.type === "files") {
|
||||
expect(result.files).toHaveLength(1);
|
||||
expect(result.files[0].name).toBe("qrcode.png");
|
||||
expect(result.files[0].mimeType).toBe("image/png");
|
||||
expect(result.files[0].blob).toBeInstanceOf(Blob);
|
||||
}
|
||||
});
|
||||
|
||||
it("should throw error for empty input text", async () => {
|
||||
await expect(
|
||||
runQrCodeGenerator({ text: "" }, { size: 256, margin: 4, errorCorrection: "M", format: "svg" }, mockContext)
|
||||
).rejects.toThrow("Please enter text or a URL to encode in the QR Code.");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user