bounds.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { getElementAbsoluteCoords } from "./bounds";
  2. import { ExcalidrawElement } from "./types";
  3. const _ce = ({ x, y, w, h }: { x: number; y: number; w: number; h: number }) =>
  4. ({
  5. type: "rectangle",
  6. strokeColor: "#000",
  7. backgroundColor: "#000",
  8. fillStyle: "solid",
  9. strokeWidth: 1,
  10. roughness: 1,
  11. opacity: 1,
  12. x,
  13. y,
  14. width: w,
  15. height: h,
  16. } as ExcalidrawElement);
  17. describe("getElementAbsoluteCoords", () => {
  18. it("test x1 coordinate", () => {
  19. const [x1] = getElementAbsoluteCoords(_ce({ x: 10, y: 0, w: 10, h: 0 }));
  20. expect(x1).toEqual(10);
  21. });
  22. it("test x2 coordinate", () => {
  23. const [, , x2] = getElementAbsoluteCoords(
  24. _ce({ x: 10, y: 0, w: 10, h: 0 }),
  25. );
  26. expect(x2).toEqual(20);
  27. });
  28. it("test y1 coordinate", () => {
  29. const [, y1] = getElementAbsoluteCoords(_ce({ x: 0, y: 10, w: 0, h: 10 }));
  30. expect(y1).toEqual(10);
  31. });
  32. it("test y2 coordinate", () => {
  33. const [, , , y2] = getElementAbsoluteCoords(
  34. _ce({ x: 0, y: 10, w: 0, h: 10 }),
  35. );
  36. expect(y2).toEqual(20);
  37. });
  38. });