mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-05 13:41:59 +00:00
## Summary Migrates all unit tests from `tests-ui/` to colocate with their source files in `src/`, improving discoverability and maintainability. ## Changes - **What**: Relocated all unit tests to be adjacent to the code they test, following the `<source>.test.ts` naming convention - **Config**: Updated `vitest.config.ts` to remove `tests-ui` include pattern and `@tests-ui` alias - **Docs**: Moved testing documentation to `docs/testing/` with updated paths and patterns ## Review Focus - Migration patterns documented in `temp/plans/migrate-tests-ui-to-src.md` - Tests use `@/` path aliases instead of relative imports - Shared fixtures placed in `__fixtures__/` directories ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7811-chore-migrate-tests-from-tests-ui-to-colocate-with-source-files-2da6d73d36508147a4cce85365dee614) by [Unito](https://www.unito.io) --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: GitHub Action <action@github.com>
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { _for_testing } from '@/renderer/extensions/vueNodes/widgets/composables/useFloatWidget'
|
|
|
|
vi.mock('@/scripts/widgets', () => ({
|
|
addValueControlWidgets: vi.fn()
|
|
}))
|
|
|
|
vi.mock('@/platform/settings/settingStore', () => ({
|
|
useSettingStore: () => ({
|
|
settings: {}
|
|
})
|
|
}))
|
|
|
|
const { onFloatValueChange } = _for_testing
|
|
|
|
describe('useFloatWidget', () => {
|
|
describe('onFloatValueChange', () => {
|
|
let widget: any
|
|
|
|
beforeEach(() => {
|
|
// Reset the widget before each test
|
|
widget = {
|
|
options: {},
|
|
value: 0
|
|
}
|
|
})
|
|
|
|
it('should not round values when round option is not set', () => {
|
|
widget.options.round = undefined
|
|
onFloatValueChange.call(widget, 5.7)
|
|
expect(widget.value).toBe(5.7)
|
|
})
|
|
|
|
it('should round values based on round option', () => {
|
|
widget.options.round = 0.5
|
|
onFloatValueChange.call(widget, 5.7)
|
|
expect(widget.value).toBe(5.5)
|
|
|
|
widget.options.round = 0.1
|
|
onFloatValueChange.call(widget, 5.74)
|
|
expect(widget.value).toBe(5.7)
|
|
|
|
widget.options.round = 1
|
|
onFloatValueChange.call(widget, 5.7)
|
|
expect(widget.value).toBe(6)
|
|
})
|
|
|
|
it('should respect min and max constraints after rounding', () => {
|
|
widget.options.round = 0.5
|
|
widget.options.min = 1
|
|
widget.options.max = 5
|
|
|
|
// Should round to 1 and respect min
|
|
onFloatValueChange.call(widget, 0.7)
|
|
expect(widget.value).toBe(1)
|
|
|
|
// Should round to 5.5 but be clamped to max of 5
|
|
onFloatValueChange.call(widget, 5.3)
|
|
expect(widget.value).toBe(5)
|
|
|
|
// Should round to 3.5 and be within bounds
|
|
onFloatValueChange.call(widget, 3.6)
|
|
expect(widget.value).toBe(3.5)
|
|
})
|
|
|
|
it('should handle Number.EPSILON for precision issues', () => {
|
|
widget.options.round = 0.1
|
|
|
|
// Without Number.EPSILON, 1.35 / 0.1 = 13.499999999999998
|
|
// which would round to 13 * 0.1 = 1.3 instead of 1.4
|
|
onFloatValueChange.call(widget, 1.35)
|
|
expect(widget.value).toBeCloseTo(1.4, 10)
|
|
|
|
// Test another edge case
|
|
onFloatValueChange.call(widget, 2.95)
|
|
expect(widget.value).toBeCloseTo(3, 10)
|
|
})
|
|
})
|
|
})
|