Skip to content

Commit

Permalink
Add playwright test
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Sep 3, 2024
1 parent eb12afc commit 76c337f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
7 changes: 4 additions & 3 deletions browser_tests/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ test.describe('Node Interaction', () => {
})

test('Can disconnect/connect edge', async ({ comfyPage }) => {
await comfyPage.setSetting(
'Comfy.NodeSearchBoxImpl.LinkReleaseAction',
'no action'
)
await comfyPage.disconnectEdge()
// Close search menu popped up.
await comfyPage.page.keyboard.press('Escape')
await comfyPage.nextFrame()
await expect(comfyPage.canvas).toHaveScreenshot(
'disconnected-edge-with-menu.png'
)
Expand Down
45 changes: 32 additions & 13 deletions browser_tests/nodeSearchBox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import { comfyPageFixture as test } from './ComfyPage'
test.describe('Node search box', () => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.setSetting(
'Comfy.NodeSearchBoxImpl.LinkReleaseTrigger',
'always'
'Comfy.NodeSearchBoxImpl.LinkReleaseAction',
'search box'
)
await comfyPage.setSetting(
'Comfy.NodeSearchBoxImpl.LinkReleaseActionShift',
'search box'
)
await comfyPage.setSetting('Comfy.NodeSearchBoxImpl', 'default')
})
;['always', 'hold shift', 'NOT hold shift'].forEach((triggerMode) => {
test(`Can trigger on empty canvas double click (${triggerMode})`, async ({
comfyPage
}) => {
await comfyPage.setSetting(
'Comfy.NodeSearchBoxImpl.LinkReleaseTrigger',
triggerMode
)
await comfyPage.doubleClickCanvas()
await expect(comfyPage.searchBox.input).toHaveCount(1)
})

test(`Can trigger on empty canvas double click`, async ({ comfyPage }) => {
await comfyPage.doubleClickCanvas()
await expect(comfyPage.searchBox.input).toHaveCount(1)
})

test('Can trigger on link release', async ({ comfyPage }) => {
Expand Down Expand Up @@ -78,3 +76,24 @@ test.describe('Node search box', () => {
)
})
})

test.describe('Release context menu', () => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.setSetting(
'Comfy.NodeSearchBoxImpl.LinkReleaseAction',
'context menu'
)
await comfyPage.setSetting(
'Comfy.NodeSearchBoxImpl.LinkReleaseActionShift',
'search box'
)
await comfyPage.setSetting('Comfy.NodeSearchBoxImpl', 'default')
})

test('Can trigger on link release', async ({ comfyPage }) => {
await comfyPage.disconnectEdge()
await expect(comfyPage.canvas).toHaveScreenshot(
'link-release-context-menu.png'
)
})
})
4 changes: 2 additions & 2 deletions src/components/searchbox/NodeSearchBoxPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ const handleCanvasEmptyRelease = (e: LiteGraphCanvasEvent) => {
? linkReleaseActionShift.value
: linkReleaseAction.value
switch (action) {
case LinkReleaseTriggerAction.SHOW_SEARCH_BOX:
case LinkReleaseTriggerAction.SEARCH_BOX:
showSearchBox(e)
break
case LinkReleaseTriggerAction.SHOW_CONTEXT_MENU:
case LinkReleaseTriggerAction.CONTEXT_MENU:
showContextMenu(e)
break
case LinkReleaseTriggerAction.NO_ACTION:
Expand Down
4 changes: 2 additions & 2 deletions src/stores/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const useSettingStore = defineStore('setting', {
name: 'Action on link release (No modifier)',
type: 'combo',
options: Object.values(LinkReleaseTriggerAction),
defaultValue: LinkReleaseTriggerAction.SHOW_CONTEXT_MENU
defaultValue: LinkReleaseTriggerAction.CONTEXT_MENU
})

app.ui.settings.addSetting({
Expand All @@ -107,7 +107,7 @@ export const useSettingStore = defineStore('setting', {
name: 'Action on link release (Shift)',
type: 'combo',
options: Object.values(LinkReleaseTriggerAction),
defaultValue: LinkReleaseTriggerAction.SHOW_SEARCH_BOX
defaultValue: LinkReleaseTriggerAction.SEARCH_BOX
})

app.ui.settings.addSetting({
Expand Down
4 changes: 2 additions & 2 deletions src/types/searchBoxTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export enum LinkReleaseTriggerMode {
}

export enum LinkReleaseTriggerAction {
SHOW_CONTEXT_MENU = 'context menu',
SHOW_SEARCH_BOX = 'search box',
CONTEXT_MENU = 'context menu',
SEARCH_BOX = 'search box',
NO_ACTION = 'no action'
}

0 comments on commit 76c337f

Please sign in to comment.