|
| 1 | +import { expect } from '@playwright/test' |
| 2 | + |
| 3 | +import { comfyPageFixture as test } from '../fixtures/ComfyPage' |
| 4 | + |
| 5 | +test.describe('Background Image Upload', () => { |
| 6 | + test.beforeEach(async ({ comfyPage }) => { |
| 7 | + // Reset the background image setting before each test |
| 8 | + await comfyPage.setSetting('Comfy.Canvas.BackgroundImage', '') |
| 9 | + }) |
| 10 | + |
| 11 | + test.afterEach(async ({ comfyPage }) => { |
| 12 | + // Clean up background image setting after each test |
| 13 | + await comfyPage.setSetting('Comfy.Canvas.BackgroundImage', '') |
| 14 | + }) |
| 15 | + |
| 16 | + test('should show background image upload component in settings', async ({ |
| 17 | + comfyPage |
| 18 | + }) => { |
| 19 | + // Open settings dialog |
| 20 | + await comfyPage.page.keyboard.press('Control+,') |
| 21 | + |
| 22 | + // Navigate to Appearance category |
| 23 | + const appearanceOption = comfyPage.page.locator('text=Appearance') |
| 24 | + await appearanceOption.click() |
| 25 | + |
| 26 | + // Find the background image setting |
| 27 | + const backgroundImageSetting = comfyPage.page.locator( |
| 28 | + '#Comfy\\.Canvas\\.BackgroundImage' |
| 29 | + ) |
| 30 | + await expect(backgroundImageSetting).toBeVisible() |
| 31 | + |
| 32 | + // Verify the component has the expected elements using semantic selectors |
| 33 | + const urlInput = backgroundImageSetting.locator('input[type="text"]') |
| 34 | + await expect(urlInput).toBeVisible() |
| 35 | + await expect(urlInput).toHaveAttribute('placeholder') |
| 36 | + |
| 37 | + const uploadButton = backgroundImageSetting.locator( |
| 38 | + 'button:has(.pi-upload)' |
| 39 | + ) |
| 40 | + await expect(uploadButton).toBeVisible() |
| 41 | + |
| 42 | + const clearButton = backgroundImageSetting.locator('button:has(.pi-trash)') |
| 43 | + await expect(clearButton).toBeVisible() |
| 44 | + await expect(clearButton).toBeDisabled() // Should be disabled when no image |
| 45 | + }) |
| 46 | + |
| 47 | + test('should upload image file and set as background', async ({ |
| 48 | + comfyPage |
| 49 | + }) => { |
| 50 | + // Open settings dialog |
| 51 | + await comfyPage.page.keyboard.press('Control+,') |
| 52 | + |
| 53 | + // Navigate to Appearance category |
| 54 | + const appearanceOption = comfyPage.page.locator('text=Appearance') |
| 55 | + await appearanceOption.click() |
| 56 | + |
| 57 | + // Find the background image setting |
| 58 | + const backgroundImageSetting = comfyPage.page.locator( |
| 59 | + '#Comfy\\.Canvas\\.BackgroundImage' |
| 60 | + ) |
| 61 | + // Click the upload button to trigger file input |
| 62 | + const uploadButton = backgroundImageSetting.locator( |
| 63 | + 'button:has(.pi-upload)' |
| 64 | + ) |
| 65 | + |
| 66 | + // Set up file upload handler |
| 67 | + const fileChooserPromise = comfyPage.page.waitForEvent('filechooser') |
| 68 | + await uploadButton.click() |
| 69 | + const fileChooser = await fileChooserPromise |
| 70 | + |
| 71 | + // Upload the test image |
| 72 | + await fileChooser.setFiles(comfyPage.assetPath('image32x32.webp')) |
| 73 | + |
| 74 | + // Wait for upload to complete and verify the setting was updated |
| 75 | + await comfyPage.page.waitForTimeout(500) // Give time for file reading |
| 76 | + |
| 77 | + // Verify the URL input now has an API URL |
| 78 | + const urlInput = backgroundImageSetting.locator('input[type="text"]') |
| 79 | + const inputValue = await urlInput.inputValue() |
| 80 | + expect(inputValue).toMatch(/^\/api\/view\?.*subfolder=backgrounds/) |
| 81 | + |
| 82 | + // Verify clear button is now enabled |
| 83 | + const clearButton = backgroundImageSetting.locator('button:has(.pi-trash)') |
| 84 | + await expect(clearButton).toBeEnabled() |
| 85 | + |
| 86 | + // Verify the setting value was actually set |
| 87 | + const settingValue = await comfyPage.getSetting( |
| 88 | + 'Comfy.Canvas.BackgroundImage' |
| 89 | + ) |
| 90 | + expect(settingValue).toMatch(/^\/api\/view\?.*subfolder=backgrounds/) |
| 91 | + }) |
| 92 | + |
| 93 | + test('should accept URL input for background image', async ({ |
| 94 | + comfyPage |
| 95 | + }) => { |
| 96 | + const testImageUrl = 'https://example.com/test-image.png' |
| 97 | + |
| 98 | + // Open settings dialog |
| 99 | + await comfyPage.page.keyboard.press('Control+,') |
| 100 | + |
| 101 | + // Navigate to Appearance category |
| 102 | + const appearanceOption = comfyPage.page.locator('text=Appearance') |
| 103 | + await appearanceOption.click() |
| 104 | + |
| 105 | + // Find the background image setting |
| 106 | + const backgroundImageSetting = comfyPage.page.locator( |
| 107 | + '#Comfy\\.Canvas\\.BackgroundImage' |
| 108 | + ) |
| 109 | + // Enter URL in the input field |
| 110 | + const urlInput = backgroundImageSetting.locator('input[type="text"]') |
| 111 | + await urlInput.fill(testImageUrl) |
| 112 | + |
| 113 | + // Trigger blur event to ensure the value is set |
| 114 | + await urlInput.blur() |
| 115 | + |
| 116 | + // Verify clear button is now enabled |
| 117 | + const clearButton = backgroundImageSetting.locator('button:has(.pi-trash)') |
| 118 | + await expect(clearButton).toBeEnabled() |
| 119 | + |
| 120 | + // Verify the setting value was updated |
| 121 | + const settingValue = await comfyPage.getSetting( |
| 122 | + 'Comfy.Canvas.BackgroundImage' |
| 123 | + ) |
| 124 | + expect(settingValue).toBe(testImageUrl) |
| 125 | + }) |
| 126 | + |
| 127 | + test('should clear background image when clear button is clicked', async ({ |
| 128 | + comfyPage |
| 129 | + }) => { |
| 130 | + const testImageUrl = 'https://example.com/test-image.png' |
| 131 | + |
| 132 | + // First set a background image |
| 133 | + await comfyPage.setSetting('Comfy.Canvas.BackgroundImage', testImageUrl) |
| 134 | + |
| 135 | + // Open settings dialog |
| 136 | + await comfyPage.page.keyboard.press('Control+,') |
| 137 | + |
| 138 | + // Navigate to Appearance category |
| 139 | + const appearanceOption = comfyPage.page.locator('text=Appearance') |
| 140 | + await appearanceOption.click() |
| 141 | + |
| 142 | + // Find the background image setting |
| 143 | + const backgroundImageSetting = comfyPage.page.locator( |
| 144 | + '#Comfy\\.Canvas\\.BackgroundImage' |
| 145 | + ) |
| 146 | + // Verify the input has the test URL |
| 147 | + const urlInput = backgroundImageSetting.locator('input[type="text"]') |
| 148 | + await expect(urlInput).toHaveValue(testImageUrl) |
| 149 | + |
| 150 | + // Verify clear button is enabled |
| 151 | + const clearButton = backgroundImageSetting.locator('button:has(.pi-trash)') |
| 152 | + await expect(clearButton).toBeEnabled() |
| 153 | + |
| 154 | + // Click the clear button |
| 155 | + await clearButton.click() |
| 156 | + |
| 157 | + // Verify the input is now empty |
| 158 | + await expect(urlInput).toHaveValue('') |
| 159 | + |
| 160 | + // Verify clear button is now disabled |
| 161 | + await expect(clearButton).toBeDisabled() |
| 162 | + |
| 163 | + // Verify the setting value was cleared |
| 164 | + const settingValue = await comfyPage.getSetting( |
| 165 | + 'Comfy.Canvas.BackgroundImage' |
| 166 | + ) |
| 167 | + expect(settingValue).toBe('') |
| 168 | + }) |
| 169 | + |
| 170 | + test('should show tooltip on upload and clear buttons', async ({ |
| 171 | + comfyPage |
| 172 | + }) => { |
| 173 | + // Open settings dialog |
| 174 | + await comfyPage.page.keyboard.press('Control+,') |
| 175 | + |
| 176 | + // Navigate to Appearance category |
| 177 | + const appearanceOption = comfyPage.page.locator('text=Appearance') |
| 178 | + await appearanceOption.click() |
| 179 | + |
| 180 | + // Find the background image setting |
| 181 | + const backgroundImageSetting = comfyPage.page.locator( |
| 182 | + '#Comfy\\.Canvas\\.BackgroundImage' |
| 183 | + ) |
| 184 | + // Hover over upload button and verify tooltip appears |
| 185 | + const uploadButton = backgroundImageSetting.locator( |
| 186 | + 'button:has(.pi-upload)' |
| 187 | + ) |
| 188 | + await uploadButton.hover() |
| 189 | + |
| 190 | + // Wait for tooltip to appear and verify it exists |
| 191 | + await comfyPage.page.waitForTimeout(700) // Tooltip delay |
| 192 | + const uploadTooltip = comfyPage.page.locator('.p-tooltip:visible') |
| 193 | + await expect(uploadTooltip).toBeVisible() |
| 194 | + |
| 195 | + // Move away to hide tooltip |
| 196 | + await comfyPage.page.locator('body').hover() |
| 197 | + await comfyPage.page.waitForTimeout(100) |
| 198 | + |
| 199 | + // Set a background to enable clear button |
| 200 | + const urlInput = backgroundImageSetting.locator('input[type="text"]') |
| 201 | + await urlInput.fill('https://example.com/test.png') |
| 202 | + await urlInput.blur() |
| 203 | + |
| 204 | + // Hover over clear button and verify tooltip appears |
| 205 | + const clearButton = backgroundImageSetting.locator('button:has(.pi-trash)') |
| 206 | + await clearButton.hover() |
| 207 | + |
| 208 | + // Wait for tooltip to appear and verify it exists |
| 209 | + await comfyPage.page.waitForTimeout(700) // Tooltip delay |
| 210 | + const clearTooltip = comfyPage.page.locator('.p-tooltip:visible') |
| 211 | + await expect(clearTooltip).toBeVisible() |
| 212 | + }) |
| 213 | + |
| 214 | + test('should maintain reactive updates between URL input and clear button state', async ({ |
| 215 | + comfyPage |
| 216 | + }) => { |
| 217 | + // Open settings dialog |
| 218 | + await comfyPage.page.keyboard.press('Control+,') |
| 219 | + |
| 220 | + // Navigate to Appearance category |
| 221 | + const appearanceOption = comfyPage.page.locator('text=Appearance') |
| 222 | + await appearanceOption.click() |
| 223 | + |
| 224 | + // Find the background image setting |
| 225 | + const backgroundImageSetting = comfyPage.page.locator( |
| 226 | + '#Comfy\\.Canvas\\.BackgroundImage' |
| 227 | + ) |
| 228 | + const urlInput = backgroundImageSetting.locator('input[type="text"]') |
| 229 | + const clearButton = backgroundImageSetting.locator('button:has(.pi-trash)') |
| 230 | + |
| 231 | + // Initially clear button should be disabled |
| 232 | + await expect(clearButton).toBeDisabled() |
| 233 | + |
| 234 | + // Type some text - clear button should become enabled |
| 235 | + await urlInput.fill('test') |
| 236 | + await expect(clearButton).toBeEnabled() |
| 237 | + |
| 238 | + // Clear the text manually - clear button should become disabled again |
| 239 | + await urlInput.fill('') |
| 240 | + await expect(clearButton).toBeDisabled() |
| 241 | + |
| 242 | + // Add text again - clear button should become enabled |
| 243 | + await urlInput.fill('https://example.com/image.png') |
| 244 | + await expect(clearButton).toBeEnabled() |
| 245 | + |
| 246 | + // Use clear button - should clear input and disable itself |
| 247 | + await clearButton.click() |
| 248 | + await expect(urlInput).toHaveValue('') |
| 249 | + await expect(clearButton).toBeDisabled() |
| 250 | + }) |
| 251 | +}) |
0 commit comments