sizeHelpers.test.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { getPerfectElementSize } from "./sizeHelpers";
  2. import * as constants from "../constants";
  3. describe("getPerfectElementSize", () => {
  4. it("should return height:0 if `elementType` is line and locked angle is 0", () => {
  5. const { height, width } = getPerfectElementSize("line", 149, 10);
  6. expect(width).toEqual(149);
  7. expect(height).toEqual(0);
  8. });
  9. it("should return width:0 if `elementType` is line and locked angle is 90 deg (Math.PI/2)", () => {
  10. const { height, width } = getPerfectElementSize("line", 10, 140);
  11. expect(width).toEqual(0);
  12. expect(height).toEqual(140);
  13. });
  14. it("should return height:0 if `elementType` is arrow and locked angle is 0", () => {
  15. const { height, width } = getPerfectElementSize("arrow", 200, 20);
  16. expect(width).toEqual(200);
  17. expect(height).toEqual(0);
  18. });
  19. it("should return width:0 if `elementType` is arrow and locked angle is 90 deg (Math.PI/2)", () => {
  20. const { height, width } = getPerfectElementSize("arrow", 10, 100);
  21. expect(width).toEqual(0);
  22. expect(height).toEqual(100);
  23. });
  24. it("should return adjust height to be width * tan(locked angle)", () => {
  25. const { height, width } = getPerfectElementSize("arrow", 120, 185);
  26. expect(width).toEqual(120);
  27. expect(height).toEqual(208);
  28. });
  29. it("should return height equals to width if locked angle is 45 deg", () => {
  30. const { height, width } = getPerfectElementSize("arrow", 135, 145);
  31. expect(width).toEqual(135);
  32. expect(height).toEqual(135);
  33. });
  34. it("should return height:0 and width:0 when width and heigh are 0", () => {
  35. const { height, width } = getPerfectElementSize("arrow", 0, 0);
  36. expect(width).toEqual(0);
  37. expect(height).toEqual(0);
  38. });
  39. describe("should respond to SHIFT_LOCKING_ANGLE constant", () => {
  40. it("should have only 2 locking angles per section if SHIFT_LOCKING_ANGLE = 45 deg (Math.PI/4)", () => {
  41. (constants as any).SHIFT_LOCKING_ANGLE = Math.PI / 4;
  42. const { height, width } = getPerfectElementSize("arrow", 120, 185);
  43. expect(width).toEqual(120);
  44. expect(height).toEqual(120);
  45. });
  46. });
  47. });