mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
test: address minimap spec review feedback
This commit is contained in:
@@ -1,8 +1,21 @@
|
||||
import { expect } from '@playwright/test'
|
||||
import type { Locator } from '@playwright/test'
|
||||
|
||||
import { comfyPageFixture as test } from '../fixtures/ComfyPage'
|
||||
import { TestIds } from '../fixtures/selectors'
|
||||
|
||||
function hasCanvasContent(canvas: Locator): Promise<boolean> {
|
||||
return canvas.evaluate((el: HTMLCanvasElement) => {
|
||||
const ctx = el.getContext('2d')
|
||||
if (!ctx) return false
|
||||
const { data } = ctx.getImageData(0, 0, el.width, el.height)
|
||||
for (let i = 3; i < data.length; i += 4) {
|
||||
if (data[i] > 0) return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
test.describe('Minimap', { tag: '@canvas' }, () => {
|
||||
test.beforeEach(async ({ comfyPage }) => {
|
||||
await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Top')
|
||||
@@ -118,19 +131,9 @@ test.describe('Minimap', { tag: '@canvas' }, () => {
|
||||
const minimapCanvas = comfyPage.page.locator('.minimap-canvas')
|
||||
await expect(minimapCanvas).toBeVisible()
|
||||
|
||||
const hasContent = await minimapCanvas.evaluate(
|
||||
(canvas: HTMLCanvasElement) => {
|
||||
const ctx = canvas.getContext('2d')
|
||||
if (!ctx) return false
|
||||
const { data } = ctx.getImageData(0, 0, canvas.width, canvas.height)
|
||||
for (let i = 3; i < data.length; i += 4) {
|
||||
if (data[i] > 0) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
)
|
||||
|
||||
expect(hasContent).toBe(true)
|
||||
await expect
|
||||
.poll(() => hasCanvasContent(minimapCanvas), { timeout: 2000 })
|
||||
.toBe(true)
|
||||
})
|
||||
|
||||
test('Minimap canvas is empty after all nodes are deleted', async ({
|
||||
@@ -146,26 +149,15 @@ test.describe('Minimap', { tag: '@canvas' }, () => {
|
||||
.toBe(0)
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
() =>
|
||||
minimapCanvas.evaluate((canvas: HTMLCanvasElement) => {
|
||||
const ctx = canvas.getContext('2d')
|
||||
if (!ctx) return true
|
||||
const { data } = ctx.getImageData(0, 0, canvas.width, canvas.height)
|
||||
for (let i = 3; i < data.length; i += 4) {
|
||||
if (data[i] > 0) return false
|
||||
}
|
||||
return true
|
||||
}),
|
||||
{ timeout: 2000 }
|
||||
)
|
||||
.toBe(true)
|
||||
.poll(() => hasCanvasContent(minimapCanvas), { timeout: 2000 })
|
||||
.toBe(false)
|
||||
})
|
||||
|
||||
test('Clicking minimap corner pans the main canvas', async ({
|
||||
comfyPage
|
||||
}) => {
|
||||
const minimap = comfyPage.page.locator('.litegraph-minimap')
|
||||
const viewport = minimap.locator('.minimap-viewport')
|
||||
const overlay = comfyPage.page.getByTestId(
|
||||
TestIds.canvas.minimapInteractionOverlay
|
||||
)
|
||||
@@ -176,6 +168,10 @@ test.describe('Minimap', { tag: '@canvas' }, () => {
|
||||
y: window.app!.canvas.ds.offset[1]
|
||||
}))
|
||||
|
||||
const transformBefore = await viewport.evaluate(
|
||||
(el: HTMLElement) => el.style.transform
|
||||
)
|
||||
|
||||
const box = await overlay.boundingBox()
|
||||
expect(box, 'Minimap interaction overlay not found').toBeTruthy()
|
||||
|
||||
@@ -196,6 +192,12 @@ test.describe('Minimap', { tag: '@canvas' }, () => {
|
||||
after,
|
||||
'Canvas offset should change after clicking minimap corner'
|
||||
).not.toStrictEqual(before)
|
||||
|
||||
await expect
|
||||
.poll(() => viewport.evaluate((el: HTMLElement) => el.style.transform), {
|
||||
timeout: 2000
|
||||
})
|
||||
.not.toBe(transformBefore)
|
||||
})
|
||||
|
||||
test('Clicking minimap center after FitView causes minimal canvas movement', async ({
|
||||
@@ -229,9 +231,7 @@ test.describe('Minimap', { tag: '@canvas' }, () => {
|
||||
y: window.app!.canvas.ds.offset[1]
|
||||
}))
|
||||
|
||||
// Clicking the minimap center maps to approximately the center of the node
|
||||
// bounds, which FitView also centers on. A small residual offset is expected
|
||||
// due to the 250px (logical) vs 253px (CSS) width discrepancy in the overlay.
|
||||
// ~3px overlay error × ~15 canvas/minimap scale ≈ 45, rounded up
|
||||
const TOLERANCE = 50
|
||||
expect(
|
||||
Math.abs(after.x - before.x),
|
||||
@@ -243,38 +243,6 @@ test.describe('Minimap', { tag: '@canvas' }, () => {
|
||||
).toBeLessThan(TOLERANCE)
|
||||
})
|
||||
|
||||
test('Viewport rectangle updates after minimap click', async ({
|
||||
comfyPage
|
||||
}) => {
|
||||
const minimap = comfyPage.page.locator('.litegraph-minimap')
|
||||
const viewport = minimap.locator('.minimap-viewport')
|
||||
const overlay = comfyPage.page.getByTestId(
|
||||
TestIds.canvas.minimapInteractionOverlay
|
||||
)
|
||||
await expect(minimap).toBeVisible()
|
||||
|
||||
const transformBefore = await viewport.evaluate(
|
||||
(el: HTMLElement) => el.style.transform
|
||||
)
|
||||
|
||||
const box = await overlay.boundingBox()
|
||||
expect(box, 'Minimap interaction overlay not found').toBeTruthy()
|
||||
|
||||
// Click bottom-left area — clear of the settings button (top-left, 32×32px)
|
||||
// and close button (top-right, 32×32px)
|
||||
await comfyPage.page.mouse.click(
|
||||
box!.x + box!.width * 0.15,
|
||||
box!.y + box!.height * 0.85
|
||||
)
|
||||
await comfyPage.nextFrame()
|
||||
|
||||
await expect
|
||||
.poll(() => viewport.evaluate((el: HTMLElement) => el.style.transform), {
|
||||
timeout: 1000
|
||||
})
|
||||
.not.toBe(transformBefore)
|
||||
})
|
||||
|
||||
test(
|
||||
'Viewport rectangle is visible and positioned within minimap',
|
||||
{ tag: '@screenshot' },
|
||||
|
||||
Reference in New Issue
Block a user