2020-04-04 12:55:22 +01:00
|
|
|
import { getPerfectElementSize } from "./sizeHelpers";
|
|
|
|
import * as constants from "../constants";
|
|
|
|
|
2022-08-05 16:52:46 +02:00
|
|
|
const EPSILON_DIGITS = 3;
|
|
|
|
|
2020-04-04 12:55:22 +01:00
|
|
|
describe("getPerfectElementSize", () => {
|
|
|
|
it("should return height:0 if `elementType` is line and locked angle is 0", () => {
|
2020-05-23 17:45:05 +09:00
|
|
|
const { height, width } = getPerfectElementSize("line", 149, 10);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(149, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(0, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
|
|
|
it("should return width:0 if `elementType` is line and locked angle is 90 deg (Math.PI/2)", () => {
|
2020-05-23 17:45:05 +09:00
|
|
|
const { height, width } = getPerfectElementSize("line", 10, 140);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(0, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(140, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
|
|
|
it("should return height:0 if `elementType` is arrow and locked angle is 0", () => {
|
2020-05-23 17:45:05 +09:00
|
|
|
const { height, width } = getPerfectElementSize("arrow", 200, 20);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(200, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(0, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
|
|
|
it("should return width:0 if `elementType` is arrow and locked angle is 90 deg (Math.PI/2)", () => {
|
|
|
|
const { height, width } = getPerfectElementSize("arrow", 10, 100);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(0, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(100, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
|
|
|
it("should return adjust height to be width * tan(locked angle)", () => {
|
|
|
|
const { height, width } = getPerfectElementSize("arrow", 120, 185);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(120, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(207.846, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
|
|
|
it("should return height equals to width if locked angle is 45 deg", () => {
|
|
|
|
const { height, width } = getPerfectElementSize("arrow", 135, 145);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(135, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(135, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
2022-03-02 01:07:12 -05:00
|
|
|
it("should return height:0 and width:0 when width and height are 0", () => {
|
2020-04-04 12:55:22 +01:00
|
|
|
const { height, width } = getPerfectElementSize("arrow", 0, 0);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(0, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(0, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("should respond to SHIFT_LOCKING_ANGLE constant", () => {
|
|
|
|
it("should have only 2 locking angles per section if SHIFT_LOCKING_ANGLE = 45 deg (Math.PI/4)", () => {
|
|
|
|
(constants as any).SHIFT_LOCKING_ANGLE = Math.PI / 4;
|
|
|
|
const { height, width } = getPerfectElementSize("arrow", 120, 185);
|
2022-08-05 16:52:46 +02:00
|
|
|
expect(width).toBeCloseTo(120, EPSILON_DIGITS);
|
|
|
|
expect(height).toBeCloseTo(120, EPSILON_DIGITS);
|
2020-04-04 12:55:22 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|