Skip to content

Commit

Permalink
Add basic playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Aug 26, 2024
1 parent 8973a11 commit 536601b
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 15 deletions.
24 changes: 18 additions & 6 deletions browser_tests/ComfyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class NodeLibrarySidebarTab {
return this.page.locator('.node-lib-node-preview')
}

get tabContainer() {
return this.page.locator('.sidebar-content-container')
}

get newFolderButton() {
return this.tabContainer.locator('.new-folder-button')
}

async open() {
if (await this.selectedTabButton.isVisible()) {
return
Expand All @@ -74,16 +82,20 @@ class NodeLibrarySidebarTab {
await this.nodeLibraryTree.waitFor({ state: 'visible' })
}

folderSelector(folderName: string) {
return `.p-tree-node-content:has(> .node-lib-tree-node-label:has(.folder-label:has-text("${folderName}")))`
}

getFolder(folderName: string) {
return this.page.locator(
`.p-tree-node-content:has(> .node-lib-tree-node-label:has(.folder-label:has-text("${folderName}")))`
)
return this.page.locator(this.folderSelector(folderName))
}

nodeSelector(nodeName: string) {
return `.p-tree-node-content:has(> .node-lib-tree-node-label:has(.node-label:has-text("${nodeName}")))`
}

getNode(nodeName: string) {
return this.page.locator(
`.p-tree-node-content:has(> .node-lib-tree-node-label:has(.node-label:has-text("${nodeName}")))`
)
return this.page.locator(this.nodeSelector(nodeName))
}
}

Expand Down
113 changes: 104 additions & 9 deletions browser_tests/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ test.describe('Menu', () => {
})

test.describe('Node library sidebar', () => {
test('Node preview and drag to canvas', async ({ comfyPage }) => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', [])
// Open the sidebar
const tab = comfyPage.menu.nodeLibraryTab
await tab.open()
})

test('Node preview and drag to canvas', async ({ comfyPage }) => {
const tab = comfyPage.menu.nodeLibraryTab
await tab.getFolder('sampling').click()

// Hover over a node to display the preview
Expand All @@ -86,11 +91,7 @@ test.describe('Menu', () => {
})

test('Bookmark node', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', [])

// Open the sidebar
const tab = comfyPage.menu.nodeLibraryTab
await tab.open()
await tab.getFolder('sampling').click()

// Bookmark the node
Expand All @@ -116,13 +117,107 @@ test.describe('Menu', () => {
test('Ignores unrecognized node', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', ['foo'])

// Open the sidebar
const tab = comfyPage.menu.nodeLibraryTab
await tab.open()

expect(await tab.getFolder('sampling').count()).toBe(1)
expect(await tab.getNode('foo').count()).toBe(0)
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', [])
})

test('Displays empty bookmarks folder', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', ['foo/'])
const tab = comfyPage.menu.nodeLibraryTab
expect(await tab.getFolder('foo').count()).toBe(1)
})

test('Can add new bookmark folder', async ({ comfyPage }) => {
const tab = comfyPage.menu.nodeLibraryTab
await tab.newFolderButton.click()
await comfyPage.page.keyboard.press('Enter')
expect(await tab.getFolder('New Folder').count()).toBe(1)
expect(await comfyPage.getSetting('Comfy.NodeLibrary.Bookmarks')).toEqual(
['New Folder/']
)
})

test('Can add nested bookmark folder', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', ['foo/'])
const tab = comfyPage.menu.nodeLibraryTab

await tab.getFolder('foo').click({ button: 'right' })
await comfyPage.page.getByLabel('New Folder').click()
await comfyPage.page.keyboard.press('Enter')

expect(await comfyPage.getSetting('Comfy.NodeLibrary.Bookmarks')).toEqual(
['foo/', 'foo/New Folder/']
)
})

test('Can delete bookmark folder', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', ['foo/'])
const tab = comfyPage.menu.nodeLibraryTab

await tab.getFolder('foo').click({ button: 'right' })
await comfyPage.page.getByLabel('Delete').click()

expect(await comfyPage.getSetting('Comfy.NodeLibrary.Bookmarks')).toEqual(
[]
)
})

test('Can rename bookmark folder', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', ['foo/'])
const tab = comfyPage.menu.nodeLibraryTab

await tab.getFolder('foo').click({ button: 'right' })
await comfyPage.page.getByLabel('Rename').click()
await comfyPage.page.keyboard.insertText('bar')
await comfyPage.page.keyboard.press('Enter')

expect(await comfyPage.getSetting('Comfy.NodeLibrary.Bookmarks')).toEqual(
['bar/']
)
})

test('Can add bookmark by dragging node to bookmark folder', async ({
comfyPage
}) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', ['foo/'])
const tab = comfyPage.menu.nodeLibraryTab
await tab.getFolder('sampling').click()
await comfyPage.page.dragAndDrop(
tab.nodeSelector('KSampler (Advanced)'),
tab.folderSelector('foo')
)
expect(await comfyPage.getSetting('Comfy.NodeLibrary.Bookmarks')).toEqual(
['foo/', 'foo/KSampler (Advanced)']
)
})

test('Can add bookmark by clicking bookmark button', async ({
comfyPage
}) => {
const tab = comfyPage.menu.nodeLibraryTab
await tab.getFolder('sampling').click()
await tab
.getNode('KSampler (Advanced)')
.locator('.bookmark-button')
.click()
expect(await comfyPage.getSetting('Comfy.NodeLibrary.Bookmarks')).toEqual(
['KSampler (Advanced)']
)
})

test('Can unbookmark node', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.NodeLibrary.Bookmarks', [
'KSampler (Advanced)'
])
const tab = comfyPage.menu.nodeLibraryTab
await tab
.getNode('KSampler (Advanced)')
.locator('.bookmark-button')
.click()
expect(await comfyPage.getSetting('Comfy.NodeLibrary.Bookmarks')).toEqual(
[]
)
})
})

Expand Down
2 changes: 2 additions & 0 deletions src/components/sidebar/tabs/NodeLibrarySidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
<SidebarTabTemplate :title="$t('sideToolbar.nodeLibrary')">
<template #tool-buttons>
<Button
class="new-folder-button"
icon="pi pi-folder-plus"
text
severity="secondary"
@click="addNewBookmarkFolder()"
v-tooltip="$t('newFolder')"
/>
<Button
class="sort-button"
:icon="alphabeticalSort ? 'pi pi-sort-alpha-down' : 'pi pi-sort-alt'"
text
severity="secondary"
Expand Down

0 comments on commit 536601b

Please sign in to comment.