Skip to content

Commit

Permalink
Add playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Sep 11, 2024
1 parent b44c2cd commit 14d6395
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 11 deletions.
24 changes: 13 additions & 11 deletions browser_tests/assets/execution_error.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
{
"id": 14,
"type": "PreviewImage",
"pos": [
858,
-41
],
"pos": {
"0": 300,
"1": 60
},
"size": {
"0": 213.8594970703125,
"1": 50.65289306640625
Expand All @@ -23,24 +23,26 @@
"link": 15
}
],
"outputs": [],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 17,
"type": "DevToolsErrorRaiseNode",
"pos": [
477,
-40
],
"pos": {
"0": 20,
"1": 60
},
"size": {
"0": 210,
"1": 26
},
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
Expand Down Expand Up @@ -71,10 +73,10 @@
"config": {},
"extra": {
"ds": {
"scale": 1.2100000000000006,
"scale": 1,
"offset": [
-266.1038310281165,
337.94335447664554
117.20766722169206,
472.69035116826046
]
}
},
Expand Down
57 changes: 57 additions & 0 deletions browser_tests/nodeBadge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from '@playwright/test'
import { comfyPageFixture as test } from './ComfyPage'
import type { ComfyApp } from '../src/scripts/app'
import { NodeSourceBadgeMode } from '../src/types/nodeSource'

test.describe('Node Badge', () => {
test('Can add badge', async ({ comfyPage }) => {
Expand All @@ -20,4 +21,60 @@ test.describe('Node Badge', () => {

await expect(comfyPage.canvas).toHaveScreenshot('node-badge.png')
})

test('Can add multiple badges', async ({ comfyPage }) => {
await comfyPage.page.evaluate(() => {
const LGraphBadge = window['LGraphBadge']
const app = window['app'] as ComfyApp
const graph = app.graph
// @ts-expect-error - accessing private property
const nodes = graph._nodes

for (const node of nodes) {
node.badges = [
new LGraphBadge({ text: 'Test Badge 1' }),
new LGraphBadge({ text: 'Test Badge 2' })
]
}

graph.setDirtyCanvas(true, true)
})

await expect(comfyPage.canvas).toHaveScreenshot('node-badge-multiple.png')
})

test('Can add badge left-side', async ({ comfyPage }) => {
await comfyPage.page.evaluate(() => {
const LGraphBadge = window['LGraphBadge']
const app = window['app'] as ComfyApp
const graph = app.graph
// @ts-expect-error - accessing private property
const nodes = graph._nodes

for (const node of nodes) {
node.badges = [new LGraphBadge({ text: 'Test Badge' })]
// @ts-expect-error - Enum value
node.badgePosition = 'top-left'
}

graph.setDirtyCanvas(true, true)
})

await expect(comfyPage.canvas).toHaveScreenshot('node-badge-left.png')
})
})

test.describe('Node source badge', () => {
Object.values(NodeSourceBadgeMode).forEach(async (mode) => {
test(`Shows node source name (${mode})`, async ({ comfyPage }) => {
// Execution error workflow has both custom node and core node.
await comfyPage.loadWorkflow('execution_error')
await comfyPage.setSetting('Comfy.Node.NodeSourceBadgeMode', mode)
await comfyPage.nextFrame()
await comfyPage.resetView()
await expect(comfyPage.canvas).toHaveScreenshot(
`node-source-badge-${mode}.png`
)
})
})
})

0 comments on commit 14d6395

Please sign in to comment.