From 14d639592819746548e1b18a015ec06ba64e0103 Mon Sep 17 00:00:00 2001 From: huchenlei Date: Wed, 11 Sep 2024 18:08:45 +0900 Subject: [PATCH] Add playwright tests --- browser_tests/assets/execution_error.json | 24 +++++----- browser_tests/nodeBadge.spec.ts | 57 +++++++++++++++++++++++ 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/browser_tests/assets/execution_error.json b/browser_tests/assets/execution_error.json index 76139d2b8..f18793b02 100644 --- a/browser_tests/assets/execution_error.json +++ b/browser_tests/assets/execution_error.json @@ -5,10 +5,10 @@ { "id": 14, "type": "PreviewImage", - "pos": [ - 858, - -41 - ], + "pos": { + "0": 300, + "1": 60 + }, "size": { "0": 213.8594970703125, "1": 50.65289306640625 @@ -23,6 +23,7 @@ "link": 15 } ], + "outputs": [], "properties": { "Node name for S&R": "PreviewImage" } @@ -30,10 +31,10 @@ { "id": 17, "type": "DevToolsErrorRaiseNode", - "pos": [ - 477, - -40 - ], + "pos": { + "0": 20, + "1": 60 + }, "size": { "0": 210, "1": 26 @@ -41,6 +42,7 @@ "flags": {}, "order": 0, "mode": 0, + "inputs": [], "outputs": [ { "name": "IMAGE", @@ -71,10 +73,10 @@ "config": {}, "extra": { "ds": { - "scale": 1.2100000000000006, + "scale": 1, "offset": [ - -266.1038310281165, - 337.94335447664554 + 117.20766722169206, + 472.69035116826046 ] } }, diff --git a/browser_tests/nodeBadge.spec.ts b/browser_tests/nodeBadge.spec.ts index d1e8731a5..b36ea3be8 100644 --- a/browser_tests/nodeBadge.spec.ts +++ b/browser_tests/nodeBadge.spec.ts @@ -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 }) => { @@ -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` + ) + }) + }) })