Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions browser_tests/fixtures/components/SettingDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export class SettingDialog extends BaseDialog {
await this.root.locator(`button[role="switch"][id="${id}"]`).click()
}

async selectSetting(id: string, value: string) {
await this.root
.locator(`[data-setting-id="${id}"]`)
.getByRole('combobox')
.click()
await this.page.getByRole('option', { name: value, exact: true }).click()
await expect.poll(() => this.comfyPage.settings.getSetting(id)).toBe(value)
}

category(name: string) {
return this.root.locator('nav').getByRole('button', { name })
}
Expand Down
93 changes: 93 additions & 0 deletions browser_tests/fixtures/helpers/LegacyNodeBadgeHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { expect } from '@playwright/test'
import type { Locator, Page } from '@playwright/test'

type BadgeTarget =
| { key: string; title: string; type?: never }
| { key: string; title?: never; type: string }

export class LegacyNodeBadgeHelper {
private readonly probe: Locator

constructor(private readonly page: Page) {
this.probe = page.locator('#legacy-node-badge-draw-probe')
}

async install(targets: readonly BadgeTarget[]) {
await this.page.evaluate((targets) => {
const probe = document.createElement('output')
probe.id = 'legacy-node-badge-draw-probe'
probe.hidden = true
probe.dataset.frames = '0'
document.body.append(probe)

for (const target of targets) {
const node = window.app!.graph.nodes.find((node) =>
target.title ? node.title === target.title : node.type === target.type
)
if (!node) throw new Error(`Badge node not found: ${target.key}`)

const drawBadges = node.drawBadges
node.drawBadges = function (ctx, options) {
const texts: string[] = []
const fillText = ctx.fillText
ctx.fillText = function (text, ...args) {
fillText.call(this, text, ...args)
texts.push(text)
}
try {
drawBadges.call(this, ctx, options)
probe.setAttribute(
`data-${target.key}-texts`,
JSON.stringify(texts)
)
probe.dataset.frames = String(Number(probe.dataset.frames) + 1)
} finally {
ctx.fillText = fillText
}
}
}
window.app!.graph.setDirtyCanvas(true, true)
}, targets)
}

async redraw() {
const frame = Number(await this.probe.getAttribute('data-frames'))
await this.page.evaluate(() => window.app!.graph.setDirtyCanvas(true, true))
await expect
.poll(async () => Number(await this.probe.getAttribute('data-frames')))
.toBeGreaterThan(frame)
}

async expectText(key: string, text: string, visible: boolean) {
const getTexts = async () => {
const serialized = await this.probe.getAttribute(`data-${key}-texts`)
// No frame has redrawn this node since install(). Return a value that
// matches neither `true` nor `false` so the poll keeps waiting: a probe
// that never draws must time out, not silently satisfy `visible: false`.
if (serialized === null) return null
const parsed: unknown = JSON.parse(serialized)
if (
!Array.isArray(parsed) ||
!parsed.every((value): value is string => typeof value === 'string')
) {
throw new Error(`Invalid legacy badge probe value: ${key}`)
}
return parsed.some((value) => value.includes(text))
}

await expect.poll(getTexts).toBe(visible)
}

async expectState(
expectations: readonly { key: string; text: string; visible: boolean }[]
) {
await this.redraw()
for (const expectation of expectations) {
await this.expectText(
expectation.key,
expectation.text,
expectation.visible
)
}
}
}
15 changes: 15 additions & 0 deletions browser_tests/fixtures/legacyNodeBadgeFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { mergeTests } from '@playwright/test'
import { networkIsolationFixture as base } from '@e2e/fixtures/networkIsolationFixture'

import { comfyPageFixture } from '@e2e/fixtures/ComfyPage'
import { LegacyNodeBadgeHelper } from '@e2e/fixtures/helpers/LegacyNodeBadgeHelper'

const legacyNodeBadgeFixture = base.extend<{
legacyNodeBadges: LegacyNodeBadgeHelper
}>({
legacyNodeBadges: async ({ page }, use) => {
await use(new LegacyNodeBadgeHelper(page))
}
})

