import { expect } from '@playwright/test' import type { ComfyPage } from '../fixtures/ComfyPage' import { comfyPageFixture as test } from '../fixtures/ComfyPage' test.describe('Mask Editor', () => { test.beforeEach(async ({ comfyPage }) => { await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true) }) async function loadImageOnNode(comfyPage: ComfyPage) { await comfyPage.workflow.loadWorkflow('widgets/load_image_widget') await comfyPage.vueNodes.waitForNodes() const loadImageNode = ( await comfyPage.nodeOps.getNodeRefsByType('LoadImage') )[0] const { x, y } = await loadImageNode.getPosition() await comfyPage.dragDrop.dragAndDropFile('image64x64.webp', { dropPosition: { x, y } }) const imagePreview = comfyPage.page.locator('.image-preview') await expect(imagePreview).toBeVisible() await expect(imagePreview.locator('img')).toBeVisible() await expect(imagePreview).toContainText('x') return { imagePreview, nodeId: String(loadImageNode.id) } } test( 'opens mask editor from image preview button', { tag: ['@smoke', '@screenshot'] }, async ({ comfyPage }) => { const { imagePreview } = await loadImageOnNode(comfyPage) // Hover over the image panel to reveal action buttons await imagePreview.getByRole('region').hover() await comfyPage.page.getByLabel('Edit or mask image').click() const dialog = comfyPage.page.locator('.mask-editor-dialog') await expect(dialog).toBeVisible() await expect( dialog.getByRole('heading', { name: 'Mask Editor' }) ).toBeVisible() const canvasContainer = dialog.locator('#maskEditorCanvasContainer') await expect(canvasContainer).toBeVisible() await expect(canvasContainer.locator('canvas')).toHaveCount(4) await expect(dialog.locator('.maskEditor-ui-container')).toBeVisible() await expect(dialog.getByText('Save')).toBeVisible() await expect(dialog.getByText('Cancel')).toBeVisible() await expect(dialog).toHaveScreenshot('mask-editor-dialog-open.png') } ) test( 'opens mask editor from context menu', { tag: ['@smoke', '@screenshot'] }, async ({ comfyPage }) => { const { nodeId } = await loadImageOnNode(comfyPage) const nodeHeader = comfyPage.vueNodes .getNodeLocator(nodeId) .locator('.lg-node-header') await nodeHeader.click() await nodeHeader.click({ button: 'right' }) const contextMenu = comfyPage.page.locator('.p-contextmenu') await expect(contextMenu).toBeVisible() await contextMenu.getByText('Open in Mask Editor').click() const dialog = comfyPage.page.locator('.mask-editor-dialog') await expect(dialog).toBeVisible() await expect( dialog.getByRole('heading', { name: 'Mask Editor' }) ).toBeVisible() await expect(dialog).toHaveScreenshot( 'mask-editor-dialog-from-context-menu.png' ) } ) })