Skip to content

Commit

Permalink
restore test
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Sep 25, 2023
1 parent cef5a00 commit 4293b84
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/shapes/Object/Object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Intersection } from '../../Intersection';
import { Point } from '../../Point';
import { iMatrix } from '../../constants';
import type { TMat2D } from '../../typedefs';
import { cornerPointContainsPoint } from '../../util/intersection/findCrossPoint';
import { FabricObject } from './Object';

Expand Down Expand Up @@ -127,4 +129,92 @@ describe('Object', () => {

expect(benchmark2).toBeLessThan(benchmark1);
});

describe('geometry', () => {
test.each(
(
[
[
{},
[
new Point(40, 30),
new Point(52, 30),
new Point(52, 47),
new Point(40, 47),
],
],
[
{ angle: 20 },
[
new Point(40, 30),
new Point(51.2763114494309, 34.104241719908025),
new Point(45.46196901289453, 50.079016273268465),
new Point(34.18565756346363, 45.97477455336044),
],
],
[
{ skewX: 45 },
[
new Point(40, 30),
new Point(69, 30),
new Point(69, 47),
new Point(40, 47),
],
],
[
{ skewY: 45 },
[
new Point(40, 30),
new Point(52, 30),
new Point(52, 59),
new Point(40, 59),
],
],
[
{ skewY: 45, skewX: 30, angle: 90 },
[
new Point(40, 30),
new Point(40, 58.74315780649914),
new Point(11, 58.74315780649914),
new Point(11, 30),
],
],
] as const
)
.map(
([options, expected]) =>
[
[options, undefined, expected],
[options, [2, 0, 0, 2, 35, 35] as TMat2D, expected],
] as const
)
.flat()
)(
'getCoords %p and viewportTransform of %p',
(options, viewportTransform = iMatrix, expected) => {
const object = new FabricObject({
width: 10,
height: 15,
strokeWidth: 2,
top: 30,
left: 40,
...options,
});
jest
.spyOn(object, 'getViewportTransform')
.mockReturnValue(viewportTransform);

const coords = object.getCoords();
expect(coords).toEqual(expected);

object.left += 5;
expect(object.getCoords()).toEqual(coords);

object.setCoords();
expect(object.getCoords()).toEqual(
expected.map((point) => point.add(new Point(5, 0)))
);
}
);
});
});

0 comments on commit 4293b84

Please sign in to comment.