From 11dc6d2cf284c0b24e20e1e65ca54f0b03c67489 Mon Sep 17 00:00:00 2001 From: Guti Date: Sun, 11 Aug 2024 14:11:39 +0200 Subject: [PATCH] added calculateShapeOffsetToXDropCoordinate unit test --- src/pods/canvas/use.monitor.business.spec.ts | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/pods/canvas/use.monitor.business.spec.ts diff --git a/src/pods/canvas/use.monitor.business.spec.ts b/src/pods/canvas/use.monitor.business.spec.ts new file mode 100644 index 00000000..a486dfc3 --- /dev/null +++ b/src/pods/canvas/use.monitor.business.spec.ts @@ -0,0 +1,36 @@ +import { calculateShapeOffsetToXDropCoordinate } from './use-monitor.business'; +import { ShapeType } from '@/core/model'; +import { getDefaultSizeFromShape } from './canvas.model'; + +describe('calculateShapeOffsetToXDropCoordinate', () => { + it('should return coordinateX - offset when coordinateX - offset is greater than 0', () => { + // Arrange + const coordinateX = 100; + const shapeType: ShapeType = 'input'; + const defaultShapeSize = getDefaultSizeFromShape(shapeType); + + // Act + const result = calculateShapeOffsetToXDropCoordinate( + coordinateX, + shapeType + ); + + // Assert + expect(result).toBe(coordinateX - defaultShapeSize.width / 2); + }); + + it('should return 0 when coordinateX - offset is less than or equal to 0', () => { + // Arrange + const coordinateX = 20; + const shapeType: ShapeType = 'input'; + + // Act + const result = calculateShapeOffsetToXDropCoordinate( + coordinateX, + shapeType + ); + + // Assert + expect(result).toBe(0); + }); +});