export const test = mergeTests(comfyPageFixture, legacyNodeBadgeFixture)
74 changes: 74 additions & 0 deletions browser_tests/tests/links/deviceScaleFactor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { expect } from '@playwright/test'

import type { ComfyPage } from '@e2e/fixtures/ComfyPage'
import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'

test.use({
deviceScaleFactor: 1.5,
initialSettings: { 'Comfy.LinkRelease.Action': 'no action' }
})

test.describe('Link interaction at emulated display scaling', () => {
test(
'disconnects and reconnects the exact endpoint at 150 percent in the legacy renderer',
{ tag: '@canvas' },
async ({ comfyPage }) => {
test.slow()
await expectExactEndpointRoundTrip(comfyPage)
}
)

test(
'disconnects and reconnects the exact endpoint at 150 percent in the Vue renderer',
{ tag: ['@canvas', '@vue-nodes'] },
async ({ comfyPage }) => {
test.slow()
await expectExactEndpointRoundTrip(comfyPage)
}
)
})

async function expectExactEndpointRoundTrip(comfyPage: ComfyPage) {
await comfyPage.workflow.loadWorkflow('default')
expect(await comfyPage.page.evaluate(() => window.devicePixelRatio)).toBe(1.5)

const checkpoint = await comfyPage.nodeOps.getNodeRefById(4)
const prompt = await comfyPage.nodeOps.getNodeRefById(6)
const output = await checkpoint.getOutput(1)
const input = await prompt.getInput(0)

await test.step('disconnect the prompt input', async () => {
await comfyPage.canvasOps.dragAndDrop(await input.getPosition(), {
x: 800,
y: 100
})
await input.expectLinkCount(0)
})

await test.step('reconnect the exact endpoint', async () => {
await comfyPage.canvasOps.dragAndDrop(
await output.getPosition(),
await input.getPosition()
)
// Node ids serialise as strings, so normalise before comparing rather
// than asserting on the current runtime type.
await expect
.poll(async () => {
const link = await input.getLink()
if (!link) return null
return {
origin_id: String(link.origin_id),
origin_slot: link.origin_slot,
target_id: String(link.target_id),
target_slot: link.target_slot
}
})
.toEqual({
origin_id: '4',
origin_slot: 1,
target_id: '6',
target_slot: 0
})
await output.expectLinkCount(2)
})
}
88 changes: 88 additions & 0 deletions browser_tests/tests/selection/deviceScaleFactor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { expect } from '@playwright/test'

import type { ComfyPage } from '@e2e/fixtures/ComfyPage'
import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'

test.use({
deviceScaleFactor: 1.5,
initialSettings: { 'Comfy.Canvas.LeftMouseClickBehavior': 'select' }
})

test.describe('Marquee selection at emulated display scaling', () => {
test(
'tracks the cursor and selects the exact intersected nodes at 150 percent in the legacy renderer',
{ tag: '@canvas' },
async ({ comfyPage }) => {
test.slow()
await expectExactMarqueeSelection(comfyPage)
}
)

test(
'tracks the cursor and selects the exact intersected nodes at 150 percent in the Vue renderer',
{ tag: ['@canvas', '@vue-nodes'] },
async ({ comfyPage }) => {
test.slow()
await expectExactMarqueeSelection(comfyPage)
}
)
})

