diff --git a/browser_tests/fixtures/ComfyPage.ts b/browser_tests/fixtures/ComfyPage.ts index ce7ca8c2df..6428c9531b 100644 --- a/browser_tests/fixtures/ComfyPage.ts +++ b/browser_tests/fixtures/ComfyPage.ts @@ -75,6 +75,28 @@ type FolderStructure = { [key: string]: FolderStructure | string } +type KeysOfType = { + [K in keyof T]: T[K] extends Match ? K : never +}[keyof T] + +class ConfirmDialog { + public readonly delete: Locator + public readonly overwrite: Locator + public readonly reject: Locator + + constructor(public readonly page: Page) { + this.delete = page.locator('button.p-button[aria-label="Delete"]') + this.overwrite = page.locator('button.p-button[aria-label="Overwrite"]') + this.reject = page.locator('button.p-button[aria-label="Cancel"]') + } + + async click(locator: KeysOfType) { + const loc = this[locator] + await expect(loc).toBeVisible() + await loc.click() + } +} + export class ComfyPage { public readonly url: string // All canvas position operations are based on default view of canvas. @@ -94,6 +116,7 @@ export class ComfyPage { public readonly actionbar: ComfyActionbar public readonly templates: ComfyTemplates public readonly settingDialog: SettingDialog + public readonly confirmDialog: ConfirmDialog /** Worker index to test user ID */ public readonly userIds: string[] = [] @@ -118,6 +141,7 @@ export class ComfyPage { this.actionbar = new ComfyActionbar(page) this.templates = new ComfyTemplates(page) this.settingDialog = new SettingDialog(page) + this.confirmDialog = new ConfirmDialog(page) } convertLeafToContent(structure: FolderStructure): FolderStructure { @@ -740,14 +764,14 @@ export class ComfyPage { ) } - async confirmDialog(prompt: string, text: string = 'Yes') { + async clickDialogButton(prompt: string, buttonText: string = 'Yes') { const modal = this.page.locator( `.comfy-modal-content:has-text("${prompt}")` ) await expect(modal).toBeVisible() await modal .locator('.comfyui-button', { - hasText: text + hasText: buttonText }) .click() await expect(modal).toBeHidden() diff --git a/browser_tests/menu.spec.ts b/browser_tests/menu.spec.ts index bc79e7e42b..5e67c4fa8e 100644 --- a/browser_tests/menu.spec.ts +++ b/browser_tests/menu.spec.ts @@ -442,7 +442,7 @@ test.describe('Menu', () => { ).toEqual(['workflow5.json']) await comfyPage.menu.topbar.saveWorkflowAs('workflow5.json') - await comfyPage.confirmDialog('Overwrite existing file?', 'Yes') + await comfyPage.confirmDialog.click('overwrite') expect( await comfyPage.menu.workflowsTab.getOpenedWorkflowNames() ).toEqual(['workflow5.json']) @@ -477,7 +477,7 @@ test.describe('Menu', () => { ) await topbar.saveWorkflowAs('workflow1.json') - await comfyPage.confirmDialog('Overwrite existing file?', 'Yes') + await comfyPage.confirmDialog.click('overwrite') // The old workflow1.json should be deleted and the new one should be saved. expect( await comfyPage.menu.workflowsTab.getOpenedWorkflowNames() @@ -519,6 +519,43 @@ test.describe('Menu', () => { await comfyPage.menu.workflowsTab.getOpenedWorkflowNames() ).toEqual(['*Unsaved Workflow.json']) }) + + test('Can delete workflows (confirm disabled)', async ({ comfyPage }) => { + await comfyPage.setSetting('Comfy.Workflow.ConfirmDelete', false) + + const { topbar, workflowsTab } = comfyPage.menu + + const filename = 'workflow18.json' + await topbar.saveWorkflow(filename) + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([filename]) + + await workflowsTab.getOpenedItem(filename).click({ button: 'right' }) + await comfyPage.nextFrame() + await comfyPage.clickContextMenuItem('Delete') + + await expect(workflowsTab.getOpenedItem(filename)).not.toBeVisible() + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([ + '*Unsaved Workflow.json' + ]) + }) + + test('Can delete workflows', async ({ comfyPage }) => { + const { topbar, workflowsTab } = comfyPage.menu + + const filename = 'workflow18.json' + await topbar.saveWorkflow(filename) + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([filename]) + + await workflowsTab.getOpenedItem(filename).click({ button: 'right' }) + await comfyPage.clickContextMenuItem('Delete') + + await comfyPage.confirmDialog.click('delete') + + await expect(workflowsTab.getOpenedItem(filename)).not.toBeVisible() + expect(await workflowsTab.getOpenedWorkflowNames()).toEqual([ + '*Unsaved Workflow.json' + ]) + }) }) test.describe('Workflows topbar tabs', () => { diff --git a/src/components/dialog/content/ConfirmationDialogContent.vue b/src/components/dialog/content/ConfirmationDialogContent.vue new file mode 100644 index 0000000000..81feebd9c0 --- /dev/null +++ b/src/components/dialog/content/ConfirmationDialogContent.vue @@ -0,0 +1,64 @@ + + + diff --git a/src/components/sidebar/tabs/WorkflowsSidebarTab.vue b/src/components/sidebar/tabs/WorkflowsSidebarTab.vue index 6a6263fc40..94526bc69e 100644 --- a/src/components/sidebar/tabs/WorkflowsSidebarTab.vue +++ b/src/components/sidebar/tabs/WorkflowsSidebarTab.vue @@ -123,6 +123,7 @@ +