Rework command menu extension API (#1144)

* Rework command menu API

* Update test

* Update README

* Prevent register other extension's command
This commit is contained in:
Chenlei Hu
2024-10-06 23:31:57 -04:00
committed by GitHub
parent 05aa78372b
commit c83ce863d7
6 changed files with 104 additions and 49 deletions

View File

@@ -1,4 +1,4 @@
import { expect } from '@playwright/test'
import { expect, Locator } from '@playwright/test'
import { comfyPageFixture as test } from './ComfyPage'
test.describe('Topbar commands', () => {
@@ -12,24 +12,50 @@ test.describe('Topbar commands', () => {
test('Should allow registering topbar commands', async ({ comfyPage }) => {
await comfyPage.page.evaluate(() => {
window['app'].extensionManager.menu.registerTopbarCommands(
['ext'],
[
window['app'].registerExtension({
name: 'TestExtension1',
commands: [
{
id: 'foo',
label: 'foo',
label: 'foo-command',
function: () => {
window['foo'] = true
}
}
],
menuCommands: [
{
path: ['ext'],
commands: ['foo']
}
]
)
})
})
await comfyPage.menu.topbar.triggerTopbarCommand(['ext', 'foo'])
await comfyPage.menu.topbar.triggerTopbarCommand(['ext', 'foo-command'])
expect(await comfyPage.page.evaluate(() => window['foo'])).toBe(true)
})
test('Should not allow register command defined in other extension', async ({
comfyPage
}) => {
await comfyPage.registerCommand('foo', () => alert(1))
await comfyPage.page.evaluate(() => {
window['app'].registerExtension({
name: 'TestExtension1',
menuCommands: [
{
path: ['ext'],
commands: ['foo']
}
]
})
})
const menuItem: Locator = await comfyPage.menu.topbar.getMenuItem('ext')
expect(await menuItem.count()).toBe(0)
})
test('Should allow registering keybindings', async ({ comfyPage }) => {
await comfyPage.page.evaluate(() => {
const app = window['app']