Skip to content
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

Fix closing saved workflows #1049

Merged
merged 3 commits into from
Sep 30, 2024
Merged
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
28 changes: 28 additions & 0 deletions browser_tests/ComfyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,34 @@ class Topbar {
.allInnerTexts()
}

async getMenuItem(itemLabel: string): Promise<Locator> {
return this.page.locator(`.p-menubar-item-label:text-is("${itemLabel}")`)
}

async getWorkflowTab(tabName: string): Promise<Locator> {
return this.page
.locator(`.workflow-tabs .workflow-label:has-text("${tabName}")`)
.locator('..')
}

async closeWorkflowTab(tabName: string) {
const tab = await this.getWorkflowTab(tabName)
await tab.locator('.close-button').click({ force: true })
}

async saveWorkflow(workflowName: string) {
this.page.on('dialog', async (dialog) => {
await dialog.accept(workflowName)
})
const workflowMenuItem = await this.getMenuItem('Workflow')
workflowMenuItem.click()
await this.page.evaluate(() => {
return new Promise<number>(requestAnimationFrame)
})
const saveButton = await this.getMenuItem('Save')
await saveButton.click()
}

async triggerTopbarCommand(path: string[]) {
if (path.length < 2) {
throw new Error('Path is too short')
Expand Down
32 changes: 32 additions & 0 deletions browser_tests/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,19 @@ test.describe('Menu', () => {
comfyPage.page.locator('.comfy-missing-nodes')
).not.toBeVisible()
})

test('Can close saved-workflows from the open workflows section', async ({
comfyPage
}) => {
await comfyPage.menu.topbar.saveWorkflow('deault')
const closeButton = comfyPage.page.locator(
'.comfyui-workflows-open .p-button-icon.pi-times'
)
await closeButton.click()
expect(
await comfyPage.menu.workflowsTab.getOpenedWorkflowNames()
).toEqual(['*Unsaved Workflow (2).json'])
})
})

test.describe('Workflows topbar tabs', () => {
Expand All @@ -447,11 +460,30 @@ test.describe('Menu', () => {
)
})

test.afterEach(async ({ comfyPage }) => {
// Delete the saved workflow for cleanup.
await comfyPage.page.evaluate(async () => {
window['app'].workflowManager.activeWorkflow.delete()
})
})

test('Can show opened workflows', async ({ comfyPage }) => {
expect(await comfyPage.menu.topbar.getTabNames()).toEqual([
'Unsaved Workflow'
])
})

test('Can close saved-workflow tabs', async ({ comfyPage }) => {
const savedWorkflowName = 'default'
await comfyPage.menu.topbar.saveWorkflow(savedWorkflowName)
expect(await comfyPage.menu.topbar.getTabNames()).toEqual([
savedWorkflowName
])
await comfyPage.menu.topbar.closeWorkflowTab('default')
expect(await comfyPage.menu.topbar.getTabNames()).toEqual([
'Unsaved Workflow (2)'
])
})
})

// Only test 'Top' to reduce test time.
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ export class ComfyWorkflow {

if (!this.path) {
// Saved new workflow, patch this instance
const oldKey = this.key
this.updatePath(path, null)

// Update workflowLookup: change the key from the old unsaved path to the new saved path
delete this.manager.workflowStore.workflowLookup[oldKey]
this.manager.workflowStore.workflowLookup[this.key] = this

await this.manager.loadWorkflows()
this.unsaved = false
this.manager.dispatchEvent(new CustomEvent('rename', { detail: this }))
Expand Down
Loading