mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
Restore all open workflows on load (#2238)
This commit is contained in:
@@ -3,6 +3,7 @@ import { createPinia, setActivePinia } from 'pinia'
|
||||
import { api } from '@/scripts/api'
|
||||
import { defaultGraph, defaultGraphJSON } from '@/scripts/defaultGraph'
|
||||
import {
|
||||
ComfyWorkflow,
|
||||
LoadedComfyWorkflow,
|
||||
useWorkflowBookmarkStore,
|
||||
useWorkflowStore
|
||||
@@ -161,6 +162,97 @@ describe('useWorkflowStore', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('openWorkflowsInBackground', () => {
|
||||
let workflowA: ComfyWorkflow
|
||||
let workflowB: ComfyWorkflow
|
||||
let workflowC: ComfyWorkflow
|
||||
|
||||
const openWorkflowPaths = () =>
|
||||
store.openWorkflows.filter((w) => store.isOpen(w)).map((w) => w.path)
|
||||
|
||||
beforeEach(async () => {
|
||||
await syncRemoteWorkflows(['a.json', 'b.json', 'c.json'])
|
||||
workflowA = store.getWorkflowByPath('workflows/a.json')!
|
||||
workflowB = store.getWorkflowByPath('workflows/b.json')!
|
||||
workflowC = store.getWorkflowByPath('workflows/c.json')!
|
||||
;(api.getUserData as jest.Mock).mockResolvedValue({
|
||||
status: 200,
|
||||
text: () => Promise.resolve(defaultGraphJSON)
|
||||
})
|
||||
})
|
||||
|
||||
it('should open workflows adjacent to the active workflow', async () => {
|
||||
await store.openWorkflow(workflowA)
|
||||
store.openWorkflowsInBackground({
|
||||
left: [workflowB.path],
|
||||
right: [workflowC.path]
|
||||
})
|
||||
expect(openWorkflowPaths()).toEqual([
|
||||
workflowB.path,
|
||||
workflowA.path,
|
||||
workflowC.path
|
||||
])
|
||||
})
|
||||
|
||||
it('should not change the active workflow', async () => {
|
||||
await store.openWorkflow(workflowA)
|
||||
store.openWorkflowsInBackground({
|
||||
left: [workflowC.path],
|
||||
right: [workflowB.path]
|
||||
})
|
||||
expect(store.activeWorkflow).not.toBeUndefined()
|
||||
expect(store.activeWorkflow!.path).toBe(workflowA.path)
|
||||
})
|
||||
|
||||
it('should open workflows when none are active', async () => {
|
||||
expect(store.openWorkflows.length).toBe(0)
|
||||
store.openWorkflowsInBackground({
|
||||
left: [workflowA.path],
|
||||
right: [workflowB.path]
|
||||
})
|
||||
expect(openWorkflowPaths()).toEqual([workflowA.path, workflowB.path])
|
||||
})
|
||||
|
||||
it('should not open duplicate workflows', async () => {
|
||||
store.openWorkflowsInBackground({
|
||||
left: [workflowA.path, workflowB.path, workflowA.path],
|
||||
right: [workflowB.path, workflowA.path, workflowB.path]
|
||||
})
|
||||
expect(openWorkflowPaths()).toEqual([workflowA.path, workflowB.path])
|
||||
})
|
||||
|
||||
it('should not open workflow that is already open', async () => {
|
||||
await store.openWorkflow(workflowA)
|
||||
store.openWorkflowsInBackground({
|
||||
left: [workflowA.path]
|
||||
})
|
||||
expect(openWorkflowPaths()).toEqual([workflowA.path])
|
||||
expect(store.activeWorkflow?.path).toBe(workflowA.path)
|
||||
})
|
||||
|
||||
it('should ignore invalid or deleted workflow paths', async () => {
|
||||
await store.openWorkflow(workflowA)
|
||||
store.openWorkflowsInBackground({
|
||||
left: ['workflows/invalid::$-path.json'],
|
||||
right: ['workflows/deleted-since-last-session.json']
|
||||
})
|
||||
expect(openWorkflowPaths()).toEqual([workflowA.path])
|
||||
expect(store.activeWorkflow?.path).toBe(workflowA.path)
|
||||
})
|
||||
|
||||
it('should do nothing when given an empty argument', async () => {
|
||||
await store.openWorkflow(workflowA)
|
||||
|
||||
store.openWorkflowsInBackground({})
|
||||
expect(openWorkflowPaths()).toEqual([workflowA.path])
|
||||
|
||||
store.openWorkflowsInBackground({ left: [], right: [] })
|
||||
expect(openWorkflowPaths()).toEqual([workflowA.path])
|
||||
|
||||
expect(store.activeWorkflow?.path).toBe(workflowA.path)
|
||||
})
|
||||
})
|
||||
|
||||
describe('renameWorkflow', () => {
|
||||
it('should rename workflow and update bookmarks', async () => {
|
||||
const workflow = store.createTemporary('dir/test.json')
|
||||
|
||||
Reference in New Issue
Block a user