diff --git a/browser_tests/ComfyPage.ts b/browser_tests/ComfyPage.ts index eedd5885df..5b08c456e5 100644 --- a/browser_tests/ComfyPage.ts +++ b/browser_tests/ComfyPage.ts @@ -485,6 +485,36 @@ export class ComfyPage { return `./browser_tests/assets/${fileName}` } + async executeCommand(commandId: string) { + await this.page.evaluate((id: string) => { + return window['app'].extensionManager.command.execute(id) + }, commandId) + } + + async registerCommand( + commandId: string, + command: (() => void) | (() => Promise) + ) { + await this.page.evaluate( + ({ commandId, commandStr }) => { + const app = window['app'] + const randomSuffix = Math.random().toString(36).substring(2, 8) + const extensionName = `TestExtension_${randomSuffix}` + + app.registerExtension({ + name: extensionName, + commands: [ + { + id: commandId, + function: eval(commandStr) + } + ] + }) + }, + { commandId, commandStr: command.toString() } + ) + } + async registerKeybinding(keyCombo: KeyCombo, command: () => void) { await this.page.evaluate( ({ keyCombo, commandStr }) => { diff --git a/browser_tests/commands.spec.ts b/browser_tests/commands.spec.ts new file mode 100644 index 0000000000..7ee3744c99 --- /dev/null +++ b/browser_tests/commands.spec.ts @@ -0,0 +1,49 @@ +import { expect } from '@playwright/test' +import { comfyPageFixture as test } from './ComfyPage' + +test.describe('Keybindings', () => { + test('Should execute command', async ({ comfyPage }) => { + await comfyPage.registerCommand('TestCommand', () => { + window['foo'] = true + }) + + await comfyPage.executeCommand('TestCommand') + expect(await comfyPage.page.evaluate(() => window['foo'])).toBe(true) + }) + + test('Should execute async command', async ({ comfyPage }) => { + await comfyPage.registerCommand('TestCommand', async () => { + await new Promise((resolve) => + setTimeout(() => { + window['foo'] = true + resolve() + }, 5) + ) + }) + + await comfyPage.executeCommand('TestCommand') + expect(await comfyPage.page.evaluate(() => window['foo'])).toBe(true) + }) + + test('Should handle command errors', async ({ comfyPage }) => { + await comfyPage.registerCommand('TestCommand', () => { + throw new Error('Test error') + }) + + await comfyPage.executeCommand('TestCommand') + await expect(comfyPage.page.locator('.p-toast')).toBeVisible() + }) + + test('Should handle async command errors', async ({ comfyPage }) => { + await comfyPage.registerCommand('TestCommand', async () => { + await new Promise((resolve, reject) => + setTimeout(() => { + reject(new Error('Test error')) + }, 5) + ) + }) + + await comfyPage.executeCommand('TestCommand') + await expect(comfyPage.page.locator('.p-toast')).toBeVisible() + }) +}) diff --git a/src/components/actionbar/ComfyActionbar.vue b/src/components/actionbar/ComfyActionbar.vue index 6f4ad95783..fb3f8fab8f 100644 --- a/src/components/actionbar/ComfyActionbar.vue +++ b/src/components/actionbar/ComfyActionbar.vue @@ -37,7 +37,7 @@ :severity="executingPrompt ? 'danger' : 'secondary'" :disabled="!executingPrompt" text - @click="() => commandStore.getCommandFunction('Comfy.Interrupt')()" + @click="() => commandStore.execute('Comfy.Interrupt')" >