This commit is contained in:
Benjamin Lu
2025-10-31 23:47:15 -07:00
parent bf03253709
commit df68b56483

View File

@@ -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 = {