Skip to content

Commit a17fb04

Browse files
webfilteredgithub-actions
andauthored
[Test] Add per-workflow viewport comparison test (#3867)
Co-authored-by: github-actions <[email protected]>
1 parent 5c0ad99 commit a17fb04

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

browser_tests/fixtures/ComfyPage.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ export class ComfyPage {
133133
// Inputs
134134
public readonly workflowUploadInput: Locator
135135

136+
// Toasts
137+
public readonly visibleToasts: Locator
138+
136139
// Components
137140
public readonly searchBox: ComfyNodeSearchBox
138141
public readonly menu: ComfyMenu
@@ -159,6 +162,8 @@ export class ComfyPage {
159162
this.resetViewButton = page.getByRole('button', { name: 'Reset View' })
160163
this.queueButton = page.getByRole('button', { name: 'Queue Prompt' })
161164
this.workflowUploadInput = page.locator('#comfy-file-input')
165+
this.visibleToasts = page.locator('.p-toast-message:visible')
166+
162167
this.searchBox = new ComfyNodeSearchBox(page)
163168
this.menu = new ComfyMenu(page)
164169
this.actionbar = new ComfyActionbar(page)
@@ -397,6 +402,30 @@ export class ComfyPage {
397402
await this.nextFrame()
398403
}
399404

405+
async deleteWorkflow(
406+
workflowName: string,
407+
whenMissing: 'ignoreMissing' | 'throwIfMissing' = 'ignoreMissing'
408+
) {
409+
// Open workflows tab
410+
const { workflowsTab } = this.menu
411+
await workflowsTab.open()
412+
413+
// Action to take if workflow missing
414+
if (whenMissing === 'ignoreMissing') {
415+
const workflows = await workflowsTab.getTopLevelSavedWorkflowNames()
416+
if (!workflows.includes(workflowName)) return
417+
}
418+
419+
// Delete workflow
420+
await workflowsTab.getPersistedItem(workflowName).click({ button: 'right' })
421+
await this.clickContextMenuItem('Delete')
422+
await this.confirmDialog.delete.click()
423+
424+
// Clear toast & close tab
425+
await this.closeToasts(1)
426+
await workflowsTab.close()
427+
}
428+
400429
async resetView() {
401430
if (await this.resetViewButton.isVisible()) {
402431
await this.resetViewButton.click()
@@ -413,7 +442,20 @@ export class ComfyPage {
413442
}
414443

415444
async getVisibleToastCount() {
416-
return await this.page.locator('.p-toast-message:visible').count()
445+
return await this.visibleToasts.count()
446+
}
447+
448+
async closeToasts(requireCount = 0) {
449+
if (requireCount) await expect(this.visibleToasts).toHaveCount(requireCount)
450+
451+
// Clear all toasts
452+
const toastCloseButtons = await this.page
453+
.locator('.p-toast-close-button')
454+
.all()
455+
for (const button of toastCloseButtons) {
456+
await button.click()
457+
}
458+
await expect(this.visibleToasts).toHaveCount(0)
417459
}
418460

419461
async clickTextEncodeNode1() {

browser_tests/tests/interaction.spec.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@playwright/test'
22

3-
import { comfyPageFixture as test } from '../fixtures/ComfyPage'
3+
import { type ComfyPage, comfyPageFixture as test } from '../fixtures/ComfyPage'
44

55
test.describe('Item Interaction', () => {
66
test('Can select/delete all items', async ({ comfyPage }) => {
@@ -689,3 +689,42 @@ test.describe('Load duplicate workflow', () => {
689689
expect(await comfyPage.getGraphNodesCount()).toBe(1)
690690
})
691691
})
692+
693+
test.describe('Viewport settings', () => {
694+
test.beforeEach(async ({ comfyPage }) => {
695+
await comfyPage.setSetting('Comfy.UseNewMenu', 'Top')
696+
await comfyPage.setSetting('Comfy.Workflow.WorkflowTabsPosition', 'Topbar')
697+
698+
await comfyPage.setupWorkflowsDirectory({})
699+
})
700+
701+
test('Keeps viewport settings when changing tabs', async ({
702+
comfyPage,
703+
comfyMouse
704+
}) => {
705+
// Screenshot the canvas element
706+
await comfyPage.menu.topbar.saveWorkflow('Workflow A')
707+
await expect(comfyPage.canvas).toHaveScreenshot('viewport-workflow-a.png')
708+
709+
// Save workflow as a new file, then zoom out before screen shot
710+
await comfyPage.menu.topbar.saveWorkflowAs('Workflow B')
711+
await comfyMouse.move(comfyPage.emptySpace)
712+
for (let i = 0; i < 4; i++) {
713+
await comfyMouse.wheel(0, 60)
714+
}
715+
await expect(comfyPage.canvas).toHaveScreenshot('viewport-workflow-b.png')
716+
717+
const tabA = comfyPage.menu.topbar.getWorkflowTab('Workflow A')
718+
const tabB = comfyPage.menu.topbar.getWorkflowTab('Workflow B')
719+
720+
// Go back to Workflow A
721+
await tabA.click()
722+
await comfyPage.nextFrame()
723+
await expect(comfyPage.canvas).toHaveScreenshot('viewport-workflow-a.png')
724+
725+
// And back to Workflow B
726+
await tabB.click()
727+
await comfyPage.nextFrame()
728+
await expect(comfyPage.canvas).toHaveScreenshot('viewport-workflow-b.png')
729+
})
730+
})
80.3 KB
Loading
67.4 KB
Loading

0 commit comments

Comments
 (0)