-
Notifications
You must be signed in to change notification settings - Fork 449
Add preview to workflow tabs #4290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9259981
Add preview to workflow tabs
pythongosssss 3efb597
revert
pythongosssss f3cb375
Fix tests
pythongosssss dcfef58
Merge branch 'main' into pysssss/workflow-tab-preview
pythongosssss 9aa052c
Merge remote-tracking branch 'origin/main' into pysssss/workflow-tab-…
pythongosssss b93cf2a
Swap tab preview to use minimap
pythongosssss 17631bf
Hide popover on unmount
pythongosssss 16c9ce0
Revert "Merge remote-tracking branch 'origin/main' into pysssss/workf…
pythongosssss fcccbd4
Merge remote-tracking branch 'origin/main' into pysssss/workflow-tab-…
pythongosssss 106b25f
fix test
pythongosssss 24f91e8
Tweak colors for light mode
pythongosssss d890c98
Merge remote-tracking branch 'origin/main' into pysssss/workflow-tab-…
pythongosssss b0990e5
- Fix rename leaking thumbnail
pythongosssss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { expect } from '@playwright/test' | ||
|
|
||
| import { type ComfyPage, comfyPageFixture as test } from '../fixtures/ComfyPage' | ||
|
|
||
| test.describe('Workflow Tab Thumbnails', () => { | ||
| test.beforeEach(async ({ comfyPage }) => { | ||
| await comfyPage.setSetting('Comfy.UseNewMenu', 'Top') | ||
| await comfyPage.setSetting('Comfy.Workflow.WorkflowTabsPosition', 'Topbar') | ||
| await comfyPage.setup() | ||
| }) | ||
|
|
||
| async function getTab(comfyPage: ComfyPage, index: number) { | ||
| const tab = comfyPage.page | ||
| .locator(`.workflow-tabs .p-togglebutton`) | ||
| .nth(index) | ||
| return tab | ||
| } | ||
|
|
||
| async function getTabPopover( | ||
| comfyPage: ComfyPage, | ||
| index: number, | ||
| name?: string | ||
| ) { | ||
| const tab = await getTab(comfyPage, index) | ||
| await tab.hover() | ||
|
|
||
| const popover = comfyPage.page.locator('.workflow-popover-fade') | ||
| await expect(popover).toHaveCount(1) | ||
| await expect(popover).toBeVisible({ timeout: 500 }) | ||
| if (name) { | ||
| await expect(popover).toContainText(name) | ||
| } | ||
| return popover | ||
| } | ||
|
|
||
| async function getTabThumbnailImage( | ||
| comfyPage: ComfyPage, | ||
| index: number, | ||
| name?: string | ||
| ) { | ||
| const popover = await getTabPopover(comfyPage, index, name) | ||
| const thumbnailImg = popover.locator('.workflow-preview-thumbnail img') | ||
| return thumbnailImg | ||
| } | ||
|
|
||
| async function getNodeThumbnailBase64(comfyPage: ComfyPage, index: number) { | ||
| const thumbnailImg = await getTabThumbnailImage(comfyPage, index) | ||
| const src = (await thumbnailImg.getAttribute('src'))! | ||
|
|
||
| // Convert blob to base64, need to execute a script to get the base64 | ||
| const base64 = await comfyPage.page.evaluate(async (src: string) => { | ||
| const blob = await fetch(src).then((res) => res.blob()) | ||
| return new Promise((resolve, reject) => { | ||
| const reader = new FileReader() | ||
| reader.onloadend = () => resolve(reader.result) | ||
| reader.onerror = reject | ||
| reader.readAsDataURL(blob) | ||
| }) | ||
| }, src) | ||
| return base64 | ||
| } | ||
|
|
||
| test('Should show thumbnail when hovering over a non-active tab', async ({ | ||
| comfyPage | ||
| }) => { | ||
| await comfyPage.menu.topbar.triggerTopbarCommand(['Workflow', 'New']) | ||
| const thumbnailImg = await getTabThumbnailImage( | ||
| comfyPage, | ||
| 0, | ||
| 'Unsaved Workflow' | ||
| ) | ||
| await expect(thumbnailImg).toBeVisible() | ||
| }) | ||
|
|
||
| test('Should not show thumbnail for active tab', async ({ comfyPage }) => { | ||
| await comfyPage.menu.topbar.triggerTopbarCommand(['Workflow', 'New']) | ||
| const thumbnailImg = await getTabThumbnailImage( | ||
| comfyPage, | ||
| 1, | ||
| 'Unsaved Workflow (2)' | ||
| ) | ||
| await expect(thumbnailImg).not.toBeVisible() | ||
| }) | ||
|
|
||
| async function addNode(comfyPage: ComfyPage, category: string, node: string) { | ||
| const canvasArea = await comfyPage.canvas.boundingBox() | ||
|
|
||
| await comfyPage.page.mouse.move( | ||
| canvasArea!.x + canvasArea!.width - 100, | ||
| 100 | ||
| ) | ||
| await comfyPage.delay(300) // Wait for the popover to hide | ||
|
|
||
| await comfyPage.rightClickCanvas(200, 200) | ||
| await comfyPage.page.getByText('Add Node').click() | ||
| await comfyPage.nextFrame() | ||
| await comfyPage.page.getByText(category).click() | ||
| await comfyPage.nextFrame() | ||
| await comfyPage.page.getByText(node).click() | ||
| await comfyPage.nextFrame() | ||
| } | ||
|
|
||
| test('Thumbnail should update when switching tabs', async ({ comfyPage }) => { | ||
| // Wait for initial workflow to load | ||
| await comfyPage.nextFrame() | ||
|
|
||
| // Create a new workflow (tab 1) which will be empty | ||
| await comfyPage.menu.topbar.triggerTopbarCommand(['Workflow', 'New']) | ||
| await comfyPage.nextFrame() | ||
|
|
||
| // Now we have two tabs: tab 0 (default workflow with nodes) and tab 1 (empty) | ||
| // Tab 1 is currently active, so we can only get thumbnail for tab 0 | ||
|
|
||
| // Step 1: Different tabs should show different previews | ||
| const tab0ThumbnailWithNodes = await getNodeThumbnailBase64(comfyPage, 0) | ||
|
|
||
| // Add a node to tab 1 (current active tab) | ||
| await addNode(comfyPage, 'loaders', 'Load Checkpoint') | ||
| await comfyPage.nextFrame() | ||
|
|
||
| // Switch to tab 0 so we can get tab 1's thumbnail | ||
| await (await getTab(comfyPage, 0)).click() | ||
| await comfyPage.nextFrame() | ||
|
|
||
| const tab1ThumbnailWithNode = await getNodeThumbnailBase64(comfyPage, 1) | ||
|
|
||
| // The thumbnails should be different | ||
| expect(tab0ThumbnailWithNodes).not.toBe(tab1ThumbnailWithNode) | ||
|
|
||
| // Step 2: Switching without changes shouldn't update thumbnail | ||
| const tab1ThumbnailBefore = await getNodeThumbnailBase64(comfyPage, 1) | ||
|
|
||
| // Switch to tab 1 and back to tab 0 without making changes | ||
| await (await getTab(comfyPage, 1)).click() | ||
| await comfyPage.nextFrame() | ||
| await (await getTab(comfyPage, 0)).click() | ||
| await comfyPage.nextFrame() | ||
|
|
||
| const tab1ThumbnailAfter = await getNodeThumbnailBase64(comfyPage, 1) | ||
| expect(tab1ThumbnailBefore).toBe(tab1ThumbnailAfter) | ||
|
|
||
| // Step 3: Adding another node should cause thumbnail to change | ||
| // We're on tab 0, add a node | ||
| await addNode(comfyPage, 'loaders', 'Load VAE') | ||
| await comfyPage.nextFrame() | ||
|
|
||
| // Switch to tab 1 and back to update tab 0's thumbnail | ||
| await (await getTab(comfyPage, 1)).click() | ||
|
|
||
| const tab0ThumbnailAfterNewNode = await getNodeThumbnailBase64(comfyPage, 0) | ||
|
|
||
| // The thumbnail should have changed after adding a node | ||
| expect(tab0ThumbnailWithNodes).not.toBe(tab0ThumbnailAfterNewNode) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.