mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 17:52:16 +00:00
npm run format
This commit is contained in:
@@ -1,40 +1,43 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { distributeSpace, type SpaceRequest } from "@/lib/litegraph/src/utils/spaceDistribution"
|
||||
import {
|
||||
type SpaceRequest,
|
||||
distributeSpace
|
||||
} from '@/lib/litegraph/src/utils/spaceDistribution'
|
||||
|
||||
describe("distributeSpace", () => {
|
||||
it("should distribute space according to minimum sizes when space is limited", () => {
|
||||
describe('distributeSpace', () => {
|
||||
it('should distribute space according to minimum sizes when space is limited', () => {
|
||||
const requests: SpaceRequest[] = [
|
||||
{ minSize: 100 },
|
||||
{ minSize: 100 },
|
||||
{ minSize: 100 },
|
||||
{ minSize: 100 }
|
||||
]
|
||||
expect(distributeSpace(300, requests)).toEqual([100, 100, 100])
|
||||
})
|
||||
|
||||
it("should distribute extra space equally when no maxSize", () => {
|
||||
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", () => {
|
||||
it('should respect maximum sizes', () => {
|
||||
const requests: SpaceRequest[] = [
|
||||
{ minSize: 100, maxSize: 150 },
|
||||
{ minSize: 100 },
|
||||
{ minSize: 100 }
|
||||
]
|
||||
expect(distributeSpace(400, requests)).toEqual([150, 250])
|
||||
})
|
||||
|
||||
it("should handle empty requests array", () => {
|
||||
it('should handle empty requests array', () => {
|
||||
expect(distributeSpace(1000, [])).toEqual([])
|
||||
})
|
||||
|
||||
it("should handle negative total space", () => {
|
||||
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", () => {
|
||||
it('should handle total space smaller than minimum sizes', () => {
|
||||
const requests: SpaceRequest[] = [{ minSize: 100 }, { minSize: 100 }]
|
||||
expect(distributeSpace(100, requests)).toEqual([100, 100])
|
||||
})
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { truncateText } from "@/lib/litegraph/src/utils/textUtils"
|
||||
import { truncateText } from '@/lib/litegraph/src/utils/textUtils'
|
||||
|
||||
describe("truncateText", () => {
|
||||
describe('truncateText', () => {
|
||||
const createMockContext = (charWidth: number = 10) => {
|
||||
return {
|
||||
measureText: vi.fn((text: string) => ({ width: text.length * charWidth })),
|
||||
measureText: vi.fn((text: string) => ({ width: text.length * charWidth }))
|
||||
} as unknown as CanvasRenderingContext2D
|
||||
}
|
||||
|
||||
it("should return original text if it fits within maxWidth", () => {
|
||||
it('should return original text if it fits within maxWidth', () => {
|
||||
const ctx = createMockContext()
|
||||
const result = truncateText(ctx, "Short", 100)
|
||||
expect(result).toBe("Short")
|
||||
const result = truncateText(ctx, 'Short', 100)
|
||||
expect(result).toBe('Short')
|
||||
})
|
||||
|
||||
it("should return original text if maxWidth is 0 or negative", () => {
|
||||
it('should return original text if maxWidth is 0 or negative', () => {
|
||||
const ctx = createMockContext()
|
||||
expect(truncateText(ctx, "Text", 0)).toBe("Text")
|
||||
expect(truncateText(ctx, "Text", -10)).toBe("Text")
|
||||
expect(truncateText(ctx, 'Text', 0)).toBe('Text')
|
||||
expect(truncateText(ctx, 'Text', -10)).toBe('Text')
|
||||
})
|
||||
|
||||
it("should truncate text and add ellipsis when text is too long", () => {
|
||||
it('should truncate text and add ellipsis when text is too long', () => {
|
||||
const ctx = createMockContext(10) // 10 pixels per character
|
||||
const result = truncateText(ctx, "This is a very long text", 100)
|
||||
const result = truncateText(ctx, 'This is a very long text', 100)
|
||||
// 100px total, "..." takes 30px, leaving 70px for text (7 chars)
|
||||
expect(result).toBe("This is...")
|
||||
expect(result).toBe('This is...')
|
||||
})
|
||||
|
||||
it("should use custom ellipsis when provided", () => {
|
||||
it('should use custom ellipsis when provided', () => {
|
||||
const ctx = createMockContext(10)
|
||||
const result = truncateText(ctx, "This is a very long text", 100, "…")
|
||||
const result = truncateText(ctx, 'This is a very long text', 100, '…')
|
||||
// 100px total, "…" takes 10px, leaving 90px for text (9 chars)
|
||||
expect(result).toBe("This is a…")
|
||||
expect(result).toBe('This is a…')
|
||||
})
|
||||
|
||||
it("should return only ellipsis if available width is too small", () => {
|
||||
it('should return only ellipsis if available width is too small', () => {
|
||||
const ctx = createMockContext(10)
|
||||
const result = truncateText(ctx, "Text", 20) // Only room for 2 chars, but "..." needs 3
|
||||
expect(result).toBe("...")
|
||||
const result = truncateText(ctx, 'Text', 20) // Only room for 2 chars, but "..." needs 3
|
||||
expect(result).toBe('...')
|
||||
})
|
||||
|
||||
it("should handle empty text", () => {
|
||||
it('should handle empty text', () => {
|
||||
const ctx = createMockContext()
|
||||
const result = truncateText(ctx, "", 100)
|
||||
expect(result).toBe("")
|
||||
const result = truncateText(ctx, '', 100)
|
||||
expect(result).toBe('')
|
||||
})
|
||||
|
||||
it("should use binary search efficiently", () => {
|
||||
it('should use binary search efficiently', () => {
|
||||
const ctx = createMockContext(10)
|
||||
const longText = "A".repeat(100) // 100 characters
|
||||
const longText = 'A'.repeat(100) // 100 characters
|
||||
|
||||
const result = truncateText(ctx, longText, 200) // Room for 20 chars total
|
||||
expect(result).toBe(`${"A".repeat(17)}...`) // 17 chars + "..." = 20 chars = 200px
|
||||
expect(result).toBe(`${'A'.repeat(17)}...`) // 17 chars + "..." = 20 chars = 200px
|
||||
|
||||
// Verify binary search efficiency - should not measure every possible substring
|
||||
// Binary search for 100 chars should take around log2(100) ≈ 7 iterations
|
||||
@@ -62,21 +62,21 @@ describe("truncateText", () => {
|
||||
expect(callCount).toBeGreaterThan(5)
|
||||
})
|
||||
|
||||
it("should handle unicode characters correctly", () => {
|
||||
it('should handle unicode characters correctly', () => {
|
||||
const ctx = createMockContext(10)
|
||||
const result = truncateText(ctx, "Hello 👋 World", 80)
|
||||
const result = truncateText(ctx, 'Hello 👋 World', 80)
|
||||
// Assuming each char (including emoji) is 10px, total is 130px
|
||||
// 80px total, "..." takes 30px, leaving 50px for text (5 chars)
|
||||
expect(result).toBe("Hello...")
|
||||
expect(result).toBe('Hello...')
|
||||
})
|
||||
|
||||
it("should handle exact boundary cases", () => {
|
||||
it('should handle exact boundary cases', () => {
|
||||
const ctx = createMockContext(10)
|
||||
|
||||
// Text exactly fits
|
||||
expect(truncateText(ctx, "Exact", 50)).toBe("Exact") // 5 chars = 50px
|
||||
expect(truncateText(ctx, 'Exact', 50)).toBe('Exact') // 5 chars = 50px
|
||||
|
||||
// Text is exactly 1 pixel too long
|
||||
expect(truncateText(ctx, "Exact!", 50)).toBe("Ex...") // 6 chars = 60px, truncated
|
||||
expect(truncateText(ctx, 'Exact!', 50)).toBe('Ex...') // 6 chars = 60px, truncated
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
import type { IWidgetOptions } from "@/lib/litegraph/src/types/widgets"
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import { describe, expect, test } from "vitest"
|
||||
import type { IWidgetOptions } from '@/lib/litegraph/src/types/widgets'
|
||||
import { getWidgetStep } from '@/lib/litegraph/src/utils/widget'
|
||||
|
||||
import { getWidgetStep } from "@/lib/litegraph/src/utils/widget"
|
||||
|
||||
describe("getWidgetStep", () => {
|
||||
test("should return step2 when available", () => {
|
||||
describe('getWidgetStep', () => {
|
||||
test('should return step2 when available', () => {
|
||||
const options: IWidgetOptions<unknown> = {
|
||||
step2: 0.5,
|
||||
step: 20,
|
||||
step: 20
|
||||
}
|
||||
|
||||
expect(getWidgetStep(options)).toBe(0.5)
|
||||
})
|
||||
|
||||
test("should calculate from step when step2 is not available", () => {
|
||||
test('should calculate from step when step2 is not available', () => {
|
||||
const options: IWidgetOptions<unknown> = {
|
||||
step: 20,
|
||||
step: 20
|
||||
}
|
||||
|
||||
expect(getWidgetStep(options)).toBe(2) // 20 * 0.1 = 2
|
||||
})
|
||||
|
||||
test("should use default step value of 10 when neither step2 nor step is provided", () => {
|
||||
test('should use default step value of 10 when neither step2 nor step is provided', () => {
|
||||
const options: IWidgetOptions<unknown> = {}
|
||||
|
||||
expect(getWidgetStep(options)).toBe(1) // 10 * 0.1 = 1
|
||||
})
|
||||
// Zero value is not allowed for step, fallback to 1.
|
||||
test("should handle zero values correctly", () => {
|
||||
test('should handle zero values correctly', () => {
|
||||
const optionsWithZeroStep2: IWidgetOptions<unknown> = {
|
||||
step2: 0,
|
||||
step: 20,
|
||||
step: 20
|
||||
}
|
||||
|
||||
expect(getWidgetStep(optionsWithZeroStep2)).toBe(2)
|
||||
|
||||
const optionsWithZeroStep: IWidgetOptions<unknown> = {
|
||||
step: 0,
|
||||
step: 0
|
||||
}
|
||||
|
||||
expect(getWidgetStep(optionsWithZeroStep)).toBe(1)
|
||||
|
||||
Reference in New Issue
Block a user