mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 14:27:40 +00:00
Add test
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
import type { SettingParams } from '@/platform/settings/types'
|
||||
import { api } from '@/scripts/api'
|
||||
import { app } from '@/scripts/app'
|
||||
import { useDialogStore } from '@/stores/dialogStore'
|
||||
|
||||
// Mock the api
|
||||
vi.mock('@/scripts/api', () => ({
|
||||
@@ -17,6 +18,14 @@ vi.mock('@/scripts/api', () => ({
|
||||
}
|
||||
}))
|
||||
|
||||
// Mock telemetry provider
|
||||
const trackSettingChanged = vi.fn()
|
||||
vi.mock('@/platform/telemetry', () => ({
|
||||
useTelemetry: vi.fn(() => ({
|
||||
trackSettingChanged
|
||||
}))
|
||||
}))
|
||||
|
||||
// Mock the app
|
||||
vi.mock('@/scripts/app', () => ({
|
||||
app: {
|
||||
@@ -399,6 +408,53 @@ describe('useSettingStore', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send telemetry when global settings dialog is visible', async () => {
|
||||
const setting: SettingParams = {
|
||||
id: 'main.sub.setting.name',
|
||||
name: 'Telemetry Visible',
|
||||
type: 'text',
|
||||
defaultValue: 'default'
|
||||
}
|
||||
|
||||
store.addSetting(setting)
|
||||
|
||||
const dialogStore = useDialogStore()
|
||||
dialogStore.showDialog({
|
||||
key: 'global-settings',
|
||||
title: 'Settings',
|
||||
component: {}
|
||||
})
|
||||
|
||||
await store.set('main.sub.setting.name', 'newvalue')
|
||||
|
||||
expect(trackSettingChanged).toHaveBeenCalledTimes(1)
|
||||
expect(trackSettingChanged).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
setting_id: 'main.sub.setting.name',
|
||||
input_type: 'text',
|
||||
category: 'main',
|
||||
sub_category: 'sub',
|
||||
previous_value: 'default',
|
||||
new_value: 'newvalue'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('should not send telemetry when global settings dialog is not visible', async () => {
|
||||
const setting: SettingParams = {
|
||||
id: 'main.sub.setting.name',
|
||||
name: 'Telemetry Invisible',
|
||||
type: 'text',
|
||||
defaultValue: 'default'
|
||||
}
|
||||
|
||||
store.addSetting(setting)
|
||||
|
||||
await store.set('main.sub.setting.name', 'newvalue')
|
||||
|
||||
expect(trackSettingChanged).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
describe('object mutation prevention', () => {
|
||||
beforeEach(() => {
|
||||
const setting: SettingParams = {
|
||||
|
||||
Reference in New Issue
Block a user