mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-23 06:10:32 +00:00
## Summary Migrate 132 test files from `@vue/test-utils` (VTU) to `@testing-library/vue` (VTL) with `@testing-library/user-event`, adopting user-centric behavioral testing patterns across the codebase. ## Changes - **What**: Systematic migration of component/unit tests from VTU's `mount`/`wrapper` API to VTL's `render`/`screen`/`userEvent` API across 132 files in `src/` - **Breaking**: None — test-only changes, no production code affected ### Migration breakdown | Batch | Files | Description | |-------|-------|-------------| | 1 | 19 | Simple render/assert tests | | 2A | 16 | Interactive tests with user events | | 2B-1 | 14 | Interactive tests (continued) | | 2B-2 | 32 | Interactive tests (continued) | | 3A–3E | 51 | Complex tests (stores, composables, heavy mocking) | | Lint fix | 7 | `await` on `fireEvent` calls for `no-floating-promises` | | Review fixes | 15 | Address CodeRabbit feedback (3 rounds) | ### Review feedback addressed - Removed class-based assertions (`text-ellipsis`, `pr-3`, `.pi-save`, `.skeleton`, `.bg-black\/15`, Tailwind utilities) in favor of behavioral/accessible queries - Added null guards before `querySelector` casts - Added `expect(roots).toHaveLength(N)` guards before indexed NodeList access - Wrapped fake timer tests in `try/finally` for guaranteed cleanup - Split double-render tests into focused single-render tests - Replaced CSS class selectors with `screen.getByText`/`screen.getByRole` queries - Updated stubs to use semantic `role`/`aria-label` instead of CSS classes - Consolidated redundant edge-case tests - Removed manual `document.body.appendChild` in favor of VTL container management - Used distinct mock return values to verify command wiring ### VTU holdouts (2 files) These files intentionally retain `@vue/test-utils` because their components use `<script setup>` without `defineExpose`, making internal computed properties and methods inaccessible via VTL: 1. **`NodeWidgets.test.ts`** — partial VTU for `vm.processedWidgets` 2. **`WidgetSelectDropdown.test.ts`** — full VTU for heavy `wrapper.vm.*` access ## Follow-up Deferred items (`ComponentProps` typing, camelCase listener props) tracked in #10966. ## Review Focus - Test correctness: all migrated tests preserve original behavioral coverage - VTL idioms: proper use of `screen` queries, `userEvent`, and accessibility-based selectors - The 2 VTU holdout files are intentional, not oversights ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10965-test-migrate-132-test-files-from-vue-test-utils-to-testing-library-vue-33c6d73d36508199a6a7e513cf5d8296) by [Unito](https://www.unito.io) --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Christian Byrne <cbyrne@comfy.org>
153 lines
4.2 KiB
TypeScript
153 lines
4.2 KiB
TypeScript
import { render } from '@testing-library/vue'
|
|
import { nextTick, ref } from 'vue'
|
|
import type { Ref } from 'vue'
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
|
|
import { useQueueProgress } from '@/composables/queue/useQueueProgress'
|
|
import { formatPercent0 } from '@/utils/numberUtil'
|
|
|
|
type ProgressValue = number | null
|
|
|
|
const localeRef: Ref<string> = ref('en-US') as Ref<string>
|
|
const executionProgressRef: Ref<ProgressValue> = ref(null)
|
|
const executingNodeProgressRef: Ref<ProgressValue> = ref(null)
|
|
|
|
const createExecutionStoreMock = () => ({
|
|
get executionProgress() {
|
|
return executionProgressRef.value ?? undefined
|
|
},
|
|
get executingNodeProgress() {
|
|
return executingNodeProgressRef.value ?? undefined
|
|
}
|
|
})
|
|
|
|
vi.mock('vue-i18n', () => ({
|
|
useI18n: () => ({
|
|
locale: localeRef
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/stores/executionStore', () => ({
|
|
useExecutionStore: () => createExecutionStoreMock()
|
|
}))
|
|
|
|
const mountUseQueueProgress = () => {
|
|
let composable: ReturnType<typeof useQueueProgress>
|
|
render({
|
|
template: '<div />',
|
|
setup() {
|
|
composable = useQueueProgress()
|
|
return {}
|
|
}
|
|
})
|
|
return { composable: composable! }
|
|
}
|
|
|
|
const setExecutionProgress = (value?: number | null) => {
|
|
executionProgressRef.value = value ?? null
|
|
}
|
|
|
|
const setExecutingNodeProgress = (value?: number | null) => {
|
|
executingNodeProgressRef.value = value ?? null
|
|
}
|
|
|
|
describe('useQueueProgress', () => {
|
|
beforeEach(() => {
|
|
localeRef.value = 'en-US'
|
|
setExecutionProgress(null)
|
|
setExecutingNodeProgress(null)
|
|
})
|
|
|
|
it.each([
|
|
{
|
|
description: 'defaults to 0% when execution store values are missing',
|
|
execution: undefined,
|
|
node: undefined,
|
|
expectedTotal: 0,
|
|
expectedNode: 0
|
|
},
|
|
{
|
|
description: 'rounds fractional progress to the nearest integer',
|
|
execution: 0.324,
|
|
node: 0.005,
|
|
expectedTotal: 32,
|
|
expectedNode: 1
|
|
},
|
|
{
|
|
description: 'clamps values below 0 and above 100%',
|
|
execution: 1.5,
|
|
node: -0.25,
|
|
expectedTotal: 100,
|
|
expectedNode: 0
|
|
},
|
|
{
|
|
description: 'caps near-complete totals at 100%',
|
|
execution: 0.999,
|
|
node: 0.731,
|
|
expectedTotal: 100,
|
|
expectedNode: 73
|
|
}
|
|
])('$description', ({ execution, node, expectedTotal, expectedNode }) => {
|
|
setExecutionProgress(execution ?? null)
|
|
setExecutingNodeProgress(node ?? null)
|
|
|
|
const { composable } = mountUseQueueProgress()
|
|
|
|
expect(composable.totalPercent.value).toBe(expectedTotal)
|
|
expect(composable.currentNodePercent.value).toBe(expectedNode)
|
|
expect(composable.totalPercentFormatted.value).toBe(
|
|
formatPercent0(localeRef.value, expectedTotal)
|
|
)
|
|
expect(composable.currentNodePercentFormatted.value).toBe(
|
|
formatPercent0(localeRef.value, expectedNode)
|
|
)
|
|
})
|
|
|
|
it('reformats output when the active locale changes', async () => {
|
|
setExecutionProgress(0.32)
|
|
setExecutingNodeProgress(0.58)
|
|
|
|
const { composable } = mountUseQueueProgress()
|
|
|
|
expect(composable.totalPercentFormatted.value).toBe(
|
|
formatPercent0('en-US', composable.totalPercent.value)
|
|
)
|
|
expect(composable.currentNodePercentFormatted.value).toBe(
|
|
formatPercent0('en-US', composable.currentNodePercent.value)
|
|
)
|
|
|
|
localeRef.value = 'fr-FR'
|
|
await nextTick()
|
|
|
|
expect(composable.totalPercentFormatted.value).toBe(
|
|
formatPercent0('fr-FR', composable.totalPercent.value)
|
|
)
|
|
expect(composable.currentNodePercentFormatted.value).toBe(
|
|
formatPercent0('fr-FR', composable.currentNodePercent.value)
|
|
)
|
|
})
|
|
|
|
it('builds progress bar styles that track store updates', async () => {
|
|
setExecutionProgress(0.1)
|
|
setExecutingNodeProgress(0.25)
|
|
|
|
const { composable } = mountUseQueueProgress()
|
|
|
|
expect(composable.totalProgressStyle.value).toEqual({
|
|
width: '10%',
|
|
background: 'var(--color-interface-panel-job-progress-primary)'
|
|
})
|
|
expect(composable.currentNodeProgressStyle.value).toEqual({
|
|
width: '25%',
|
|
background: 'var(--color-interface-panel-job-progress-secondary)'
|
|
})
|
|
|
|
setExecutionProgress(0.755)
|
|
setExecutingNodeProgress(0.02)
|
|
await nextTick()
|
|
|
|
expect(composable.totalProgressStyle.value.width).toBe('76%')
|
|
expect(composable.currentNodeProgressStyle.value.width).toBe('2%')
|
|
})
|
|
})
|