npm run format

This commit is contained in:
Benjamin Lu
2025-08-05 09:57:28 -04:00
parent 50feb27339
commit c53f197de2
129 changed files with 10575 additions and 7230 deletions

View File

@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, test } from "vitest"
import { beforeEach, describe, expect, test } from 'vitest'
import { Rectangle } from "@/lib/litegraph/src/infrastructure/Rectangle"
import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle'
describe("Rectangle resize functionality", () => {
describe('Rectangle resize functionality', () => {
let rect: Rectangle
beforeEach(() => {
@@ -10,37 +10,37 @@ describe("Rectangle resize functionality", () => {
// So: left=100, top=200, right=400, bottom=600
})
describe("findContainingCorner", () => {
describe('findContainingCorner', () => {
const cornerSize = 15
test("should detect NW (top-left) corner", () => {
expect(rect.findContainingCorner(100, 200, cornerSize)).toBe("NW")
expect(rect.findContainingCorner(110, 210, cornerSize)).toBe("NW")
expect(rect.findContainingCorner(114, 214, cornerSize)).toBe("NW")
test('should detect NW (top-left) corner', () => {
expect(rect.findContainingCorner(100, 200, cornerSize)).toBe('NW')
expect(rect.findContainingCorner(110, 210, cornerSize)).toBe('NW')
expect(rect.findContainingCorner(114, 214, cornerSize)).toBe('NW')
})
test("should detect NE (top-right) corner", () => {
test('should detect NE (top-right) corner', () => {
// Top-right corner starts at (right - cornerSize, top) = (385, 200)
expect(rect.findContainingCorner(385, 200, cornerSize)).toBe("NE")
expect(rect.findContainingCorner(390, 210, cornerSize)).toBe("NE")
expect(rect.findContainingCorner(399, 214, cornerSize)).toBe("NE")
expect(rect.findContainingCorner(385, 200, cornerSize)).toBe('NE')
expect(rect.findContainingCorner(390, 210, cornerSize)).toBe('NE')
expect(rect.findContainingCorner(399, 214, cornerSize)).toBe('NE')
})
test("should detect SW (bottom-left) corner", () => {
test('should detect SW (bottom-left) corner', () => {
// Bottom-left corner starts at (left, bottom - cornerSize) = (100, 585)
expect(rect.findContainingCorner(100, 585, cornerSize)).toBe("SW")
expect(rect.findContainingCorner(110, 590, cornerSize)).toBe("SW")
expect(rect.findContainingCorner(114, 599, cornerSize)).toBe("SW")
expect(rect.findContainingCorner(100, 585, cornerSize)).toBe('SW')
expect(rect.findContainingCorner(110, 590, cornerSize)).toBe('SW')
expect(rect.findContainingCorner(114, 599, cornerSize)).toBe('SW')
})
test("should detect SE (bottom-right) corner", () => {
test('should detect SE (bottom-right) corner', () => {
// Bottom-right corner starts at (right - cornerSize, bottom - cornerSize) = (385, 585)
expect(rect.findContainingCorner(385, 585, cornerSize)).toBe("SE")
expect(rect.findContainingCorner(390, 590, cornerSize)).toBe("SE")
expect(rect.findContainingCorner(399, 599, cornerSize)).toBe("SE")
expect(rect.findContainingCorner(385, 585, cornerSize)).toBe('SE')
expect(rect.findContainingCorner(390, 590, cornerSize)).toBe('SE')
expect(rect.findContainingCorner(399, 599, cornerSize)).toBe('SE')
})
test("should return undefined when not in any corner", () => {
test('should return undefined when not in any corner', () => {
// Middle of rectangle
expect(rect.findContainingCorner(250, 400, cornerSize)).toBeUndefined()
// On edge but not in corner
@@ -51,17 +51,17 @@ describe("Rectangle resize functionality", () => {
})
})
describe("corner detection methods", () => {
describe('corner detection methods', () => {
const cornerSize = 20
describe("isInTopLeftCorner", () => {
test("should return true when point is in top-left corner", () => {
describe('isInTopLeftCorner', () => {
test('should return true when point is in top-left corner', () => {
expect(rect.isInTopLeftCorner(100, 200, cornerSize)).toBe(true)
expect(rect.isInTopLeftCorner(110, 210, cornerSize)).toBe(true)
expect(rect.isInTopLeftCorner(119, 219, cornerSize)).toBe(true)
})
test("should return false when point is outside top-left corner", () => {
test('should return false when point is outside top-left corner', () => {
expect(rect.isInTopLeftCorner(120, 200, cornerSize)).toBe(false)
expect(rect.isInTopLeftCorner(100, 220, cornerSize)).toBe(false)
expect(rect.isInTopLeftCorner(99, 200, cornerSize)).toBe(false)
@@ -69,8 +69,8 @@ describe("Rectangle resize functionality", () => {
})
})
describe("isInTopRightCorner", () => {
test("should return true when point is in top-right corner", () => {
describe('isInTopRightCorner', () => {
test('should return true when point is in top-right corner', () => {
// Top-right corner area is from (right - cornerSize, top) to (right, top + cornerSize)
// That's (380, 200) to (400, 220)
expect(rect.isInTopRightCorner(380, 200, cornerSize)).toBe(true)
@@ -78,7 +78,7 @@ describe("Rectangle resize functionality", () => {
expect(rect.isInTopRightCorner(399, 219, cornerSize)).toBe(true)
})
test("should return false when point is outside top-right corner", () => {
test('should return false when point is outside top-right corner', () => {
expect(rect.isInTopRightCorner(379, 200, cornerSize)).toBe(false)
expect(rect.isInTopRightCorner(400, 220, cornerSize)).toBe(false)
expect(rect.isInTopRightCorner(401, 200, cornerSize)).toBe(false)
@@ -86,8 +86,8 @@ describe("Rectangle resize functionality", () => {
})
})
describe("isInBottomLeftCorner", () => {
test("should return true when point is in bottom-left corner", () => {
describe('isInBottomLeftCorner', () => {
test('should return true when point is in bottom-left corner', () => {
// Bottom-left corner area is from (left, bottom - cornerSize) to (left + cornerSize, bottom)
// That's (100, 580) to (120, 600)
expect(rect.isInBottomLeftCorner(100, 580, cornerSize)).toBe(true)
@@ -95,7 +95,7 @@ describe("Rectangle resize functionality", () => {
expect(rect.isInBottomLeftCorner(119, 599, cornerSize)).toBe(true)
})
test("should return false when point is outside bottom-left corner", () => {
test('should return false when point is outside bottom-left corner', () => {
expect(rect.isInBottomLeftCorner(120, 600, cornerSize)).toBe(false)
expect(rect.isInBottomLeftCorner(100, 579, cornerSize)).toBe(false)
expect(rect.isInBottomLeftCorner(99, 600, cornerSize)).toBe(false)
@@ -103,8 +103,8 @@ describe("Rectangle resize functionality", () => {
})
})
describe("isInBottomRightCorner", () => {
test("should return true when point is in bottom-right corner", () => {
describe('isInBottomRightCorner', () => {
test('should return true when point is in bottom-right corner', () => {
// Bottom-right corner area is from (right - cornerSize, bottom - cornerSize) to (right, bottom)
// That's (380, 580) to (400, 600)
expect(rect.isInBottomRightCorner(380, 580, cornerSize)).toBe(true)
@@ -112,7 +112,7 @@ describe("Rectangle resize functionality", () => {
expect(rect.isInBottomRightCorner(399, 599, cornerSize)).toBe(true)
})
test("should return false when point is outside bottom-right corner", () => {
test('should return false when point is outside bottom-right corner', () => {
expect(rect.isInBottomRightCorner(379, 600, cornerSize)).toBe(false)
expect(rect.isInBottomRightCorner(400, 579, cornerSize)).toBe(false)
expect(rect.isInBottomRightCorner(401, 600, cornerSize)).toBe(false)
@@ -121,24 +121,24 @@ describe("Rectangle resize functionality", () => {
})
})
describe("edge cases", () => {
test("should handle zero-sized corner areas", () => {
describe('edge cases', () => {
test('should handle zero-sized corner areas', () => {
expect(rect.findContainingCorner(100, 200, 0)).toBeUndefined()
expect(rect.isInTopLeftCorner(100, 200, 0)).toBe(false)
})
test("should handle rectangles at origin", () => {
test('should handle rectangles at origin', () => {
const originRect = new Rectangle(0, 0, 100, 100)
expect(originRect.findContainingCorner(0, 0, 10)).toBe("NW")
expect(originRect.findContainingCorner(0, 0, 10)).toBe('NW')
// Bottom-right corner is at (90, 90) to (100, 100)
expect(originRect.findContainingCorner(90, 90, 10)).toBe("SE")
expect(originRect.findContainingCorner(90, 90, 10)).toBe('SE')
})
test("should handle negative coordinates", () => {
test('should handle negative coordinates', () => {
const negRect = new Rectangle(-50, -50, 100, 100)
expect(negRect.findContainingCorner(-50, -50, 10)).toBe("NW")
expect(negRect.findContainingCorner(-50, -50, 10)).toBe('NW')
// Bottom-right corner is at (40, 40) to (50, 50)
expect(negRect.findContainingCorner(40, 40, 10)).toBe("SE")
expect(negRect.findContainingCorner(40, 40, 10)).toBe('SE')
})
})
})

View File

@@ -1,20 +1,19 @@
import type { Point, Size } from "@/lib/litegraph/src/interfaces"
import { test as baseTest, describe, expect, vi } from 'vitest'
import { describe, expect, test as baseTest, vi } from "vitest"
import { Rectangle } from "@/lib/litegraph/src/infrastructure/Rectangle"
import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle'
import type { Point, Size } from '@/lib/litegraph/src/interfaces'
// TODO: If there's a common test context, use it here
// For now, we'll define a simple context for Rectangle tests
const test = baseTest.extend<{ rect: Rectangle }>({
rect: async ({}, use) => {
await use(new Rectangle())
},
}
})
describe("Rectangle", () => {
describe("constructor and basic properties", () => {
test("should create a default rectangle", ({ rect }) => {
describe('Rectangle', () => {
describe('constructor and basic properties', () => {
test('should create a default rectangle', ({ rect }) => {
expect(rect.x).toBe(0)
expect(rect.y).toBe(0)
expect(rect.width).toBe(0)
@@ -22,7 +21,7 @@ describe("Rectangle", () => {
expect(rect.length).toBe(4)
})
test("should create a rectangle with specified values", () => {
test('should create a rectangle with specified values', () => {
const rect = new Rectangle(1, 2, 3, 4)
expect(rect.x).toBe(1)
expect(rect.y).toBe(2)
@@ -30,7 +29,7 @@ describe("Rectangle", () => {
expect(rect.height).toBe(4)
})
test("should update the rectangle values", ({ rect }) => {
test('should update the rectangle values', ({ rect }) => {
const newValues: [number, number, number, number] = [1, 2, 3, 4]
rect.updateTo(newValues)
expect(rect.x).toBe(1)
@@ -40,8 +39,8 @@ describe("Rectangle", () => {
})
})
describe("array operations", () => {
test("should return a Float64Array representing the subarray", () => {
describe('array operations', () => {
test('should return a Float64Array representing the subarray', () => {
const rect = new Rectangle(10, 20, 30, 40)
const sub = rect.subarray(1, 3)
expect(sub).toBeInstanceOf(Float64Array)
@@ -50,7 +49,7 @@ describe("Rectangle", () => {
expect(sub[1]).toBe(30) // width
})
test("should return a Float64Array for the entire array if no args", () => {
test('should return a Float64Array for the entire array if no args', () => {
const rect = new Rectangle(10, 20, 30, 40)
const sub = rect.subarray()
expect(sub).toBeInstanceOf(Float64Array)
@@ -61,7 +60,7 @@ describe("Rectangle", () => {
expect(sub[3]).toBe(40)
})
test("should return an array with [x, y, width, height]", () => {
test('should return an array with [x, y, width, height]', () => {
const rect = new Rectangle(1, 2, 3, 4)
const arr = rect.toArray()
expect(arr).toEqual([1, 2, 3, 4])
@@ -75,8 +74,8 @@ describe("Rectangle", () => {
})
})
describe("position and size properties", () => {
test("should get the position", ({ rect }) => {
describe('position and size properties', () => {
test('should get the position', ({ rect }) => {
rect.x = 10
rect.y = 20
const pos = rect.pos
@@ -85,14 +84,16 @@ describe("Rectangle", () => {
expect(pos.length).toBe(2)
})
test("should set the position", ({ rect }) => {
test('should set the position', ({ rect }) => {
const newPos: Point = [5, 15]
rect.pos = newPos
expect(rect.x).toBe(5)
expect(rect.y).toBe(15)
})
test("should update the rectangle when the returned pos object is modified", ({ rect }) => {
test('should update the rectangle when the returned pos object is modified', ({
rect
}) => {
rect.x = 1
rect.y = 2
const pos = rect.pos
@@ -102,7 +103,7 @@ describe("Rectangle", () => {
expect(rect.y).toBe(200)
})
test("should get the size", ({ rect }) => {
test('should get the size', ({ rect }) => {
rect.width = 30
rect.height = 40
const size = rect.size
@@ -111,14 +112,16 @@ describe("Rectangle", () => {
expect(size.length).toBe(2)
})
test("should set the size", ({ rect }) => {
test('should set the size', ({ rect }) => {
const newSize: Size = [35, 45]
rect.size = newSize
expect(rect.width).toBe(35)
expect(rect.height).toBe(45)
})
test("should update the rectangle when the returned size object is modified", ({ rect }) => {
test('should update the rectangle when the returned size object is modified', ({
rect
}) => {
rect.width = 3
rect.height = 4
const size = rect.size
@@ -129,74 +132,74 @@ describe("Rectangle", () => {
})
})
describe("edge properties", () => {
test("should get x", ({ rect }) => {
describe('edge properties', () => {
test('should get x', ({ rect }) => {
rect[0] = 5
expect(rect.x).toBe(5)
})
test("should set x", ({ rect }) => {
test('should set x', ({ rect }) => {
rect.x = 10
expect(rect[0]).toBe(10)
})
test("should get y", ({ rect }) => {
test('should get y', ({ rect }) => {
rect[1] = 6
expect(rect.y).toBe(6)
})
test("should set y", ({ rect }) => {
test('should set y', ({ rect }) => {
rect.y = 11
expect(rect[1]).toBe(11)
})
test("should get width", ({ rect }) => {
test('should get width', ({ rect }) => {
rect[2] = 7
expect(rect.width).toBe(7)
})
test("should set width", ({ rect }) => {
test('should set width', ({ rect }) => {
rect.width = 12
expect(rect[2]).toBe(12)
})
test("should get height", ({ rect }) => {
test('should get height', ({ rect }) => {
rect[3] = 8
expect(rect.height).toBe(8)
})
test("should set height", ({ rect }) => {
test('should set height', ({ rect }) => {
rect.height = 13
expect(rect[3]).toBe(13)
})
test("should get left", ({ rect }) => {
test('should get left', ({ rect }) => {
rect[0] = 1
expect(rect.left).toBe(1)
})
test("should set left", ({ rect }) => {
test('should set left', ({ rect }) => {
rect.left = 2
expect(rect[0]).toBe(2)
})
test("should get top", ({ rect }) => {
test('should get top', ({ rect }) => {
rect[1] = 3
expect(rect.top).toBe(3)
})
test("should set top", ({ rect }) => {
test('should set top', ({ rect }) => {
rect.top = 4
expect(rect[1]).toBe(4)
})
test("should get right", ({ rect }) => {
test('should get right', ({ rect }) => {
rect[0] = 1
rect[2] = 10
expect(rect.right).toBe(11)
})
test("should set right", ({ rect }) => {
test('should set right', ({ rect }) => {
rect.x = 1
rect.width = 10 // right is 11
rect.right = 20 // new right
@@ -204,13 +207,13 @@ describe("Rectangle", () => {
expect(rect.width).toBe(10)
})
test("should get bottom", ({ rect }) => {
test('should get bottom', ({ rect }) => {
rect[1] = 2
rect[3] = 20
expect(rect.bottom).toBe(22)
})
test("should set bottom", ({ rect }) => {
test('should set bottom', ({ rect }) => {
rect.y = 2
rect.height = 20 // bottom is 22
rect.bottom = 30 // new bottom
@@ -218,7 +221,7 @@ describe("Rectangle", () => {
expect(rect.height).toBe(20)
})
test("should get centreX", () => {
test('should get centreX', () => {
const rect = new Rectangle(0, 0, 10, 0)
expect(rect.centreX).toBe(5)
rect.x = 5
@@ -227,7 +230,7 @@ describe("Rectangle", () => {
expect(rect.centreX).toBe(15) // 5 + (20 * 0.5)
})
test("should get centreY", () => {
test('should get centreY', () => {
const rect = new Rectangle(0, 0, 0, 10)
expect(rect.centreY).toBe(5)
rect.y = 5
@@ -237,8 +240,8 @@ describe("Rectangle", () => {
})
})
describe("geometric operations", () => {
test("should return the centre point", () => {
describe('geometric operations', () => {
test('should return the centre point', () => {
const rect = new Rectangle(10, 20, 30, 40) // centreX = 10 + 15 = 25, centreY = 20 + 20 = 40
const centre = rect.getCentre()
expect(centre[0]).toBe(25)
@@ -246,17 +249,17 @@ describe("Rectangle", () => {
expect(centre).not.toBe(rect.pos) // Should be a new Point
})
test("should return the area", () => {
test('should return the area', () => {
expect(new Rectangle(0, 0, 5, 10).getArea()).toBe(50)
expect(new Rectangle(1, 1, 0, 10).getArea()).toBe(0)
})
test("should return the perimeter", () => {
test('should return the perimeter', () => {
expect(new Rectangle(0, 0, 5, 10).getPerimeter()).toBe(30) // 2 * (5+10)
expect(new Rectangle(0, 0, 0, 0).getPerimeter()).toBe(0)
})
test("should return the top-left point", () => {
test('should return the top-left point', () => {
const rect = new Rectangle(1, 2, 3, 4)
const tl = rect.getTopLeft()
expect(tl[0]).toBe(1)
@@ -264,14 +267,14 @@ describe("Rectangle", () => {
expect(tl).not.toBe(rect.pos)
})
test("should return the bottom-right point", () => {
test('should return the bottom-right point', () => {
const rect = new Rectangle(1, 2, 10, 20) // right=11, bottom=22
const br = rect.getBottomRight()
expect(br[0]).toBe(11)
expect(br[1]).toBe(22)
})
test("should return the size", () => {
test('should return the size', () => {
const rect = new Rectangle(1, 2, 30, 40)
const s = rect.getSize()
expect(s[0]).toBe(30)
@@ -279,14 +282,14 @@ describe("Rectangle", () => {
expect(s).not.toBe(rect.size)
})
test("should return the offset from top-left to the point", () => {
test('should return the offset from top-left to the point', () => {
const rect = new Rectangle(10, 20, 5, 5)
const offset = rect.getOffsetTo([12, 23])
expect(offset[0]).toBe(2) // 12 - 10
expect(offset[1]).toBe(3) // 23 - 20
})
test("should return the offset from the point to the top-left", () => {
test('should return the offset from the point to the top-left', () => {
const rect = new Rectangle(10, 20, 5, 5)
const offset = rect.getOffsetFrom([12, 23])
expect(offset[0]).toBe(-2) // 10 - 12
@@ -294,7 +297,7 @@ describe("Rectangle", () => {
})
})
describe("containment and overlap", () => {
describe('containment and overlap', () => {
const rect = new Rectangle(10, 10, 20, 20) // x: 10, y: 10, right: 30, bottom: 30
test.each([
@@ -306,10 +309,13 @@ describe("Rectangle", () => {
[15, 5, false], // outside top
[15, 30, false], // outside bottom
[10, 29, true], // on bottom edge
[29, 10, true], // on right edge
])("when checking if (%s, %s) is inside, should return %s", (x, y, expected) => {
expect(rect.containsXy(x, y)).toBe(expected)
})
[29, 10, true] // on right edge
])(
'when checking if (%s, %s) is inside, should return %s',
(x, y, expected) => {
expect(rect.containsXy(x, y)).toBe(expected)
}
)
test.each([
[[0, 0] as Point, true],
@@ -318,8 +324,8 @@ describe("Rectangle", () => {
[[-1, 5] as Point, false],
[[11, 5] as Point, false],
[[5, -1] as Point, false],
[[5, 11] as Point, false],
])("should return %s for point %j", (point: Point, expected: boolean) => {
[[5, 11] as Point, false]
])('should return %s for point %j', (point: Point, expected: boolean) => {
rect.updateTo([0, 0, 10, 10])
expect(rect.containsPoint(point)).toBe(expected)
})
@@ -340,18 +346,25 @@ describe("Rectangle", () => {
// Outer rectangle is smaller
[new Rectangle(0, 0, 5, 5), new Rectangle(0, 0, 10, 10), true],
// Same size
[new Rectangle(0, 0, 99, 99), true],
])("should return %s when checking if %s is inside outer rect", (inner: Rectangle, expectedOrOuter: boolean | Rectangle, expectedIfThreeArgs?: boolean) => {
let testOuter = rect
rect.updateTo([0, 0, 100, 100])
[new Rectangle(0, 0, 99, 99), true]
])(
'should return %s when checking if %s is inside outer rect',
(
inner: Rectangle,
expectedOrOuter: boolean | Rectangle,
expectedIfThreeArgs?: boolean
) => {
let testOuter = rect
rect.updateTo([0, 0, 100, 100])
let testExpected = expectedOrOuter as boolean
if (typeof expectedOrOuter !== "boolean") {
testOuter = expectedOrOuter as Rectangle
testExpected = expectedIfThreeArgs as boolean
let testExpected = expectedOrOuter as boolean
if (typeof expectedOrOuter !== 'boolean') {
testOuter = expectedOrOuter as Rectangle
testExpected = expectedIfThreeArgs as boolean
}
expect(testOuter.containsRect(inner)).toBe(testExpected)
}
expect(testOuter.containsRect(inner)).toBe(testExpected)
})
)
test.each([
// Completely overlapping
@@ -372,8 +385,8 @@ describe("Rectangle", () => {
[new Rectangle(100, 100, 5, 5), false], // r2 far away
[new Rectangle(0, 0, 5, 5), false], // r2 outside top-left
// rect1 inside rect2
[new Rectangle(0, 0, 100, 100), true],
])("should return %s for overlap with %s", (rect2, expected) => {
[new Rectangle(0, 0, 100, 100), true]
])('should return %s for overlap with %s', (rect2, expected) => {
const rect = new Rectangle(10, 10, 20, 20) // 10,10 to 30,30
expect(rect.overlaps(rect2)).toBe(expected)
@@ -382,8 +395,10 @@ describe("Rectangle", () => {
})
})
describe("resize operations", () => {
test("should resize from top-left corner while maintaining bottom-right", ({ rect }) => {
describe('resize operations', () => {
test('should resize from top-left corner while maintaining bottom-right', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20]) // x: 10, y: 10, width: 20, height: 20
rect.resizeTopLeft(5, 5)
expect(rect.x).toBe(5)
@@ -392,7 +407,9 @@ describe("Rectangle", () => {
expect(rect.height).toBe(25) // 20 + (10 - 5)
})
test("should handle negative coordinates for top-left resize", ({ rect }) => {
test('should handle negative coordinates for top-left resize', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20])
rect.resizeTopLeft(-5, -5)
expect(rect.x).toBe(-5)
@@ -401,7 +418,9 @@ describe("Rectangle", () => {
expect(rect.height).toBe(35) // 20 + (10 - (-5))
})
test("should resize from bottom-left corner while maintaining top-right", ({ rect }) => {
test('should resize from bottom-left corner while maintaining top-right', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20])
rect.resizeBottomLeft(5, 35)
expect(rect.x).toBe(5)
@@ -410,7 +429,9 @@ describe("Rectangle", () => {
expect(rect.height).toBe(25) // 35 - 10
})
test("should handle negative coordinates for bottom-left resize", ({ rect }) => {
test('should handle negative coordinates for bottom-left resize', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20])
rect.resizeBottomLeft(-5, 35)
expect(rect.x).toBe(-5)
@@ -419,7 +440,9 @@ describe("Rectangle", () => {
expect(rect.height).toBe(25) // 35 - 10
})
test("should resize from top-right corner while maintaining bottom-left", ({ rect }) => {
test('should resize from top-right corner while maintaining bottom-left', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20])
rect.resizeTopRight(35, 5)
expect(rect.x).toBe(10)
@@ -428,7 +451,9 @@ describe("Rectangle", () => {
expect(rect.height).toBe(25) // 20 + (10 - 5)
})
test("should handle negative coordinates for top-right resize", ({ rect }) => {
test('should handle negative coordinates for top-right resize', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20])
rect.resizeTopRight(35, -5)
expect(rect.x).toBe(10)
@@ -437,7 +462,9 @@ describe("Rectangle", () => {
expect(rect.height).toBe(35) // 20 + (10 - (-5))
})
test("should resize from bottom-right corner while maintaining top-left", ({ rect }) => {
test('should resize from bottom-right corner while maintaining top-left', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20])
rect.resizeBottomRight(35, 35)
expect(rect.x).toBe(10)
@@ -446,7 +473,9 @@ describe("Rectangle", () => {
expect(rect.height).toBe(25) // 35 - 10
})
test("should handle negative coordinates for bottom-right resize", ({ rect }) => {
test('should handle negative coordinates for bottom-right resize', ({
rect
}) => {
rect.updateTo([10, 10, 20, 20])
rect.resizeBottomRight(35, -5)
expect(rect.x).toBe(10)
@@ -455,7 +484,7 @@ describe("Rectangle", () => {
expect(rect.height).toBe(-15) // -5 - 10
})
test("should set width, anchoring the right edge", () => {
test('should set width, anchoring the right edge', () => {
const rect = new Rectangle(10, 0, 20, 0) // x:10, width:20 -> right:30
rect.setWidthRightAnchored(15) // new width 15
expect(rect.width).toBe(15)
@@ -463,7 +492,7 @@ describe("Rectangle", () => {
expect(rect.right).toBe(30) // right should remain 30 (15+15)
})
test("should set height, anchoring the bottom edge", () => {
test('should set height, anchoring the bottom edge', () => {
const rect = new Rectangle(0, 10, 0, 20) // y:10, height:20 -> bottom:30
rect.setHeightBottomAnchored(15) // new height 15
expect(rect.height).toBe(15)
@@ -472,21 +501,21 @@ describe("Rectangle", () => {
})
})
describe("debug drawing", () => {
test("should call canvas context methods", () => {
describe('debug drawing', () => {
test('should call canvas context methods', () => {
const rect = new Rectangle(10, 20, 30, 40)
const mockCtx = {
strokeStyle: "black",
strokeStyle: 'black',
lineWidth: 1,
beginPath: vi.fn(),
strokeRect: vi.fn(),
strokeRect: vi.fn()
} as unknown as CanvasRenderingContext2D
rect._drawDebug(mockCtx, "blue")
rect._drawDebug(mockCtx, 'blue')
expect(mockCtx.beginPath).toHaveBeenCalledOnce()
expect(mockCtx.strokeRect).toHaveBeenCalledWith(10, 20, 30, 40)
expect(mockCtx.strokeStyle).toBe("black") // Restored
expect(mockCtx.strokeStyle).toBe('black') // Restored
expect(mockCtx.lineWidth).toBe(1) // Restored
// Check if it was set during the call
@@ -496,20 +525,20 @@ describe("Rectangle", () => {
// A more robust test could involve spying on property assignments if vitest supports it easily.
})
test("should use default color if not provided", () => {
test('should use default color if not provided', () => {
const rect = new Rectangle(1, 2, 3, 4)
const mockCtx = {
strokeStyle: "black",
strokeStyle: 'black',
lineWidth: 1,
beginPath: vi.fn(),
strokeRect: vi.fn(),
strokeRect: vi.fn()
} as unknown as CanvasRenderingContext2D
rect._drawDebug(mockCtx)
// Check if strokeStyle was "red" at the time of strokeRect
// This requires a more complex mock or observing calls.
// A simple check is that it ran without error and values were restored.
expect(mockCtx.strokeRect).toHaveBeenCalledWith(1, 2, 3, 4)
expect(mockCtx.strokeStyle).toBe("black")
expect(mockCtx.strokeStyle).toBe('black')
})
})
})