mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-24 14:45:36 +00:00
## Summary
This is a follow-up PR of #11102
| Requirement | Status | Implementation |
| :--- | :--- | :--- |
| Add vitest configuration for desktop-ui workspace | ✅ Done | Added
`apps/desktop-ui/vitest.config.mts` with `happy-dom` environment, `@`
alias, and `setupFiles` pointing to `src/test/setup.ts` (registers
`@testing-library/jest-dom` matchers) |
| Add test:unit script to package.json | ✅ Done | Added `"test:unit":
"vitest run --config vitest.config.mts"` to
`apps/desktop-ui/package.json` |
| stores/maintenanceTaskStore.ts | ✅ Done | 34 tests covering task state
machine, IPC integration, executeTask flow, and error handling via
`@pinia/testing` |
| utils/electronMirrorCheck.ts | ✅ Done | 5 tests covering URL
validation, canAccessUrl delegation, and true/false return logic |
| utils/refUtil.ts (useMinLoadingDurationRef) | ✅ Done | 7 tests
covering initial state, timing behavior using `vi.useFakeTimers`, and
computed ref input |
| utils/envUtil.ts | ✅ Done | 7 tests covering electronAPI detection and
fallback behavior |
| constants/desktopDialogs.ts | ✅ Done | 8 tests covering dialog
structure and field contracts |
| constants/desktopMaintenanceTasks.ts | ✅ Done | 5 tests covering
`pythonPackages.execute` success/failure return values, and URL-opening
tasks calling `window.open` |
| composables/bottomPanelTabs/useTerminal.ts | ✅ Done | 7 tests covering
key event handler: Ctrl/Meta+C with/without selection, Ctrl/Meta+V,
non-keydown events, and unrelated keys — mocked xterm with Vitest
v4-compatible function constructors |
| composables/bottomPanelTabs/useTerminalBuffer.ts | ✅ Done | 2 tests
for `copyTo`: verifies serialized buffer content is written to
destination terminal |
| utils/validationUtil.ts | ⛔ Skipped | The current file contains only a
`ValidationState` enum with no logic. There is no behavior to test
without writing a change-detector test (asserting enum values), which
violates project testing guidelines |
**Additional config changes (not in issue but required to make tests
work):**
| Change | Reason |
| :--- | :--- |
| Added `"vitest.config.mts"` to `apps/desktop-ui/tsconfig.json` include
| Required for ESLint's TypeScript parser to process the config file
without a parsing error |
| Removed 6 redundant test devDependencies from
`apps/desktop-ui/package.json` | `vitest`, `@testing-library/*`,
`@pinia/testing`, `happy-dom` are already declared at the root and
hoisted by pnpm — re-declaring them in the sub-package is unnecessary |
## Changes
- Add vitest.config.mts with happy-dom environment and path aliases
- Add src/test/setup.ts to register @testing-library/jest-dom matchers
- Add test:unit script to package.json
- Add vitest.config.mts to tsconfig.json include for ESLint
compatibility
- Remove redundant test devDependencies already declared at root
- Add 132 tests across 16 files covering stores, composables, utils, and
constants
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Test- and config-only changes; main risk is CI/build instability from
new Vitest configuration or brittle mocks, with no runtime behavior
changes shipped to users.
>
> **Overview**
> Adds a dedicated Vitest setup for `apps/desktop-ui` (new
`vitest.config.mts` using `happy-dom`, aliases, and a `jest-dom` setup
file) and wires it into the workspace via a new `test:unit` script plus
`tsconfig.json` inclusion.
>
> Introduces a broad set of new unit tests for desktop UI components,
composables, constants, utilities, and the `maintenanceTaskStore`
(mocking Electron/PrimeVue/Xterm as needed) to validate state
transitions, validation flows, and key UI behaviors without changing
production logic.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
0a96ffb37c. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-11275-test-add-unit-test-suite-for-apps-desktop-ui-3436d73d36508145ae1fe99ec7a3a4fa)
by [Unito](https://www.unito.io)
103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { computed, nextTick, ref } from 'vue'
|
|
|
|
import { withSetup } from '@/test/withSetup'
|
|
import { useMinLoadingDurationRef } from '@/utils/refUtil'
|
|
|
|
describe('useMinLoadingDurationRef', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('reflects false when source is initially false', () => {
|
|
const source = ref(false)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source))
|
|
expect(result.value).toBe(false)
|
|
})
|
|
|
|
it('reflects true when source is initially true', () => {
|
|
const source = ref(true)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source))
|
|
expect(result.value).toBe(true)
|
|
})
|
|
|
|
it('becomes true immediately when source transitions to true', async () => {
|
|
const source = ref(false)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source))
|
|
source.value = true
|
|
await nextTick()
|
|
expect(result.value).toBe(true)
|
|
})
|
|
|
|
it('stays true within minDuration after source returns to false', async () => {
|
|
const source = ref(false)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source, 250))
|
|
|
|
source.value = true
|
|
await nextTick()
|
|
source.value = false
|
|
await nextTick()
|
|
|
|
vi.advanceTimersByTime(100)
|
|
await nextTick()
|
|
expect(result.value).toBe(true)
|
|
})
|
|
|
|
it('becomes false after minDuration has elapsed', async () => {
|
|
const source = ref(false)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source, 250))
|
|
|
|
source.value = true
|
|
await nextTick()
|
|
source.value = false
|
|
await nextTick()
|
|
|
|
vi.advanceTimersByTime(250)
|
|
await nextTick()
|
|
expect(result.value).toBe(false)
|
|
})
|
|
|
|
it('remains true while source is true even after minDuration elapses', async () => {
|
|
const source = ref(false)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source, 250))
|
|
|
|
source.value = true
|
|
await nextTick()
|
|
vi.advanceTimersByTime(500)
|
|
await nextTick()
|
|
expect(result.value).toBe(true)
|
|
})
|
|
|
|
it('works with a computed ref as input', async () => {
|
|
const raw = ref(false)
|
|
const source = computed(() => raw.value)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source))
|
|
|
|
raw.value = true
|
|
await nextTick()
|
|
expect(result.value).toBe(true)
|
|
})
|
|
|
|
it('uses 250ms as default minDuration', async () => {
|
|
const source = ref(false)
|
|
const result = withSetup(() => useMinLoadingDurationRef(source))
|
|
|
|
source.value = true
|
|
await nextTick()
|
|
source.value = false
|
|
await nextTick()
|
|
|
|
vi.advanceTimersByTime(249)
|
|
await nextTick()
|
|
expect(result.value).toBe(true)
|
|
|
|
vi.advanceTimersByTime(1)
|
|
await nextTick()
|
|
expect(result.value).toBe(false)
|
|
})
|
|
})
|