mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-26 01:09:46 +00:00
test(store): move setting store tests to tests-ui/tests/store/settingStore.test.ts
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
import { setActivePinia, createPinia } from 'pinia'
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
trackSettingChanged: vi.fn(),
|
||||
storeSetting: vi.fn().mockResolvedValue(undefined)
|
||||
}))
|
||||
|
||||
let isSettingsDialogOpen = false
|
||||
|
||||
vi.mock('@/platform/telemetry', () => {
|
||||
return {
|
||||
useTelemetry: () => ({
|
||||
trackSettingChanged: hoisted.trackSettingChanged
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('@/stores/dialogStore', () => {
|
||||
return {
|
||||
useDialogStore: () => ({
|
||||
isDialogOpen: (key: string) =>
|
||||
isSettingsDialogOpen && key === 'global-settings'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('@/scripts/api', () => {
|
||||
return {
|
||||
api: {
|
||||
storeSetting: hoisted.storeSetting,
|
||||
getSettings: vi.fn().mockResolvedValue({})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('@/scripts/app', () => {
|
||||
return {
|
||||
app: {
|
||||
ui: {
|
||||
settings: {
|
||||
dispatchChange: vi.fn()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
import { useSettingStore } from '@/platform/settings/settingStore'
|
||||
|
||||
describe('useSettingStore telemetry', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
hoisted.trackSettingChanged.mockReset()
|
||||
hoisted.storeSetting.mockReset().mockResolvedValue(undefined)
|
||||
isSettingsDialogOpen = false
|
||||
})
|
||||
|
||||
it('tracks telemetry when settings dialog is open', async () => {
|
||||
isSettingsDialogOpen = true
|
||||
|
||||
const store = useSettingStore()
|
||||
store.addSetting({
|
||||
id: 'main.sub.setting.name',
|
||||
name: 'Test Setting',
|
||||
type: 'text',
|
||||
defaultValue: 'old'
|
||||
})
|
||||
|
||||
await store.set('main.sub.setting.name', 'new')
|
||||
|
||||
expect(hoisted.trackSettingChanged).toHaveBeenCalledTimes(1)
|
||||
expect(hoisted.trackSettingChanged).toHaveBeenCalledWith({
|
||||
setting_id: 'main.sub.setting.name',
|
||||
input_type: 'text',
|
||||
category: 'main',
|
||||
sub_category: 'sub',
|
||||
previous_value: 'old',
|
||||
new_value: 'new'
|
||||
})
|
||||
})
|
||||
|
||||
it('does not track telemetry when settings dialog is closed', async () => {
|
||||
isSettingsDialogOpen = false
|
||||
|
||||
const store = useSettingStore()
|
||||
store.addSetting({
|
||||
id: 'single.setting',
|
||||
name: 'Another Setting',
|
||||
type: 'text',
|
||||
defaultValue: 'x'
|
||||
})
|
||||
|
||||
await store.set('single.setting', 'y')
|
||||
|
||||
expect(hoisted.trackSettingChanged).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user