mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-04 05:02:17 +00:00
Mock settingStore (#845)
This commit is contained in:
@@ -84,10 +84,6 @@ class NodeBadgeExtension implements ComfyExtension {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
init(app: ComfyApp) {
|
init(app: ComfyApp) {
|
||||||
if (!app.vueAppReady) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const settingStore = useSettingStore()
|
const settingStore = useSettingStore()
|
||||||
this.nodeSourceBadgeMode = computed(
|
this.nodeSourceBadgeMode = computed(
|
||||||
() =>
|
() =>
|
||||||
@@ -119,10 +115,6 @@ class NodeBadgeExtension implements ComfyExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nodeCreated(node: ComfyLGraphNode, app: ComfyApp) {
|
nodeCreated(node: ComfyLGraphNode, app: ComfyApp) {
|
||||||
if (!app.vueAppReady) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
node.badgePosition = BadgePosition.TopRight
|
node.badgePosition = BadgePosition.TopRight
|
||||||
// @ts-expect-error Disable ComfyUI-Manager's badge drawing by setting badge_enabled to true. Remove this when ComfyUI-Manager's badge drawing is removed.
|
// @ts-expect-error Disable ComfyUI-Manager's badge drawing by setting badge_enabled to true. Remove this when ComfyUI-Manager's badge drawing is removed.
|
||||||
node.badge_enabled = true
|
node.badge_enabled = true
|
||||||
|
|||||||
@@ -1895,9 +1895,7 @@ export class ComfyApp {
|
|||||||
|
|
||||||
// Save current workflow automatically
|
// Save current workflow automatically
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const sortNodes =
|
const sortNodes = useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
|
||||||
this.vueAppReady &&
|
|
||||||
useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
|
|
||||||
const workflow = JSON.stringify(this.graph.serialize({ sortNodes }))
|
const workflow = JSON.stringify(this.graph.serialize({ sortNodes }))
|
||||||
localStorage.setItem('workflow', workflow)
|
localStorage.setItem('workflow', workflow)
|
||||||
if (api.clientId) {
|
if (api.clientId) {
|
||||||
@@ -2134,10 +2132,7 @@ export class ComfyApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showMissingNodesError(missingNodeTypes, hasAddedNodes = true) {
|
showMissingNodesError(missingNodeTypes, hasAddedNodes = true) {
|
||||||
if (
|
if (useSettingStore().get('Comfy.Workflow.ShowMissingNodesWarning')) {
|
||||||
this.vueAppReady &&
|
|
||||||
useSettingStore().get('Comfy.Workflow.ShowMissingNodesWarning')
|
|
||||||
) {
|
|
||||||
showLoadWorkflowWarning({
|
showLoadWorkflowWarning({
|
||||||
missingNodeTypes,
|
missingNodeTypes,
|
||||||
hasAddedNodes,
|
hasAddedNodes,
|
||||||
@@ -2151,10 +2146,7 @@ export class ComfyApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showMissingModelsError(missingModels) {
|
showMissingModelsError(missingModels) {
|
||||||
if (
|
if (useSettingStore().get('Comfy.Workflow.ShowMissingModelsWarning')) {
|
||||||
this.vueAppReady &&
|
|
||||||
useSettingStore().get('Comfy.Workflow.ShowMissingModelsWarning')
|
|
||||||
) {
|
|
||||||
showMissingModelsWarning({
|
showMissingModelsWarning({
|
||||||
missingModels,
|
missingModels,
|
||||||
maximizable: true
|
maximizable: true
|
||||||
@@ -2210,10 +2202,7 @@ export class ComfyApp {
|
|||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (useSettingStore().get('Comfy.Validation.Workflows')) {
|
||||||
this.vueAppReady &&
|
|
||||||
useSettingStore().get('Comfy.Validation.Workflows')
|
|
||||||
) {
|
|
||||||
// TODO: Show validation error in a dialog.
|
// TODO: Show validation error in a dialog.
|
||||||
const validatedGraphData = await validateComfyWorkflow(
|
const validatedGraphData = await validateComfyWorkflow(
|
||||||
graphData,
|
graphData,
|
||||||
@@ -2416,9 +2405,8 @@ export class ComfyApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortNodes =
|
const sortNodes = useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
|
||||||
this.vueAppReady &&
|
|
||||||
useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
|
|
||||||
const workflow = graph.serialize({ sortNodes })
|
const workflow = graph.serialize({ sortNodes })
|
||||||
const output = {}
|
const output = {}
|
||||||
// Process nodes in order of execution
|
// Process nodes in order of execution
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { APIConfig, mockApi } from './setup'
|
import { APIConfig, mockApi, mockSettingStore } from './setup'
|
||||||
import { Ez, EzGraph, EzNameSpace } from './ezgraph'
|
import { Ez, EzGraph, EzNameSpace } from './ezgraph'
|
||||||
import lg from './litegraph'
|
import lg from './litegraph'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
@@ -40,7 +40,11 @@ export async function start(config: StartConfig = {}): Promise<StartResult> {
|
|||||||
document.body.innerHTML = html.toString()
|
document.body.innerHTML = html.toString()
|
||||||
|
|
||||||
mockApi(config)
|
mockApi(config)
|
||||||
|
mockSettingStore()
|
||||||
const { app } = await import('../../src/scripts/app')
|
const { app } = await import('../../src/scripts/app')
|
||||||
|
const { useSettingStore } = await import('../../src/stores/settingStore')
|
||||||
|
useSettingStore().addSettings(app.ui.settings)
|
||||||
|
|
||||||
const { LiteGraph, LGraphCanvas } = await import('@comfyorg/litegraph')
|
const { LiteGraph, LGraphCanvas } = await import('@comfyorg/litegraph')
|
||||||
config.preSetup?.(app)
|
config.preSetup?.(app)
|
||||||
const canvasEl = document.createElement('canvas')
|
const canvasEl = document.createElement('canvas')
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { ComfySettingsDialog } from '@/scripts/ui/settings'
|
||||||
|
import type { ComfyApp } from '@/scripts/app'
|
||||||
import '../../src/scripts/api'
|
import '../../src/scripts/api'
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
@@ -97,3 +99,28 @@ export function mockApi(config: APIConfig = {}) {
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const mockSettingStore = () => {
|
||||||
|
let app: ComfyApp | null = null
|
||||||
|
|
||||||
|
const mockedSettingStore = {
|
||||||
|
addSettings(settings: ComfySettingsDialog) {
|
||||||
|
app = settings.app
|
||||||
|
},
|
||||||
|
|
||||||
|
set(key: string, value: any) {
|
||||||
|
app?.ui.settings.setSettingValue(key, value)
|
||||||
|
},
|
||||||
|
|
||||||
|
get(key: string) {
|
||||||
|
return (
|
||||||
|
app?.ui.settings.getSettingValue(key) ??
|
||||||
|
app?.ui.settings.getSettingDefaultValue(key)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jest.mock('@/stores/settingStore', () => ({
|
||||||
|
useSettingStore: jest.fn(() => mockedSettingStore)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user