mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-10 15:40:24 +00:00
Remove magic 10% scale on numeric widget step (#643)
There are external code still dependent on the fact that Widget.options.step is scaled 10x, so the 10x-ed value is still kept there, while we use the new unscaled step2 within our code now. Ref: https://cs.comfy.org/search?q=context:global+%22step+/+10%22&patternType=keyword&sm=0
This commit is contained in:
45
test/utils/widget.test.ts
Normal file
45
test/utils/widget.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { IWidgetOptions } from "@/types/widgets"
|
||||
|
||||
import { describe, expect, test } from "vitest"
|
||||
|
||||
import { getWidgetStep } from "@/utils/widget"
|
||||
|
||||
describe("getWidgetStep", () => {
|
||||
test("should return step2 when available", () => {
|
||||
const options: IWidgetOptions<unknown> = {
|
||||
step2: 0.5,
|
||||
step: 20,
|
||||
}
|
||||
|
||||
expect(getWidgetStep(options)).toBe(0.5)
|
||||
})
|
||||
|
||||
test("should calculate from step when step2 is not available", () => {
|
||||
const options: IWidgetOptions<unknown> = {
|
||||
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", () => {
|
||||
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", () => {
|
||||
const optionsWithZeroStep2: IWidgetOptions<unknown> = {
|
||||
step2: 0,
|
||||
step: 20,
|
||||
}
|
||||
|
||||
expect(getWidgetStep(optionsWithZeroStep2)).toBe(2)
|
||||
|
||||
const optionsWithZeroStep: IWidgetOptions<unknown> = {
|
||||
step: 0,
|
||||
}
|
||||
|
||||
expect(getWidgetStep(optionsWithZeroStep)).toBe(1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user