Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
*.iml
dist/
node_modules
.parcel-cache
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint && yarn test
9 changes: 0 additions & 9 deletions app/components/photo-editor/index.spec.ts

This file was deleted.

57 changes: 0 additions & 57 deletions app/components/photo-editor/index.tsx

This file was deleted.

16 changes: 16 additions & 0 deletions app/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const appConfig = {
/**
* Specifies the number of pixels per inch used for rendering and measurements.
* */
PIXELS_PER_INCH: 40,

/**
* Specifies the width of the canvas in inches
* */
CANVAS_WIDTH_INCHES: 15,

/**
* Specifies the height of the canvas in inches
* */
CANVAS_HEIGHT_INCHES: 10,
};
84 changes: 84 additions & 0 deletions app/features/photo-editor/components/photo-editor/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { act, render, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { PhotoEditor } from "@/features/photo-editor/components/photo-editor/index";

describe("PhotoEditor", () => {
beforeEach(() => {
render(<PhotoEditor />);
});

it("renders PhotoEditor and doesnt crash", () => {
expect(screen.getByTestId("photo-editor")).toBeDefined();
});

it("renders PhotoEditor file input", () => {
expect(screen.getByTestId("photo-editor-file-input")).toBeDefined();
});

it("renders PhotoEditor canvas", () => {
expect(screen.getByTestId("photo-editor-canvas")).toBeDefined();
});

it("can insert a base64 image file", async () => {
const user = userEvent.setup();

// Base64 image data
const base64Image =
"iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQ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MK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMO0TAAD//2Anhf4QtqobAAAAAElFTkSuQmCC";

// Convert base64 to Blob
const blob = await fetch(`data:image/png;base64,${base64Image}`).then(
(res) => res.blob(),
);

// Create File from Blob
const file = new File([blob], "image.png", { type: "image/png" });

const fileInput = screen.getByTestId("photo-editor-file-input");

await act(async () => {
await user.upload(fileInput, file);

const fileReader = new FileReader();

fileReader.onload = () => {
expect(fileReader.result as string).toBe(
`data:image/png;base64,${base64Image}`,
);
};

expect(fileInput.files[0]).toBe(file);
expect(fileInput.files[0].type).toBe("image/png");
expect(fileInput.files.length).toBe(1);
});
});

it("can insert JSON file", async () => {
const jsonInput = screen.getByTestId("photo-editor-json-input");

const user = userEvent.setup();

const file = new File(
[
JSON.stringify({
id: "12345",
src: "https://example.com/image.png",
width: 100,
height: 100,
x: 0,
y: 0,
}),
],
"example.json",
{ type: "application/json" },
);

await act(async () => {
await user.upload(jsonInput, file);

expect(jsonInput.files[0]).toBe(file);
expect(jsonInput.files[0].type).toBe("application/json");
expect(jsonInput.files.length).toBe(1);
});
});
});
Loading