mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-24 00:09:32 +00:00
Upstream frontend widgets layout logic (#531)
* Upstream frontend widgets layout logic * Add back LGraphNode.freeWidgetSpace * nit * update expectations
This commit is contained in:
40
test/utils/spaceDistribution.test.ts
Normal file
40
test/utils/spaceDistribution.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
import { type SpaceRequest, distributeSpace } from "@/utils/spaceDistribution"
|
||||
|
||||
describe("distributeSpace", () => {
|
||||
it("should distribute space according to minimum sizes when space is limited", () => {
|
||||
const requests: SpaceRequest[] = [
|
||||
{ minSize: 100 },
|
||||
{ minSize: 100 },
|
||||
{ minSize: 100 },
|
||||
]
|
||||
expect(distributeSpace(300, requests)).toEqual([100, 100, 100])
|
||||
})
|
||||
|
||||
it("should distribute extra space equally when no maxSize", () => {
|
||||
const requests: SpaceRequest[] = [{ minSize: 100 }, { minSize: 100 }]
|
||||
expect(distributeSpace(400, requests)).toEqual([200, 200])
|
||||
})
|
||||
|
||||
it("should respect maximum sizes", () => {
|
||||
const requests: SpaceRequest[] = [
|
||||
{ minSize: 100, maxSize: 150 },
|
||||
{ minSize: 100 },
|
||||
]
|
||||
expect(distributeSpace(400, requests)).toEqual([150, 250])
|
||||
})
|
||||
|
||||
it("should handle empty requests array", () => {
|
||||
expect(distributeSpace(1000, [])).toEqual([])
|
||||
})
|
||||
|
||||
it("should handle negative total space", () => {
|
||||
const requests: SpaceRequest[] = [{ minSize: 100 }, { minSize: 100 }]
|
||||
expect(distributeSpace(-100, requests)).toEqual([100, 100])
|
||||
})
|
||||
|
||||
it("should handle total space smaller than minimum sizes", () => {
|
||||
const requests: SpaceRequest[] = [{ minSize: 100 }, { minSize: 100 }]
|
||||
expect(distributeSpace(100, requests)).toEqual([100, 100])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user