async function expectExactMarqueeSelection(comfyPage: ComfyPage) {
await comfyPage.workflow.loadWorkflow('default')
expect(await comfyPage.page.evaluate(() => window.devicePixelRatio)).toBe(1.5)

const bounds = await comfyPage.page.evaluate(() => {
const nodes = window.app!.graph.nodes.filter((node) =>
['6', '7'].includes(String(node.id))
)
const positions = nodes.map((node) => node.pos)
return {
start: window.app!.canvasPosToClientPos([
Math.min(...positions.map(([x]) => x)) - 64,
Math.min(...positions.map(([, y]) => y)) - 64
]),
end: window.app!.canvasPosToClientPos([
Math.max(...positions.map(([x]) => x)) + 64,
Math.max(...positions.map(([, y]) => y)) + 64
])
}
})
const clientPosition = ([x, y]: number[]) => ({ x, y })
const start = clientPosition(bounds.start)
const end = clientPosition(bounds.end)

await test.step('track the marquee in client coordinates', async () => {
await comfyPage.page.mouse.move(start.x, start.y)
await comfyPage.page.mouse.down()
await comfyPage.page.mouse.move(end.x, end.y, { steps: 10 })
await comfyPage.nextFrame()
const rectangle = await comfyPage.page.evaluate(() => {
const rectangle = window.app!.canvas.dragging_rectangle
if (!rectangle) return null
const start = window.app!.canvasPosToClientPos([
rectangle[0],
rectangle[1]
])
const end = window.app!.canvasPosToClientPos([
rectangle[0] + rectangle[2],
rectangle[1] + rectangle[3]
])
return { start, end }
})

await comfyPage.page.mouse.up()
expect(rectangle).toEqual({
start: [expect.closeTo(start.x, 0), expect.closeTo(start.y, 0)],
end: [expect.closeTo(end.x, 0), expect.closeTo(end.y, 0)]
})
})

await test.step('select exactly the intersected nodes', async () => {
await expect
.poll(async () =>
(await comfyPage.nodeOps.getSelectedNodeIds()).map(String).sort()
)
.toEqual(['6', '7'])
})
}
85 changes: 85 additions & 0 deletions browser_tests/tests/widgets/apiPricingBadge.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { expect } from '@playwright/test'

import type { ComfyPage } from '@e2e/fixtures/ComfyPage'
import { test } from '@e2e/fixtures/legacyNodeBadgeFixture'

const API_NODE_TITLE = 'Flux 1.1 [pro] Ultra Image'
const PRICE_TEXT = '12.7 credits/Run'

test.use({ initialSettings: { 'Comfy.NodeBadge.ShowApiPricing': true } })

test.beforeEach(async ({ context }) => {
await context.route(
'https://comfyanonymous.github.io/ComfyUI_examples/',
(route) =>
route.fulfill({ contentType: 'text/html', body: '<!doctype html>' })
)
})

test.describe(
'API node pricing badge (Vue)',
{ tag: ['@node', '@widget', '@vue-nodes'] },
() => {
test('follows the Settings UI toggle', async ({ comfyPage }) => {
await comfyPage.workflow.loadWorkflow('partner_api_node')
const vueNode = await comfyPage.vueNodes.getFixtureByTitle(API_NODE_TITLE)

await test.step('show pricing initially', async () => {
await expect(vueNode.priceBadge.required).toBeVisible()
})

await test.step('hide pricing through Settings', async () => {
await toggleApiPricing(comfyPage)
await expect(vueNode.priceBadge.required).toBeHidden()
})

await test.step('restore pricing through Settings', async () => {
await toggleApiPricing(comfyPage)
await expect(vueNode.priceBadge.required).toBeVisible()
})
})
}
)

test.describe(
'API node pricing badge (legacy)',
{ tag: ['@node', '@widget'] },
() => {
test('follows the Settings UI toggle', async ({
comfyPage,
legacyNodeBadges
}) => {
await comfyPage.workflow.loadWorkflow('partner_api_node')
await legacyNodeBadges.install([{ key: 'price', title: API_NODE_TITLE }])

await test.step('show pricing initially', async () => {
await legacyNodeBadges.expectState([
{ key: 'price', text: PRICE_TEXT, visible: true }
])
})

await test.step('hide pricing through Settings', async () => {
await toggleApiPricing(comfyPage)
await legacyNodeBadges.expectState([
{ key: 'price', text: PRICE_TEXT, visible: false }
])
})

await test.step('restore pricing through Settings', async () => {
await toggleApiPricing(comfyPage)
await legacyNodeBadges.expectState([
{ key: 'price', text: PRICE_TEXT, visible: true }
])
})
})
}
)

async function toggleApiPricing(comfyPage: ComfyPage) {
await comfyPage.settingDialog.open()
await comfyPage.settingDialog.category('Comfy').click()
await comfyPage.settingDialog.toggleBooleanSetting(
'Comfy.NodeBadge.ShowApiPricing'
)
await comfyPage.settingDialog.close()
}
Loading
Loading