mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-13 00:50:01 +00:00
Mock settingStore (#845)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { APIConfig, mockApi } from './setup'
|
||||
import { APIConfig, mockApi, mockSettingStore } from './setup'
|
||||
import { Ez, EzGraph, EzNameSpace } from './ezgraph'
|
||||
import lg from './litegraph'
|
||||
import fs from 'fs'
|
||||
@@ -40,7 +40,11 @@ export async function start(config: StartConfig = {}): Promise<StartResult> {
|
||||
document.body.innerHTML = html.toString()
|
||||
|
||||
mockApi(config)
|
||||
mockSettingStore()
|
||||
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')
|
||||
config.preSetup?.(app)
|
||||
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'
|
||||
|
||||
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