-
Notifications
You must be signed in to change notification settings - Fork 408
feat(telemetry): track settings changes #6504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+149
−4
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f2952e9
Implement setting telemetry
benceruleanlu 5d7321e
chore(settings): clarify variable names in telemetry tracking and add…
benceruleanlu 75857b3
test(store): move setting store tests to tests-ui/tests/store/setting…
benceruleanlu bf03253
restore settingStore.test.ts
benceruleanlu df68b56
Add test
benceruleanlu c7eb80b
Remove input type, category, and subcategory telemetry tracking
benceruleanlu 9fd2c25
Move from setting store to setting item component
benceruleanlu 7a4dea8
Merge remote-tracking branch 'origin/main' into chief-pig
benceruleanlu 7473093
Fix tests
benceruleanlu 434ada4
Fix normalization bug
benceruleanlu 18b3995
Merge branch 'main' into chief-pig
benceruleanlu 0c02fd0
typing
benceruleanlu b8772cb
Fix syntax error
benceruleanlu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
tests-ui/tests/platform/settings/components/SettingItem.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { flushPromises, shallowMount } from '@vue/test-utils' | ||
| import { describe, expect, it, vi, beforeEach } from 'vitest' | ||
|
|
||
| import SettingItem from '@/platform/settings/components/SettingItem.vue' | ||
| import type { SettingParams } from '@/platform/settings/types' | ||
| import { i18n } from '@/i18n' | ||
|
|
||
| /** | ||
| * Verifies that SettingItem emits telemetry when its value changes | ||
| * and suppresses telemetry when the value remains the same. | ||
| */ | ||
| const trackSettingChanged = vi.fn() | ||
| vi.mock('@/platform/telemetry', () => ({ | ||
| useTelemetry: vi.fn(() => ({ | ||
| trackSettingChanged | ||
| })) | ||
| })) | ||
|
|
||
| const mockGet = vi.fn() | ||
| const mockSet = vi.fn() | ||
| vi.mock('@/platform/settings/settingStore', () => ({ | ||
| useSettingStore: () => ({ | ||
| get: mockGet, | ||
| set: mockSet | ||
| }) | ||
| })) | ||
|
|
||
| /** | ||
| * Minimal stub for FormItem that allows emitting `update:form-value`. | ||
| */ | ||
| const FormItemUpdateStub = { | ||
| template: '<div />', | ||
| emits: ['update:form-value'], | ||
| props: ['id', 'item', 'formValue'] | ||
| } | ||
|
|
||
| describe('SettingItem (telemetry UI tracking)', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| const mountComponent = (setting: SettingParams) => { | ||
| return shallowMount(SettingItem, { | ||
| global: { | ||
| plugins: [i18n], | ||
| stubs: { | ||
| FormItem: FormItemUpdateStub, | ||
| Tag: true | ||
| } | ||
| }, | ||
| props: { | ||
| setting | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| it('tracks telemetry when value changes via UI (uses normalized value)', async () => { | ||
| const settingParams: SettingParams = { | ||
| id: 'main.sub.setting.name', | ||
| name: 'Telemetry Visible', | ||
| type: 'text', | ||
| defaultValue: 'default' | ||
| } | ||
|
|
||
| mockGet.mockReturnValueOnce('default').mockReturnValueOnce('normalized') | ||
| mockSet.mockResolvedValue(undefined) | ||
|
|
||
| const wrapper = mountComponent(settingParams) | ||
|
|
||
| const newValue = 'newvalue' | ||
| const formItem = wrapper.findComponent(FormItemUpdateStub) | ||
| formItem.vm.$emit('update:form-value', newValue) | ||
|
|
||
| await flushPromises() | ||
|
|
||
| expect(trackSettingChanged).toHaveBeenCalledTimes(1) | ||
| expect(trackSettingChanged).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| setting_id: 'main.sub.setting.name', | ||
| previous_value: 'default', | ||
| new_value: 'normalized' | ||
| }) | ||
| ) | ||
| }) | ||
|
|
||
| it('does not track telemetry when normalized value does not change', async () => { | ||
| const settingParams: SettingParams = { | ||
| id: 'main.sub.setting.name', | ||
| name: 'Telemetry Visible', | ||
| type: 'text', | ||
| defaultValue: 'same' | ||
| } | ||
|
|
||
| mockGet.mockReturnValueOnce('same').mockReturnValueOnce('same') | ||
| mockSet.mockResolvedValue(undefined) | ||
|
|
||
| const wrapper = mountComponent(settingParams) | ||
|
|
||
| const unchangedValue = 'same' | ||
| const formItem = wrapper.findComponent(FormItemUpdateStub) | ||
| formItem.vm.$emit('update:form-value', unchangedValue) | ||
|
|
||
| await flushPromises() | ||
|
|
||
| expect(trackSettingChanged).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.