From df68b56483b2ddbc0fd6ffeea9766c13f89f0f96 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Fri, 31 Oct 2025 23:47:15 -0700 Subject: [PATCH] Add test --- tests-ui/tests/store/settingStore.test.ts | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests-ui/tests/store/settingStore.test.ts b/tests-ui/tests/store/settingStore.test.ts index 60d7acd1c..f9e649f40 100644 --- a/tests-ui/tests/store/settingStore.test.ts +++ b/tests-ui/tests/store/settingStore.test.ts @@ -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 = {