mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 15:10:06 +00:00
## Summary Major refactoring of browser tests to improve reliability, maintainability, and type safety. ## Changes ### Test Infrastructure Decomposition - Decomposed `ComfyPage.ts` (~1000 lines) into focused helpers: - `CanvasHelper`, `DebugHelper`, `SubgraphHelper`, `NodeOperationsHelper` - `SettingsHelper`, `WorkflowHelper`, `ClipboardHelper`, `KeyboardHelper` - Created `ContextMenu` page object, `BaseDialog` base class, and `BottomPanel` page object - Extracted `DefaultGraphPositions` constants ### Locator Stability - Added `data-testid` attributes to Vue components (sidebar, dialogs, node library) - Created centralized `selectors.ts` with test ID constants - Replaced fragile CSS selectors (`.nth()`, `:nth-child()`) with `getByTestId`/`getByRole` ### Performance & Reliability - Removed `setTimeout` anti-patterns (replaced with `waitForFunction`) - Replaced `waitForTimeout` with retrying assertions - Replaced hardcoded coordinates with computed `NodeReference` positions - Enforced LF line endings for all text files ### Type Safety - Enabled `no-explicit-any` lint rule for browser_tests via oxlint - Purged `as any` casts from browser_tests - Added Window type augmentation for standardized window access - Added proper type annotations throughout ### Bug Fixes - Restored `ExtensionManager` API contract - Removed test-only settings from production schema - Fixed flaky selectors and missing test setup ## Testing - All browser tests pass - Typecheck passes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Overhauled browser E2E test infrastructure with many new helpers/fixtures, updated test APIs, and CI test container image bumped for consistency. * **Chores** * Standardized line endings and applied stricter lint rules for browser tests; workspace dependency version updated. * **Documentation** * Updated Playwright and TypeScript testing guidance and test-run commands. * **UI** * Added stable data-testids to multiple components to improve testability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
262 lines
8.4 KiB
TypeScript
262 lines
8.4 KiB
TypeScript
import { expect } from '@playwright/test'
|
|
|
|
import { comfyPageFixture as test } from '../fixtures/ComfyPage'
|
|
|
|
test.beforeEach(async ({ comfyPage }) => {
|
|
await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Disabled')
|
|
})
|
|
|
|
test.describe('Background Image Upload', () => {
|
|
test.beforeEach(async ({ comfyPage }) => {
|
|
// Reset the background image setting before each test
|
|
await comfyPage.settings.setSetting('Comfy.Canvas.BackgroundImage', '')
|
|
})
|
|
|
|
test.afterEach(async ({ comfyPage }) => {
|
|
// Clean up background image setting after each test
|
|
await comfyPage.settings.setSetting('Comfy.Canvas.BackgroundImage', '')
|
|
})
|
|
|
|
test('should show background image upload component in settings', async ({
|
|
comfyPage
|
|
}) => {
|
|
// Open settings dialog
|
|
await comfyPage.page.keyboard.press('Control+,')
|
|
|
|
// Navigate to Appearance category
|
|
const appearanceOption = comfyPage.page.locator('text=Appearance')
|
|
await appearanceOption.click()
|
|
|
|
// Find the background image setting
|
|
const backgroundImageSetting = comfyPage.page.locator(
|
|
'#Comfy\\.Canvas\\.BackgroundImage'
|
|
)
|
|
await expect(backgroundImageSetting).toBeVisible()
|
|
|
|
// Verify the component has the expected elements using semantic selectors
|
|
const urlInput = backgroundImageSetting.getByRole('textbox')
|
|
await expect(urlInput).toBeVisible()
|
|
await expect(urlInput).toHaveAttribute('placeholder')
|
|
|
|
const uploadButton = backgroundImageSetting.getByRole('button', {
|
|
name: /upload/i
|
|
})
|
|
await expect(uploadButton).toBeVisible()
|
|
|
|
const clearButton = backgroundImageSetting.getByRole('button', {
|
|
name: /clear/i
|
|
})
|
|
await expect(clearButton).toBeVisible()
|
|
await expect(clearButton).toBeDisabled() // Should be disabled when no image
|
|
})
|
|
|
|
test('should upload image file and set as background', async ({
|
|
comfyPage
|
|
}) => {
|
|
// Open settings dialog
|
|
await comfyPage.page.keyboard.press('Control+,')
|
|
|
|
// Navigate to Appearance category
|
|
const appearanceOption = comfyPage.page.locator('text=Appearance')
|
|
await appearanceOption.click()
|
|
|
|
// Find the background image setting
|
|
const backgroundImageSetting = comfyPage.page.locator(
|
|
'#Comfy\\.Canvas\\.BackgroundImage'
|
|
)
|
|
// Click the upload button to trigger file input
|
|
const uploadButton = backgroundImageSetting.getByRole('button', {
|
|
name: /upload/i
|
|
})
|
|
|
|
// Set up file upload handler
|
|
const fileChooserPromise = comfyPage.page.waitForEvent('filechooser')
|
|
await uploadButton.click()
|
|
const fileChooser = await fileChooserPromise
|
|
|
|
// Upload the test image
|
|
await fileChooser.setFiles(comfyPage.assetPath('image32x32.webp'))
|
|
|
|
// Verify the URL input now has an API URL
|
|
const urlInput = backgroundImageSetting.getByRole('textbox')
|
|
await expect(urlInput).toHaveValue(/^\/api\/view\?.*subfolder=backgrounds/)
|
|
|
|
// Verify clear button is now enabled
|
|
const clearButton = backgroundImageSetting.getByRole('button', {
|
|
name: /clear/i
|
|
})
|
|
await expect(clearButton).toBeEnabled()
|
|
|
|
// Verify the setting value was actually set
|
|
const settingValue = await comfyPage.settings.getSetting(
|
|
'Comfy.Canvas.BackgroundImage'
|
|
)
|
|
expect(settingValue).toMatch(/^\/api\/view\?.*subfolder=backgrounds/)
|
|
})
|
|
|
|
test('should accept URL input for background image', async ({
|
|
comfyPage
|
|
}) => {
|
|
const testImageUrl = 'https://example.com/test-image.png'
|
|
|
|
// Open settings dialog
|
|
await comfyPage.page.keyboard.press('Control+,')
|
|
|
|
// Navigate to Appearance category
|
|
const appearanceOption = comfyPage.page.locator('text=Appearance')
|
|
await appearanceOption.click()
|
|
|
|
// Find the background image setting
|
|
const backgroundImageSetting = comfyPage.page.locator(
|
|
'#Comfy\\.Canvas\\.BackgroundImage'
|
|
)
|
|
// Enter URL in the input field
|
|
const urlInput = backgroundImageSetting.getByRole('textbox')
|
|
await urlInput.fill(testImageUrl)
|
|
|
|
// Trigger blur event to ensure the value is set
|
|
await urlInput.blur()
|
|
|
|
// Verify clear button is now enabled
|
|
const clearButton = backgroundImageSetting.getByRole('button', {
|
|
name: /clear/i
|
|
})
|
|
await expect(clearButton).toBeEnabled()
|
|
|
|
// Verify the setting value was updated
|
|
const settingValue = await comfyPage.settings.getSetting(
|
|
'Comfy.Canvas.BackgroundImage'
|
|
)
|
|
expect(settingValue).toBe(testImageUrl)
|
|
})
|
|
|
|
test('should clear background image when clear button is clicked', async ({
|
|
comfyPage
|
|
}) => {
|
|
const testImageUrl = 'https://example.com/test-image.png'
|
|
|
|
// First set a background image
|
|
await comfyPage.settings.setSetting(
|
|
'Comfy.Canvas.BackgroundImage',
|
|
testImageUrl
|
|
)
|
|
|
|
// Open settings dialog
|
|
await comfyPage.page.keyboard.press('Control+,')
|
|
|
|
// Navigate to Appearance category
|
|
const appearanceOption = comfyPage.page.locator('text=Appearance')
|
|
await appearanceOption.click()
|
|
|
|
// Find the background image setting
|
|
const backgroundImageSetting = comfyPage.page.locator(
|
|
'#Comfy\\.Canvas\\.BackgroundImage'
|
|
)
|
|
// Verify the input has the test URL
|
|
const urlInput = backgroundImageSetting.getByRole('textbox')
|
|
await expect(urlInput).toHaveValue(testImageUrl)
|
|
|
|
// Verify clear button is enabled
|
|
const clearButton = backgroundImageSetting.getByRole('button', {
|
|
name: /clear/i
|
|
})
|
|
await expect(clearButton).toBeEnabled()
|
|
|
|
// Click the clear button
|
|
await clearButton.click()
|
|
|
|
// Verify the input is now empty
|
|
await expect(urlInput).toHaveValue('')
|
|
|
|
// Verify clear button is now disabled
|
|
await expect(clearButton).toBeDisabled()
|
|
|
|
// Verify the setting value was cleared
|
|
const settingValue = await comfyPage.settings.getSetting(
|
|
'Comfy.Canvas.BackgroundImage'
|
|
)
|
|
expect(settingValue).toBe('')
|
|
})
|
|
|
|
test('should show tooltip on upload and clear buttons', async ({
|
|
comfyPage
|
|
}) => {
|
|
// Open settings dialog
|
|
await comfyPage.page.keyboard.press('Control+,')
|
|
|
|
// Navigate to Appearance category
|
|
const appearanceOption = comfyPage.page.locator('text=Appearance')
|
|
await appearanceOption.click()
|
|
|
|
// Find the background image setting
|
|
const backgroundImageSetting = comfyPage.page.locator(
|
|
'#Comfy\\.Canvas\\.BackgroundImage'
|
|
)
|
|
// Hover over upload button and verify tooltip appears
|
|
const uploadButton = backgroundImageSetting.getByRole('button', {
|
|
name: /upload/i
|
|
})
|
|
await uploadButton.hover()
|
|
|
|
const uploadTooltip = comfyPage.page.locator('.p-tooltip:visible')
|
|
await expect(uploadTooltip).toBeVisible()
|
|
|
|
// Move away to hide tooltip
|
|
await comfyPage.page.locator('body').hover()
|
|
|
|
// Set a background to enable clear button
|
|
const urlInput = backgroundImageSetting.getByRole('textbox')
|
|
await urlInput.fill('https://example.com/test.png')
|
|
await urlInput.blur()
|
|
|
|
// Hover over clear button and verify tooltip appears
|
|
const clearButton = backgroundImageSetting.getByRole('button', {
|
|
name: /clear/i
|
|
})
|
|
await clearButton.hover()
|
|
|
|
const clearTooltip = comfyPage.page.locator('.p-tooltip:visible')
|
|
await expect(clearTooltip).toBeVisible()
|
|
})
|
|
|
|
test('should maintain reactive updates between URL input and clear button state', async ({
|
|
comfyPage
|
|
}) => {
|
|
// Open settings dialog
|
|
await comfyPage.page.keyboard.press('Control+,')
|
|
|
|
// Navigate to Appearance category
|
|
const appearanceOption = comfyPage.page.locator('text=Appearance')
|
|
await appearanceOption.click()
|
|
|
|
// Find the background image setting
|
|
const backgroundImageSetting = comfyPage.page.locator(
|
|
'#Comfy\\.Canvas\\.BackgroundImage'
|
|
)
|
|
const urlInput = backgroundImageSetting.getByRole('textbox')
|
|
const clearButton = backgroundImageSetting.getByRole('button', {
|
|
name: /clear/i
|
|
})
|
|
|
|
// Initially clear button should be disabled
|
|
await expect(clearButton).toBeDisabled()
|
|
|
|
// Type some text - clear button should become enabled
|
|
await urlInput.fill('test')
|
|
await expect(clearButton).toBeEnabled()
|
|
|
|
// Clear the text manually - clear button should become disabled again
|
|
await urlInput.fill('')
|
|
await expect(clearButton).toBeDisabled()
|
|
|
|
// Add text again - clear button should become enabled
|
|
await urlInput.fill('https://example.com/image.png')
|
|
await expect(clearButton).toBeEnabled()
|
|
|
|
// Use clear button - should clear input and disable itself
|
|
await clearButton.click()
|
|
await expect(urlInput).toHaveValue('')
|
|
await expect(clearButton).toBeDisabled()
|
|
})
|
|
})
|