From 8cfc86a266deb36dea4f1cb40faeccab1b7fe92d Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 15 Sep 2026 00:51:29 +0000 Subject: [PATCH 1/6] test: share typed telemetry mocks across 61 suites --- src/components/TopMenuSection.test.ts | 15 ++++++++---- .../builder/builderViewOptions.test.ts | 11 ++++++--- src/components/builder/useBuilderSave.test.ts | 17 +++++++++----- .../common/WorkflowActionsDropdown.test.ts | 11 ++++++--- .../TopUpCreditsDialogContentLegacy.test.ts | 17 +++++++++----- .../content/setting/CreditsPanel.test.ts | 11 ++++++--- .../CancelSubscriptionDialogContent.test.ts | 15 ++++++++---- .../graph/selectionToolbox/InfoButton.test.ts | 15 ++++++++---- .../helpcenter/HelpCenterMenuContent.test.ts | 19 +++++++++------ .../rightSidePanel/RightSidePanel.test.ts | 4 ++-- .../errors/ErrorNodeCard.test.ts | 18 ++++++++++----- .../parameters/SectionWidgets.test.ts | 15 ++++++++---- .../parameters/WidgetActions.test.ts | 15 ++++++++---- .../rightSidePanelTabTelemetry.test.ts | 15 ++++++++---- src/components/sidebar/SideToolbar.test.ts | 11 ++++++--- .../topbar/CurrentUserPopoverLegacy.test.ts | 16 +++++++++---- src/composables/auth/useAuthActions.test.ts | 16 +++++++++---- .../canvas/visibleCanvasViewport.test.ts | 4 ++-- src/composables/useCoreCommands.test.ts | 20 ++++++++++------ src/composables/useTemplateFiltering.test.ts | 18 ++++++++++----- src/platform/auth/unified/remintRetry.test.ts | 15 ++++++++---- .../cloud/onboarding/CloudSignupView.test.ts | 4 ++-- .../components/PricingTable.test.ts | 17 +++++++++----- .../composables/useSubscriptionDialog.test.ts | 11 ++++++--- .../composables/useTopUpUrlLoader.test.ts | 15 ++++++++---- .../launchCancellationFlow.test.ts | 15 ++++++++---- .../teamSubscriptionCheckoutUtil.test.ts | 17 +++++++++----- ...onboardingTourStore.registeredTour.test.ts | 11 ++++++--- .../onboarding/onboardingTourStore.test.ts | 11 ++++++--- .../composables/useSettingsDialog.test.ts | 4 ++-- src/platform/settings/settingStore.test.ts | 16 +++++++++---- src/platform/support/feedbackDialog.test.ts | 10 +++++--- src/platform/telemetry/__mocks__/telemetry.ts | 10 ++++++++ .../useSearchQueryTracking.test.ts | 11 ++++++--- .../workflowService.insertWorkflow.test.ts | 19 +++++++++------ .../core/services/workflowService.test.ts | 19 +++++++++------ .../ShareWorkflowDialogContent.test.ts | 15 ++++++++---- .../useSharedWorkflowUrlLoader.test.ts | 15 ++++++++---- .../CurrentUserPopoverWorkspace.test.ts | 4 ++-- .../components/InviteMembersForm.test.ts | 17 +++++++++----- ...TopUpCreditsDialogContentWorkspace.test.ts | 19 +++++++++------ .../dialogs/InviteMemberDialogContent.test.ts | 17 +++++++++----- .../useDowngradeToPersonal.test.ts | 15 ++++++++---- .../composables/useResubscribe.test.ts | 17 +++++++++----- .../useSubscriptionCheckout.test.ts | 23 +++++++++++-------- .../composables/useWorkspaceBilling.test.ts | 15 ++++++++---- .../stores/billingOperationStore.test.ts | 17 +++++++++----- .../workspace/stores/useWorkspaceAuth.test.ts | 15 ++++++++---- .../nudge/FirstRunTourNudge.test.ts | 11 ++++++--- .../vueNodes/components/ImagePreview.test.ts | 15 ++++++++---- src/services/dialogService.downgrade.test.ts | 4 ++-- src/services/dialogService.renderer.test.ts | 4 ++-- .../dialogService.topUpCredits.test.ts | 4 ++-- .../__tests__/authTokenPriority.test.ts | 10 +++++--- .../apiKeyAuthStore.integration.test.ts | 10 +++++--- src/stores/authStore.test.ts | 15 ++++++++---- src/stores/executionStore.test.ts | 21 ++++++++++------- src/views/GraphView.test.ts | 4 ++-- .../components/agent/DockedAgentPanel.test.ts | 4 ++-- .../agent/dockedAgentPanelLoadFailure.test.ts | 4 ++-- .../composables/useAgentDockMount.test.ts | 4 ++-- .../stores/agent/agentPanelStoreId.test.ts | 4 ++-- 62 files changed, 522 insertions(+), 269 deletions(-) create mode 100644 src/platform/telemetry/__mocks__/telemetry.ts diff --git a/src/components/TopMenuSection.test.ts b/src/components/TopMenuSection.test.ts index f17b98c8fd1..6559a6e8859 100644 --- a/src/components/TopMenuSection.test.ts +++ b/src/components/TopMenuSection.test.ts @@ -82,11 +82,16 @@ vi.mock(import('@/scripts/app'), () => ({ const mockTrackUiButtonClicked = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackUiButtonClicked: mockTrackUiButtonClicked + }) + } +}) type WrapperOptions = { pinia?: Pinia diff --git a/src/components/builder/builderViewOptions.test.ts b/src/components/builder/builderViewOptions.test.ts index 6b0e5807f49..cd42df457cc 100644 --- a/src/components/builder/builderViewOptions.test.ts +++ b/src/components/builder/builderViewOptions.test.ts @@ -9,9 +9,14 @@ const mockTrackDefaultViewSet = vi.hoisted(() => vi.fn()) vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackDefaultViewSet: mockTrackDefaultViewSet }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackDefaultViewSet: mockTrackDefaultViewSet }) + } +}) vi.mock(import('@/scripts/app'), () => { const rootGraph = { extra: {} } diff --git a/src/components/builder/useBuilderSave.test.ts b/src/components/builder/useBuilderSave.test.ts index 669f45f33a5..33efd31d874 100644 --- a/src/components/builder/useBuilderSave.test.ts +++ b/src/components/builder/useBuilderSave.test.ts @@ -38,12 +38,17 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ useErrorHandling: () => ({ toastErrorHandler: mockToastErrorHandler }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackEnterLinear: mockTrackEnterLinear, - trackDefaultViewSet: mockTrackDefaultViewSet - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackEnterLinear: mockTrackEnterLinear, + trackDefaultViewSet: mockTrackDefaultViewSet + }) + } +}) vi.mock( import('@/platform/workflow/core/services/workflowService'), diff --git a/src/components/common/WorkflowActionsDropdown.test.ts b/src/components/common/WorkflowActionsDropdown.test.ts index 38409dfc746..2b9db8bd906 100644 --- a/src/components/common/WorkflowActionsDropdown.test.ts +++ b/src/components/common/WorkflowActionsDropdown.test.ts @@ -26,9 +26,14 @@ const spies = vi.hoisted(() => ({ markAsSeen: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackUiButtonClicked: spies.trackUiButtonClicked }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackUiButtonClicked: spies.trackUiButtonClicked }) + } +}) vi.mock(import('@/composables/useWorkflowActionsMenu'), async () => { const { ref } = await import('vue') diff --git a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts index 340316bea41..edc22324d87 100644 --- a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts +++ b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts @@ -48,12 +48,17 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, + trackBillingEvent: mockTrackBillingEvent + }) + } +}) const mockClearPendingTopup = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ diff --git a/src/components/dialog/content/setting/CreditsPanel.test.ts b/src/components/dialog/content/setting/CreditsPanel.test.ts index 10f125ec936..4aac326662f 100644 --- a/src/components/dialog/content/setting/CreditsPanel.test.ts +++ b/src/components/dialog/content/setting/CreditsPanel.test.ts @@ -47,9 +47,14 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackHelpResourceClicked: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackHelpResourceClicked: vi.fn() }) + } +}) vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ diff --git a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts index 8962e9d9bf9..ee27be399c1 100644 --- a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts +++ b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts @@ -101,11 +101,16 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackSubscriptionCancellation: mockTrackCancellation - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackSubscriptionCancellation: mockTrackCancellation + }) + } +}) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports diff --git a/src/components/graph/selectionToolbox/InfoButton.test.ts b/src/components/graph/selectionToolbox/InfoButton.test.ts index 282c77e5fb2..9929bb0b8ce 100644 --- a/src/components/graph/selectionToolbox/InfoButton.test.ts +++ b/src/components/graph/selectionToolbox/InfoButton.test.ts @@ -19,11 +19,16 @@ vi.mock(import('@/composables/graph/useSelectionState'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: trackUiButtonClickedMock - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackUiButtonClicked: trackUiButtonClickedMock + }) + } +}) describe('InfoButton', () => { const i18n = createI18n({ diff --git a/src/components/helpcenter/HelpCenterMenuContent.test.ts b/src/components/helpcenter/HelpCenterMenuContent.test.ts index 1c31441c69e..0ddc14cea3d 100644 --- a/src/components/helpcenter/HelpCenterMenuContent.test.ts +++ b/src/components/helpcenter/HelpCenterMenuContent.test.ts @@ -44,13 +44,18 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackHelpResourceClicked: vi.fn(), - trackHelpCenterOpened: vi.fn(), - trackHelpCenterClosed: vi.fn() - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackHelpResourceClicked: vi.fn(), + trackHelpCenterOpened: vi.fn(), + trackHelpCenterClosed: vi.fn() + }) + } +}) vi.mock(import('@/utils/envUtil'), () => ({ electronAPI: () => null diff --git a/src/components/rightSidePanel/RightSidePanel.test.ts b/src/components/rightSidePanel/RightSidePanel.test.ts index b7bd926953e..7e419a1d521 100644 --- a/src/components/rightSidePanel/RightSidePanel.test.ts +++ b/src/components/rightSidePanel/RightSidePanel.test.ts @@ -32,8 +32,8 @@ vi.mock(import('@/composables/graph/useGraphHierarchy'), () => ({ useGraphHierarchy: () => ({ findParentGroup: vi.fn(() => null) }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) function createPanelI18n() { diff --git a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts index 75889bc2426..23a8b52f93f 100644 --- a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts +++ b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts @@ -41,12 +41,18 @@ vi.mock(import('@/utils/errorReportUtil'), () => ({ const mockTrackHelpResourceClicked = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackUiButtonClicked: vi.fn(), - trackHelpResourceClicked: mockTrackHelpResourceClicked - })) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: vi.fn(() => + createTelemetryMock({ + trackUiButtonClicked: vi.fn(), + trackHelpResourceClicked: mockTrackHelpResourceClicked + }) + ) + } +}) vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: vi.fn(() => ({ diff --git a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts index 423c880f4c4..1cc1a886458 100644 --- a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts +++ b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts @@ -31,11 +31,16 @@ const setDirty = vi.fn() const getNodeById = vi.fn() const animateToBounds = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackUiButtonClicked: mockTrackUiButtonClicked + }) + } +}) const WidgetItemStub = defineComponent({ inheritAttrs: false, diff --git a/src/components/rightSidePanel/parameters/WidgetActions.test.ts b/src/components/rightSidePanel/parameters/WidgetActions.test.ts index a67b935afbd..0620f893e37 100644 --- a/src/components/rightSidePanel/parameters/WidgetActions.test.ts +++ b/src/components/rightSidePanel/parameters/WidgetActions.test.ts @@ -26,11 +26,16 @@ vi.mock(import('@/core/graph/subgraph/promotionUtils'), () => ({ promoteWidget: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackWidgetFavoriteToggled: mockTrackWidgetFavoriteToggled - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackWidgetFavoriteToggled: mockTrackWidgetFavoriteToggled + }) + } +}) vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ diff --git a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts index 24f7fff5df9..c9448e7ad2c 100644 --- a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts +++ b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts @@ -4,11 +4,16 @@ const { mockTrackUiButtonClicked } = vi.hoisted(() => ({ mockTrackUiButtonClicked: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackUiButtonClicked: mockTrackUiButtonClicked + }) + } +}) import { trackRightSidePanelTabOpened } from './rightSidePanelTabTelemetry' diff --git a/src/components/sidebar/SideToolbar.test.ts b/src/components/sidebar/SideToolbar.test.ts index d381a73e6f0..8f9f1e0a786 100644 --- a/src/components/sidebar/SideToolbar.test.ts +++ b/src/components/sidebar/SideToolbar.test.ts @@ -39,9 +39,14 @@ vi.mock(import('@/platform/distribution/types'), () => ({ isNightly: false })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackUiButtonClicked: spies.trackUiButtonClicked }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackUiButtonClicked: spies.trackUiButtonClicked }) + } +}) const i18n = createI18n({ legacy: false, diff --git a/src/components/topbar/CurrentUserPopoverLegacy.test.ts b/src/components/topbar/CurrentUserPopoverLegacy.test.ts index 3c5f82e6675..6dc6c4d3b83 100644 --- a/src/components/topbar/CurrentUserPopoverLegacy.test.ts +++ b/src/components/topbar/CurrentUserPopoverLegacy.test.ts @@ -119,11 +119,17 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ })) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackAddApiCreditButtonClicked: vi.fn() - })) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: vi.fn(() => + createTelemetryMock({ + trackAddApiCreditButtonClicked: vi.fn() + }) + ) + } +}) describe('CurrentUserPopoverLegacy', () => { beforeEach(() => { diff --git a/src/composables/auth/useAuthActions.test.ts b/src/composables/auth/useAuthActions.test.ts index 141d2546a28..7b2c3af7014 100644 --- a/src/composables/auth/useAuthActions.test.ts +++ b/src/composables/auth/useAuthActions.test.ts @@ -77,11 +77,17 @@ vi.mock(import('@/platform/distribution/types'), () => ({ } })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackAuthFailed: mockTrackAuthFailed - })) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: vi.fn(() => + createTelemetryMock({ + trackAuthFailed: mockTrackAuthFailed + }) + ) + } +}) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ startPendingTopup: mockStartPendingTopup }) diff --git a/src/composables/canvas/visibleCanvasViewport.test.ts b/src/composables/canvas/visibleCanvasViewport.test.ts index 00d331f95f9..521ec503c18 100644 --- a/src/composables/canvas/visibleCanvasViewport.test.ts +++ b/src/composables/canvas/visibleCanvasViewport.test.ts @@ -5,8 +5,8 @@ import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/ag import { visibleCanvasViewport } from './visibleCanvasViewport' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) describe('visibleCanvasViewport', () => { diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index c46da96a7ae..18aa452b189 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -117,13 +117,19 @@ vi.mock(import('@/services/litegraphService'), () => ({ })) const mockTrackHelpResourceClicked = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackHelpResourceClicked: mockTrackHelpResourceClicked, - trackRunButton: vi.fn(), - trackWorkflowExecution: vi.fn() - })) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: vi.fn(() => + createTelemetryMock({ + trackHelpResourceClicked: mockTrackHelpResourceClicked, + trackRunButton: vi.fn(), + trackWorkflowExecution: vi.fn() + }) + ) + } +}) const mockShowAbout = vi.hoisted(() => vi.fn()) const mockShowSettings = vi.hoisted(() => vi.fn()) diff --git a/src/composables/useTemplateFiltering.test.ts b/src/composables/useTemplateFiltering.test.ts index 6a99235d5a6..62a2a80177b 100644 --- a/src/composables/useTemplateFiltering.test.ts +++ b/src/composables/useTemplateFiltering.test.ts @@ -18,12 +18,18 @@ let defaultRankingStore: ReturnType let mockSystemStatsStore: ReturnType const trackTemplateFilterChanged = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackTemplateFilterChanged, - trackSearchQuery: vi.fn() - })) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: vi.fn(() => + createTelemetryMock({ + trackTemplateFilterChanged, + trackSearchQuery: vi.fn() + }) + ) + } +}) vi.mock( import('@/platform/telemetry/searchQuery/useSearchQueryTracking'), diff --git a/src/platform/auth/unified/remintRetry.test.ts b/src/platform/auth/unified/remintRetry.test.ts index 33c76045aa1..c461734e24d 100644 --- a/src/platform/auth/unified/remintRetry.test.ts +++ b/src/platform/auth/unified/remintRetry.test.ts @@ -14,11 +14,16 @@ const { mockRemint, mockTrackUnifiedAuthRetry, flagState } = vi.hoisted(() => ({ flagState: { unifiedCloudAuthEnabled: true } })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUnifiedAuthRetry: mockTrackUnifiedAuthRetry - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackUnifiedAuthRetry: mockTrackUnifiedAuthRetry + }) + } +}) vi.mock(import('@/composables/useFeatureFlags'), () => ({ useFeatureFlags: () => ({ diff --git a/src/platform/cloud/onboarding/CloudSignupView.test.ts b/src/platform/cloud/onboarding/CloudSignupView.test.ts index 632a31bd452..12f03ab24e6 100644 --- a/src/platform/cloud/onboarding/CloudSignupView.test.ts +++ b/src/platform/cloud/onboarding/CloudSignupView.test.ts @@ -23,8 +23,8 @@ vi.mock( vi.mock(import('@comfyorg/account/webviewDetection'), () => ({ isEmbeddedWebView: () => false })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) const inChina = vi.hoisted(() => ({ diff --git a/src/platform/cloud/subscription/components/PricingTable.test.ts b/src/platform/cloud/subscription/components/PricingTable.test.ts index 1ab8e8052b6..f79cc7572cb 100644 --- a/src/platform/cloud/subscription/components/PricingTable.test.ts +++ b/src/platform/cloud/subscription/components/PricingTable.test.ts @@ -114,12 +114,17 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBeginCheckout: mockTrackBeginCheckout, - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackBeginCheckout: mockTrackBeginCheckout, + trackBillingEvent: mockTrackBillingEvent + }) + } +}) vi.mock( import('@/platform/telemetry/utils/checkoutAttribution'), diff --git a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts index dca4859dfe9..c447694379a 100644 --- a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts +++ b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts @@ -105,9 +105,14 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackSubscription: mockTrackSubscription }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackSubscription: mockTrackSubscription }) + } +}) vi.mock( import('@/platform/workspace/composables/useWorkspaceUI'), diff --git a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts index 2fcc1f261b0..a34dcb50f9e 100644 --- a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts +++ b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts @@ -55,11 +55,16 @@ vi.mock( const mockTrackAddApiCreditButtonClicked = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackAddApiCreditButtonClicked: mockTrackAddApiCreditButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackAddApiCreditButtonClicked: mockTrackAddApiCreditButtonClicked + }) + } +}) describe('useTopUpUrlLoader', () => { beforeEach(() => { diff --git a/src/platform/cloud/subscription/launchCancellationFlow.test.ts b/src/platform/cloud/subscription/launchCancellationFlow.test.ts index ea3446b9374..471b0dcfed3 100644 --- a/src/platform/cloud/subscription/launchCancellationFlow.test.ts +++ b/src/platform/cloud/subscription/launchCancellationFlow.test.ts @@ -39,11 +39,16 @@ vi.mock(import('@/platform/cloud/churnkey/churnkeyClient'), () => ({ prepareChurnkey: mocks.prepare })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackSubscriptionCancellation: mocks.trackCancellation - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackSubscriptionCancellation: mocks.trackCancellation + }) + } +}) import { launchCancellationFlow } from './launchCancellationFlow' diff --git a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts index 572d2b1f0cf..e421918a33a 100644 --- a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts +++ b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts @@ -34,12 +34,17 @@ vi.mock(import('@/platform/workspace/api/workspaceApi'), () => ({ } } })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBeginCheckout: mockTrackBeginCheckout, - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackBeginCheckout: mockTrackBeginCheckout, + trackBillingEvent: mockTrackBillingEvent + }) + } +}) import { performTeamSubscriptionCheckout } from './teamSubscriptionCheckoutUtil' diff --git a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts index 74abcf2eb9c..f65334b8b41 100644 --- a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts +++ b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts @@ -12,9 +12,14 @@ import type { SpotlightStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' const telemetry = vi.hoisted(() => ({ track: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackOnboardingTour: telemetry.track }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackOnboardingTour: telemetry.track }) + } +}) const appModeMock = vi.hoisted(() => ({ mode: null as Ref | null })) vi.mock(import('@/composables/useAppMode'), async () => { diff --git a/src/platform/onboarding/onboardingTourStore.test.ts b/src/platform/onboarding/onboardingTourStore.test.ts index 158ae9d2c5e..4a66d6c699f 100644 --- a/src/platform/onboarding/onboardingTourStore.test.ts +++ b/src/platform/onboarding/onboardingTourStore.test.ts @@ -19,9 +19,14 @@ import type { CoachId, CoachStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' const telemetry = vi.hoisted(() => ({ track: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackOnboardingTour: telemetry.track }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackOnboardingTour: telemetry.track }) + } +}) const appModeMock = vi.hoisted((): { mode: Ref | null } => ({ mode: null diff --git a/src/platform/settings/composables/useSettingsDialog.test.ts b/src/platform/settings/composables/useSettingsDialog.test.ts index 39016f9c5d4..86035728f47 100644 --- a/src/platform/settings/composables/useSettingsDialog.test.ts +++ b/src/platform/settings/composables/useSettingsDialog.test.ts @@ -20,8 +20,8 @@ vi.mock(import('@/i18n'), () => ({ t: (k: string) => k })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index 8c637cbb2ff..b4b0fc5d005 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -13,11 +13,17 @@ const { trackSettingChanged } = vi.hoisted(() => ({ trackSettingChanged: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackSettingChanged - })) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: vi.fn(() => + createTelemetryMock({ + trackSettingChanged + }) + ) + } +}) // Mock the api vi.mock(import('@/scripts/api'), () => ({ diff --git a/src/platform/support/feedbackDialog.test.ts b/src/platform/support/feedbackDialog.test.ts index 10dbb33c4c6..c06c498f818 100644 --- a/src/platform/support/feedbackDialog.test.ts +++ b/src/platform/support/feedbackDialog.test.ts @@ -15,9 +15,13 @@ vi.mock(import('@/platform/surveys/openTypeformDialog'), () => ({ })) const trackUiButtonClicked = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ trackUiButtonClicked })) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: vi.fn(() => createTelemetryMock({ trackUiButtonClicked })) + } +}) const userEmail = vi.hoisted((): { value: string | undefined } => ({ value: undefined diff --git a/src/platform/telemetry/__mocks__/telemetry.ts b/src/platform/telemetry/__mocks__/telemetry.ts new file mode 100644 index 00000000000..382cb8a8dfb --- /dev/null +++ b/src/platform/telemetry/__mocks__/telemetry.ts @@ -0,0 +1,10 @@ +import { vi } from 'vitest' + +import { TelemetryRegistry } from '../TelemetryRegistry' +import type { TelemetryDispatcher, TelemetryProvider } from '../types' + +export function createTelemetryMock( + overrides: TelemetryProvider = {} +): TelemetryDispatcher { + return Object.assign(vi.mockObject(new TelemetryRegistry()), overrides) +} diff --git a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts index 8a4cae2cafb..2ebb86b6d0d 100644 --- a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts +++ b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts @@ -6,9 +6,14 @@ const hoisted = vi.hoisted(() => ({ trackSearchQuery: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackSearchQuery: hoisted.trackSearchQuery }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackSearchQuery: hoisted.trackSearchQuery }) + } +}) import { useSearchQueryTracking } from './useSearchQueryTracking' diff --git a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts index 4e13f9b3da7..4cf158b4a67 100644 --- a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts +++ b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts @@ -51,13 +51,18 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackDefaultViewSet: vi.fn(), - trackWorkflowSaved: vi.fn(), - trackEnterLinear: vi.fn() - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackDefaultViewSet: vi.fn(), + trackWorkflowSaved: vi.fn(), + trackEnterLinear: vi.fn() + }) + } +}) const PROBE_NODE_TYPE = 'test/insert-workflow-probe' diff --git a/src/platform/workflow/core/services/workflowService.test.ts b/src/platform/workflow/core/services/workflowService.test.ts index 2fe1d295ffa..7e1c40c4a2d 100644 --- a/src/platform/workflow/core/services/workflowService.test.ts +++ b/src/platform/workflow/core/services/workflowService.test.ts @@ -131,13 +131,18 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: reportErrorMock })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackDefaultViewSet: vi.fn(), - trackWorkflowSaved: mockTrackWorkflowSaved, - trackEnterLinear: vi.fn() - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackDefaultViewSet: vi.fn(), + trackWorkflowSaved: mockTrackWorkflowSaved, + trackEnterLinear: vi.fn() + }) + } +}) function createWorkflow( warnings: PendingWarnings | null = null, diff --git a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts index 1433b1c0bc4..194e444c603 100644 --- a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts +++ b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts @@ -9,11 +9,16 @@ import ShareWorkflowDialogContent from '@/platform/workflow/sharing/components/S const mockTrackShareFlow = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackShareFlow: mockTrackShareFlow - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackShareFlow: mockTrackShareFlow + }) + } +}) const mockToast = vi.hoisted(() => ({ add: vi.fn() })) diff --git a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts index 481d04399f6..651edf4f84c 100644 --- a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts +++ b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts @@ -49,11 +49,16 @@ vi.mock(import('@/composables/useAppMode'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackShareLinkOpened: mockTrackShareLinkOpened - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackShareLinkOpened: mockTrackShareLinkOpened + }) + } +}) vi.mock( import('@/platform/workflow/sharing/services/workflowShareService'), diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts index d11ff770641..9e6db502bad 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts @@ -127,8 +127,8 @@ vi.mock(import('@/services/dialogService'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) vi.mock(import('@/composables/useExternalLink'), () => ({ diff --git a/src/platform/workspace/components/InviteMembersForm.test.ts b/src/platform/workspace/components/InviteMembersForm.test.ts index f33b1a8669a..acb306cecc7 100644 --- a/src/platform/workspace/components/InviteMembersForm.test.ts +++ b/src/platform/workspace/components/InviteMembersForm.test.ts @@ -33,12 +33,17 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackWorkspaceInviteSent: mockTrackInviteSent, - trackWorkspaceInviteFailed: mockTrackInviteFailed - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackWorkspaceInviteSent: mockTrackInviteSent, + trackWorkspaceInviteFailed: mockTrackInviteFailed + }) + } +}) const i18n = createI18n({ legacy: false, diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index d5d2df5eab6..0401d2d5a0a 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -96,13 +96,18 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, - trackBillingEvent: mockTrackBillingEvent, - trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, + trackBillingEvent: mockTrackBillingEvent, + trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent + }) + } +}) vi.mock(import('firebase/auth'), { spy: true }) diff --git a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts index 838d4183660..269e7ec0a80 100644 --- a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts +++ b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts @@ -36,12 +36,17 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackWorkspaceInviteSent: mockTrackInviteSent, - trackWorkspaceInviteFailed: mockTrackInviteFailed - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackWorkspaceInviteSent: mockTrackInviteSent, + trackWorkspaceInviteFailed: mockTrackInviteFailed + }) + } +}) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports diff --git a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts index 6036a8ffd66..d5ef24e7c59 100644 --- a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts +++ b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts @@ -104,11 +104,16 @@ vi.mock(import('@/config/comfyApi'), () => ({ getComfyPlatformBaseUrl: () => 'https://platform.test' })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackBillingEvent: mockTrackBillingEvent + }) + } +}) function createMember( overrides: Partial = {} diff --git a/src/platform/workspace/composables/useResubscribe.test.ts b/src/platform/workspace/composables/useResubscribe.test.ts index b628ac9d6b6..b089fc75129 100644 --- a/src/platform/workspace/composables/useResubscribe.test.ts +++ b/src/platform/workspace/composables/useResubscribe.test.ts @@ -67,12 +67,17 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackResubscribeClicked: state.trackResubscribeClicked, - trackBillingEvent: state.trackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackResubscribeClicked: state.trackResubscribeClicked, + trackBillingEvent: state.trackBillingEvent + }) + } +}) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 7c7246fcc86..c965ae3708d 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -381,15 +381,20 @@ const mockTrackResubscribeClicked = vi.hoisted(() => vi.fn()) const mockTrackMonthlySubscriptionSucceeded = vi.hoisted(() => vi.fn()) const mockTrackCheckoutJourneyEvent = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent, - trackResubscribeClicked: mockTrackResubscribeClicked, - trackBeginCheckout: mockTrackBeginCheckout, - trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded, - trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackBillingEvent: mockTrackBillingEvent, + trackResubscribeClicked: mockTrackResubscribeClicked, + trackBeginCheckout: mockTrackBeginCheckout, + trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded, + trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent + }) + } +}) vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: mockReportError diff --git a/src/platform/workspace/composables/useWorkspaceBilling.test.ts b/src/platform/workspace/composables/useWorkspaceBilling.test.ts index a0789802746..b6a30944b3b 100644 --- a/src/platform/workspace/composables/useWorkspaceBilling.test.ts +++ b/src/platform/workspace/composables/useWorkspaceBilling.test.ts @@ -85,11 +85,16 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ const mockTrackBillingEvent = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackBillingEvent: mockTrackBillingEvent + }) + } +}) let scope: ReturnType | undefined diff --git a/src/platform/workspace/stores/billingOperationStore.test.ts b/src/platform/workspace/stores/billingOperationStore.test.ts index 5c35d18cd80..81d87bda8ad 100644 --- a/src/platform/workspace/stores/billingOperationStore.test.ts +++ b/src/platform/workspace/stores/billingOperationStore.test.ts @@ -83,12 +83,17 @@ vi.mock(import('@/platform/settings/composables/useSettingsDialog'), () => ({ const mockTrackBillingEvent = vi.fn() const mockTrackMonthlySubscriptionSucceeded = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent, - trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackBillingEvent: mockTrackBillingEvent, + trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded + }) + } +}) import { workspaceApi } from '@/platform/workspace/api/workspaceApi' diff --git a/src/platform/workspace/stores/useWorkspaceAuth.test.ts b/src/platform/workspace/stores/useWorkspaceAuth.test.ts index d64cb82244a..1ece78555e8 100644 --- a/src/platform/workspace/stores/useWorkspaceAuth.test.ts +++ b/src/platform/workspace/stores/useWorkspaceAuth.test.ts @@ -70,11 +70,16 @@ vi.mock(import('@/platform/auth/session/useSessionCookie'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUnifiedAuthRefresh: mockTrackUnifiedAuthRefresh - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackUnifiedAuthRefresh: mockTrackUnifiedAuthRefresh + }) + } +}) vi.mock(import('@/platform/workspace/api/workspaceApiUrl'), () => ({ workspaceApiUrl: (route: string) => `https://api.example.com/api${route}` diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts index b4808391abb..043a16df152 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts @@ -40,9 +40,14 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackOnboardingTour: mocks.trackOnboardingTour }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ trackOnboardingTour: mocks.trackOnboardingTour }) + } +}) const i18n = createI18n({ legacy: false, diff --git a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts index c9a657a5d5c..ec9aaa08223 100644 --- a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts +++ b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts @@ -20,11 +20,16 @@ vi.mock(import('@/services/hdrViewerService'), () => ({ })) const mockTrackImageLoadFailed = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackImageLoadFailed: mockTrackImageLoadFailed - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackImageLoadFailed: mockTrackImageLoadFailed + }) + } +}) const i18n = createI18n({ legacy: false, diff --git a/src/services/dialogService.downgrade.test.ts b/src/services/dialogService.downgrade.test.ts index bbc2db3b5f6..e61943fcca4 100644 --- a/src/services/dialogService.downgrade.test.ts +++ b/src/services/dialogService.downgrade.test.ts @@ -38,8 +38,8 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) vi.mock(import('@/platform/distribution/types'), () => ({ diff --git a/src/services/dialogService.renderer.test.ts b/src/services/dialogService.renderer.test.ts index 73c126fbdab..b8b44f4cd45 100644 --- a/src/services/dialogService.renderer.test.ts +++ b/src/services/dialogService.renderer.test.ts @@ -9,8 +9,8 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) vi.mock(import('@/platform/distribution/types'), () => ({ diff --git a/src/services/dialogService.topUpCredits.test.ts b/src/services/dialogService.topUpCredits.test.ts index a09cf064f5a..c61090a3305 100644 --- a/src/services/dialogService.topUpCredits.test.ts +++ b/src/services/dialogService.topUpCredits.test.ts @@ -17,8 +17,8 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) const mockIsCloud = vi.hoisted(() => ({ value: true })) diff --git a/src/stores/__tests__/authTokenPriority.test.ts b/src/stores/__tests__/authTokenPriority.test.ts index 831e54b087e..1d26c58d9e6 100644 --- a/src/stores/__tests__/authTokenPriority.test.ts +++ b/src/stores/__tests__/authTokenPriority.test.ts @@ -33,9 +33,13 @@ vi.mock(import('vuefire'), () => ({ vi.mock(import('firebase/auth')) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackAuth: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => createTelemetryMock({ trackAuth: vi.fn() }) + } +}) vi.mock(import('@/services/dialogService')) vi.mock(import('@/platform/distribution/types'), () => mockDistributionTypes) diff --git a/src/stores/apiKeyAuthStore.integration.test.ts b/src/stores/apiKeyAuthStore.integration.test.ts index 25c0b44f011..71087dc5a34 100644 --- a/src/stores/apiKeyAuthStore.integration.test.ts +++ b/src/stores/apiKeyAuthStore.integration.test.ts @@ -30,9 +30,13 @@ vi.mock(import('@/composables/useFeatureFlags'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackAuth: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => createTelemetryMock({ trackAuth: vi.fn() }) + } +}) vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ showErrorDialog: vi.fn() }) diff --git a/src/stores/authStore.test.ts b/src/stores/authStore.test.ts index 1429154b17c..bc8429c9b5a 100644 --- a/src/stores/authStore.test.ts +++ b/src/stores/authStore.test.ts @@ -95,11 +95,16 @@ vi.mock(import('vuefire'), () => ({ vi.mock(import('firebase/auth')) const mockTrackAuth = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackAuth: mockTrackAuth - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackAuth: mockTrackAuth + }) + } +}) let mockResetSocket: Mock diff --git a/src/stores/executionStore.test.ts b/src/stores/executionStore.test.ts index ad8c0bb6f10..a15bfae4978 100644 --- a/src/stores/executionStore.test.ts +++ b/src/stores/executionStore.test.ts @@ -57,14 +57,19 @@ vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: true })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackExecutionError: mockTrackExecutionError, - trackExecutionOutcome: mockTrackExecutionOutcome, - trackExecutionSuccess: mockTrackExecutionSuccess, - trackSharedWorkflowRun: mockTrackSharedWorkflowRun - }) -})) +vi.mock(import('@/platform/telemetry'), async () => { + const { createTelemetryMock } = + await import('@/platform/telemetry/__mocks__/telemetry') + return { + useTelemetry: () => + createTelemetryMock({ + trackExecutionError: mockTrackExecutionError, + trackExecutionOutcome: mockTrackExecutionOutcome, + trackExecutionSuccess: mockTrackExecutionSuccess, + trackSharedWorkflowRun: mockTrackSharedWorkflowRun + }) + } +}) // Remove any previous global types declare global { diff --git a/src/views/GraphView.test.ts b/src/views/GraphView.test.ts index 79fe5d3dec8..f901084f966 100644 --- a/src/views/GraphView.test.ts +++ b/src/views/GraphView.test.ts @@ -115,8 +115,8 @@ vi.mock(import('@/composables/useProgressFavicon'), () => ({ })) vi.mock(import('@/platform/distribution/types'), () => distribution) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) vi.mock( import('@/platform/updates/common/useFrontendVersionMismatchWarning'), diff --git a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts index 3dd31606946..de925a63569 100644 --- a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts +++ b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts @@ -13,8 +13,8 @@ import { useAgentRunModeStore } from '@/workbench/extensions/agent/stores/agent/ import DockedAgentPanel from './DockedAgentPanel.vue' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: vi.fn() diff --git a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts index de1075f830a..a21bcabbcf1 100644 --- a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts +++ b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts @@ -11,8 +11,8 @@ import DockedAgentPanel from './DockedAgentPanel.vue' vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) // The mocked module factory throws, so the dynamic import itself rejects - diff --git a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts index 25dde8c79d5..ee33d420364 100644 --- a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts +++ b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts @@ -4,8 +4,8 @@ import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/ag import { useAgentDockMount } from './useAgentDockMount' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) const { loadDockedAgentPanel } = vi.hoisted(() => ({ loadDockedAgentPanel: vi.fn(() => ({ name: 'DockedAgentPanel' })) diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts index b74e01f2429..49c7f6667c5 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts @@ -8,8 +8,8 @@ import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useA import { useAgentPanelStore } from './agentPanelStore' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => null })) /** From d1c3e018bb06a42fa2d665f2bc83cfb2640b3ee1 Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 15 Sep 2026 01:12:01 +0000 Subject: [PATCH 2/6] test: load the matching telemetry automock --- src/components/TopMenuSection.test.ts | 14 ++++------- .../builder/builderViewOptions.test.ts | 12 ++++------ src/components/builder/useBuilderSave.test.ts | 16 +++++-------- .../common/WorkflowActionsDropdown.test.ts | 12 ++++------ .../TopUpCreditsDialogContentLegacy.test.ts | 17 ++++++-------- .../content/setting/CreditsPanel.test.ts | 12 ++++------ .../CancelSubscriptionDialogContent.test.ts | 14 ++++------- .../graph/selectionToolbox/InfoButton.test.ts | 14 ++++------- .../helpcenter/HelpCenterMenuContent.test.ts | 18 ++++++--------- .../rightSidePanel/RightSidePanel.test.ts | 9 +++++--- .../errors/ErrorNodeCard.test.ts | 17 +++++--------- .../parameters/SectionWidgets.test.ts | 14 ++++------- .../parameters/WidgetActions.test.ts | 14 ++++------- .../rightSidePanelTabTelemetry.test.ts | 16 +++++-------- src/components/sidebar/SideToolbar.test.ts | 12 ++++------ .../topbar/CurrentUserPopoverLegacy.test.ts | 15 ++++-------- src/composables/auth/useAuthActions.test.ts | 15 ++++-------- .../canvas/visibleCanvasViewport.test.ts | 9 +++++--- src/composables/useCoreCommands.test.ts | 19 ++++++--------- src/composables/useTemplateFiltering.test.ts | 17 +++++--------- src/platform/auth/unified/remintRetry.test.ts | 14 ++++------- .../cloud/onboarding/CloudSignupView.test.ts | 9 +++++--- .../components/PricingTable.test.ts | 16 +++++-------- .../composables/useSubscriptionDialog.test.ts | 12 ++++------ .../composables/useTopUpUrlLoader.test.ts | 15 +++++------- .../launchCancellationFlow.test.ts | 14 ++++------- .../teamSubscriptionCheckoutUtil.test.ts | 16 +++++-------- ...onboardingTourStore.registeredTour.test.ts | 12 ++++------ .../onboarding/onboardingTourStore.test.ts | 12 ++++------ .../composables/useSettingsDialog.test.ts | 9 +++++--- src/platform/settings/settingStore.test.ts | 15 ++++-------- src/platform/support/feedbackDialog.test.ts | 11 ++++----- src/platform/telemetry/__mocks__/index.ts | 11 +++++++++ src/platform/telemetry/__mocks__/telemetry.ts | 10 -------- .../useSearchQueryTracking.test.ts | 12 ++++------ .../workflowService.insertWorkflow.test.ts | 18 ++++++--------- .../core/services/workflowService.test.ts | 18 ++++++--------- .../ShareWorkflowDialogContent.test.ts | 14 ++++------- .../useSharedWorkflowUrlLoader.test.ts | 14 ++++------- .../CurrentUserPopoverWorkspace.test.ts | 9 +++++--- .../components/InviteMembersForm.test.ts | 16 +++++-------- ...TopUpCreditsDialogContentWorkspace.test.ts | 19 +++++++-------- .../dialogs/InviteMemberDialogContent.test.ts | 16 +++++-------- .../useDowngradeToPersonal.test.ts | 14 ++++------- .../composables/useResubscribe.test.ts | 16 +++++-------- .../useSubscriptionCheckout.test.ts | 23 ++++++++----------- .../composables/useWorkspaceBilling.test.ts | 14 ++++------- .../stores/billingOperationStore.test.ts | 17 ++++++-------- .../workspace/stores/useWorkspaceAuth.test.ts | 14 ++++------- .../nudge/FirstRunTourNudge.test.ts | 12 ++++------ .../vueNodes/components/ImagePreview.test.ts | 16 +++++-------- src/services/dialogService.downgrade.test.ts | 9 +++++--- src/services/dialogService.renderer.test.ts | 11 +++++---- .../dialogService.topUpCredits.test.ts | 9 +++++--- .../__tests__/authTokenPriority.test.ts | 11 ++++----- .../apiKeyAuthStore.integration.test.ts | 11 ++++----- src/stores/authStore.test.ts | 14 ++++------- src/stores/executionStore.test.ts | 20 +++++++--------- src/views/GraphView.test.ts | 9 +++++--- .../components/agent/DockedAgentPanel.test.ts | 9 +++++--- .../agent/dockedAgentPanelLoadFailure.test.ts | 9 +++++--- .../composables/useAgentDockMount.test.ts | 9 +++++--- .../stores/agent/agentPanelStoreId.test.ts | 9 +++++--- 63 files changed, 364 insertions(+), 490 deletions(-) create mode 100644 src/platform/telemetry/__mocks__/index.ts delete mode 100644 src/platform/telemetry/__mocks__/telemetry.ts diff --git a/src/components/TopMenuSection.test.ts b/src/components/TopMenuSection.test.ts index 6559a6e8859..403224e4bdf 100644 --- a/src/components/TopMenuSection.test.ts +++ b/src/components/TopMenuSection.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' /* eslint-disable testing-library/no-container */ /* eslint-disable testing-library/no-node-access */ import { getActivePinia } from 'pinia' @@ -82,15 +83,10 @@ vi.mock(import('@/scripts/app'), () => ({ const mockTrackUiButtonClicked = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = mockTrackUiButtonClicked }) type WrapperOptions = { diff --git a/src/components/builder/builderViewOptions.test.ts b/src/components/builder/builderViewOptions.test.ts index cd42df457cc..19637c1bcd0 100644 --- a/src/components/builder/builderViewOptions.test.ts +++ b/src/components/builder/builderViewOptions.test.ts @@ -1,5 +1,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { app } from '@/scripts/app' import { createMockLoadedWorkflow } from '@/utils/__tests__/litegraphTestUtils' @@ -9,13 +10,10 @@ const mockTrackDefaultViewSet = vi.hoisted(() => vi.fn()) vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackDefaultViewSet: mockTrackDefaultViewSet }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackDefaultViewSet = mockTrackDefaultViewSet }) vi.mock(import('@/scripts/app'), () => { diff --git a/src/components/builder/useBuilderSave.test.ts b/src/components/builder/useBuilderSave.test.ts index 33efd31d874..dbf2ccd5966 100644 --- a/src/components/builder/useBuilderSave.test.ts +++ b/src/components/builder/useBuilderSave.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { fromPartial } from '@total-typescript/shoehorn' import { beforeEach, describe, expect, it, vi } from 'vitest' import { ref } from 'vue' @@ -38,16 +39,11 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ useErrorHandling: () => ({ toastErrorHandler: mockToastErrorHandler }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackEnterLinear: mockTrackEnterLinear, - trackDefaultViewSet: mockTrackDefaultViewSet - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackEnterLinear = mockTrackEnterLinear + telemetryMock.trackDefaultViewSet = mockTrackDefaultViewSet }) vi.mock( diff --git a/src/components/common/WorkflowActionsDropdown.test.ts b/src/components/common/WorkflowActionsDropdown.test.ts index 2b9db8bd906..0553bab3442 100644 --- a/src/components/common/WorkflowActionsDropdown.test.ts +++ b/src/components/common/WorkflowActionsDropdown.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -26,13 +27,10 @@ const spies = vi.hoisted(() => ({ markAsSeen: vi.fn() })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackUiButtonClicked: spies.trackUiButtonClicked }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = spies.trackUiButtonClicked }) vi.mock(import('@/composables/useWorkflowActionsMenu'), async () => { diff --git a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts index edc22324d87..b7fbccd91d8 100644 --- a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts +++ b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -48,16 +49,12 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, - trackBillingEvent: mockTrackBillingEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackApiCreditTopupButtonPurchaseClicked = + mockTrackTopUpPurchase + telemetryMock.trackBillingEvent = mockTrackBillingEvent }) const mockClearPendingTopup = vi.hoisted(() => vi.fn()) diff --git a/src/components/dialog/content/setting/CreditsPanel.test.ts b/src/components/dialog/content/setting/CreditsPanel.test.ts index 4aac326662f..600e2139350 100644 --- a/src/components/dialog/content/setting/CreditsPanel.test.ts +++ b/src/components/dialog/content/setting/CreditsPanel.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -47,13 +48,10 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackHelpResourceClicked: vi.fn() }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackHelpResourceClicked = vi.fn() }) vi.mock(import('@/composables/useExternalLink'), () => ({ diff --git a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts index ee27be399c1..cc6ebdfbf89 100644 --- a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts +++ b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -101,15 +102,10 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackSubscriptionCancellation: mockTrackCancellation - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackSubscriptionCancellation = mockTrackCancellation }) vi.mock( diff --git a/src/components/graph/selectionToolbox/InfoButton.test.ts b/src/components/graph/selectionToolbox/InfoButton.test.ts index 9929bb0b8ce..92154c65132 100644 --- a/src/components/graph/selectionToolbox/InfoButton.test.ts +++ b/src/components/graph/selectionToolbox/InfoButton.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import PrimeVue from 'primevue/config' @@ -19,15 +20,10 @@ vi.mock(import('@/composables/graph/useSelectionState'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackUiButtonClicked: trackUiButtonClickedMock - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = trackUiButtonClickedMock }) describe('InfoButton', () => { diff --git a/src/components/helpcenter/HelpCenterMenuContent.test.ts b/src/components/helpcenter/HelpCenterMenuContent.test.ts index 0ddc14cea3d..67489704c12 100644 --- a/src/components/helpcenter/HelpCenterMenuContent.test.ts +++ b/src/components/helpcenter/HelpCenterMenuContent.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -44,17 +45,12 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackHelpResourceClicked: vi.fn(), - trackHelpCenterOpened: vi.fn(), - trackHelpCenterClosed: vi.fn() - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackHelpResourceClicked = vi.fn() + telemetryMock.trackHelpCenterOpened = vi.fn() + telemetryMock.trackHelpCenterClosed = vi.fn() }) vi.mock(import('@/utils/envUtil'), () => ({ diff --git a/src/components/rightSidePanel/RightSidePanel.test.ts b/src/components/rightSidePanel/RightSidePanel.test.ts index 7e419a1d521..3d506396ad9 100644 --- a/src/components/rightSidePanel/RightSidePanel.test.ts +++ b/src/components/rightSidePanel/RightSidePanel.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { getActivePinia } from 'pinia' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -32,9 +33,11 @@ vi.mock(import('@/composables/graph/useGraphHierarchy'), () => ({ useGraphHierarchy: () => ({ findParentGroup: vi.fn(() => null) }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) function createPanelI18n() { return createI18n({ diff --git a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts index 23a8b52f93f..a170f7dee59 100644 --- a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts +++ b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { getActivePinia } from 'pinia' import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' @@ -41,17 +42,11 @@ vi.mock(import('@/utils/errorReportUtil'), () => ({ const mockTrackHelpResourceClicked = vi.fn() -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: vi.fn(() => - createTelemetryMock({ - trackUiButtonClicked: vi.fn(), - trackHelpResourceClicked: mockTrackHelpResourceClicked - }) - ) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = vi.fn() + telemetryMock.trackHelpResourceClicked = mockTrackHelpResourceClicked }) vi.mock(import('@/composables/useExternalLink'), () => ({ diff --git a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts index 1cc1a886458..a5917f790af 100644 --- a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts +++ b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' import { fromPartial } from '@total-typescript/shoehorn' @@ -31,15 +32,10 @@ const setDirty = vi.fn() const getNodeById = vi.fn() const animateToBounds = vi.fn() -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = mockTrackUiButtonClicked }) const WidgetItemStub = defineComponent({ diff --git a/src/components/rightSidePanel/parameters/WidgetActions.test.ts b/src/components/rightSidePanel/parameters/WidgetActions.test.ts index 0620f893e37..4a8ed67788f 100644 --- a/src/components/rightSidePanel/parameters/WidgetActions.test.ts +++ b/src/components/rightSidePanel/parameters/WidgetActions.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { fromPartial, fromAny } from '@total-typescript/shoehorn' @@ -26,15 +27,10 @@ vi.mock(import('@/core/graph/subgraph/promotionUtils'), () => ({ promoteWidget: vi.fn() })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackWidgetFavoriteToggled: mockTrackWidgetFavoriteToggled - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackWidgetFavoriteToggled = mockTrackWidgetFavoriteToggled }) vi.mock(import('@/services/dialogService'), () => ({ diff --git a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts index c9448e7ad2c..263df294f82 100644 --- a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts +++ b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts @@ -1,18 +1,14 @@ -import { describe, expect, it, vi } from 'vitest' +import { telemetryMock } from '@/platform/telemetry/__mocks__' +import { beforeEach, describe, expect, it, vi } from 'vitest' const { mockTrackUiButtonClicked } = vi.hoisted(() => ({ mockTrackUiButtonClicked: vi.fn() })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = mockTrackUiButtonClicked }) import { trackRightSidePanelTabOpened } from './rightSidePanelTabTelemetry' diff --git a/src/components/sidebar/SideToolbar.test.ts b/src/components/sidebar/SideToolbar.test.ts index 8f9f1e0a786..100e09b653f 100644 --- a/src/components/sidebar/SideToolbar.test.ts +++ b/src/components/sidebar/SideToolbar.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import PrimeVue from 'primevue/config' @@ -39,13 +40,10 @@ vi.mock(import('@/platform/distribution/types'), () => ({ isNightly: false })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackUiButtonClicked: spies.trackUiButtonClicked }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = spies.trackUiButtonClicked }) const i18n = createI18n({ diff --git a/src/components/topbar/CurrentUserPopoverLegacy.test.ts b/src/components/topbar/CurrentUserPopoverLegacy.test.ts index 6dc6c4d3b83..5f13311a132 100644 --- a/src/components/topbar/CurrentUserPopoverLegacy.test.ts +++ b/src/components/topbar/CurrentUserPopoverLegacy.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { getActivePinia } from 'pinia' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' @@ -119,16 +120,10 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ })) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: vi.fn(() => - createTelemetryMock({ - trackAddApiCreditButtonClicked: vi.fn() - }) - ) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackAddApiCreditButtonClicked = vi.fn() }) describe('CurrentUserPopoverLegacy', () => { diff --git a/src/composables/auth/useAuthActions.test.ts b/src/composables/auth/useAuthActions.test.ts index 7b2c3af7014..e6e49ec9094 100644 --- a/src/composables/auth/useAuthActions.test.ts +++ b/src/composables/auth/useAuthActions.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' import { useToastStore } from '@/platform/updates/common/toastStore' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' @@ -77,16 +78,10 @@ vi.mock(import('@/platform/distribution/types'), () => ({ } })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: vi.fn(() => - createTelemetryMock({ - trackAuthFailed: mockTrackAuthFailed - }) - ) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackAuthFailed = mockTrackAuthFailed }) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ diff --git a/src/composables/canvas/visibleCanvasViewport.test.ts b/src/composables/canvas/visibleCanvasViewport.test.ts index 521ec503c18..ed3882cd94c 100644 --- a/src/composables/canvas/visibleCanvasViewport.test.ts +++ b/src/composables/canvas/visibleCanvasViewport.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { LGraphCanvas } from '@/lib/litegraph/src/litegraph' @@ -5,9 +6,11 @@ import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/ag import { visibleCanvasViewport } from './visibleCanvasViewport' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) describe('visibleCanvasViewport', () => { beforeEach(() => { diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index 18aa452b189..0bf05a823ff 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -117,18 +118,12 @@ vi.mock(import('@/services/litegraphService'), () => ({ })) const mockTrackHelpResourceClicked = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: vi.fn(() => - createTelemetryMock({ - trackHelpResourceClicked: mockTrackHelpResourceClicked, - trackRunButton: vi.fn(), - trackWorkflowExecution: vi.fn() - }) - ) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackHelpResourceClicked = mockTrackHelpResourceClicked + telemetryMock.trackRunButton = vi.fn() + telemetryMock.trackWorkflowExecution = vi.fn() }) const mockShowAbout = vi.hoisted(() => vi.fn()) diff --git a/src/composables/useTemplateFiltering.test.ts b/src/composables/useTemplateFiltering.test.ts index 62a2a80177b..75ee81487fc 100644 --- a/src/composables/useTemplateFiltering.test.ts +++ b/src/composables/useTemplateFiltering.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useSettingStore } from '@/platform/settings/settingStore' import { useTemplateRankingStore } from '@/stores/templateRankingStore' import { useSystemStatsStore } from '@/stores/systemStatsStore' @@ -18,17 +19,11 @@ let defaultRankingStore: ReturnType let mockSystemStatsStore: ReturnType const trackTemplateFilterChanged = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: vi.fn(() => - createTelemetryMock({ - trackTemplateFilterChanged, - trackSearchQuery: vi.fn() - }) - ) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackTemplateFilterChanged = trackTemplateFilterChanged + telemetryMock.trackSearchQuery = vi.fn() }) vi.mock( diff --git a/src/platform/auth/unified/remintRetry.test.ts b/src/platform/auth/unified/remintRetry.test.ts index c461734e24d..96a42f1c2ce 100644 --- a/src/platform/auth/unified/remintRetry.test.ts +++ b/src/platform/auth/unified/remintRetry.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkspaceAuthStore } from '@/platform/workspace/stores/workspaceAuthStore' import type { AxiosAdapter } from 'axios' import axios, { AxiosError } from 'axios' @@ -14,15 +15,10 @@ const { mockRemint, mockTrackUnifiedAuthRetry, flagState } = vi.hoisted(() => ({ flagState: { unifiedCloudAuthEnabled: true } })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackUnifiedAuthRetry: mockTrackUnifiedAuthRetry - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUnifiedAuthRetry = mockTrackUnifiedAuthRetry }) vi.mock(import('@/composables/useFeatureFlags'), () => ({ diff --git a/src/platform/cloud/onboarding/CloudSignupView.test.ts b/src/platform/cloud/onboarding/CloudSignupView.test.ts index 12f03ab24e6..4c0a87eb148 100644 --- a/src/platform/cloud/onboarding/CloudSignupView.test.ts +++ b/src/platform/cloud/onboarding/CloudSignupView.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { render, screen, waitFor } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' @@ -23,9 +24,11 @@ vi.mock( vi.mock(import('@comfyorg/account/webviewDetection'), () => ({ isEmbeddedWebView: () => false })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) const inChina = vi.hoisted(() => ({ value: false, diff --git a/src/platform/cloud/subscription/components/PricingTable.test.ts b/src/platform/cloud/subscription/components/PricingTable.test.ts index f79cc7572cb..0b119d7c80a 100644 --- a/src/platform/cloud/subscription/components/PricingTable.test.ts +++ b/src/platform/cloud/subscription/components/PricingTable.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' @@ -114,16 +115,11 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackBeginCheckout: mockTrackBeginCheckout, - trackBillingEvent: mockTrackBillingEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackBeginCheckout = mockTrackBeginCheckout + telemetryMock.trackBillingEvent = mockTrackBillingEvent }) vi.mock( diff --git a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts index c447694379a..3d941350e06 100644 --- a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts +++ b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useDialogStore } from '@/stores/dialogStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' @@ -105,13 +106,10 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackSubscription: mockTrackSubscription }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackSubscription = mockTrackSubscription }) vi.mock( diff --git a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts index a34dcb50f9e..b6e82a53fdb 100644 --- a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts +++ b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { fromAny } from '@total-typescript/shoehorn' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -55,15 +56,11 @@ vi.mock( const mockTrackAddApiCreditButtonClicked = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackAddApiCreditButtonClicked: mockTrackAddApiCreditButtonClicked - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackAddApiCreditButtonClicked = + mockTrackAddApiCreditButtonClicked }) describe('useTopUpUrlLoader', () => { diff --git a/src/platform/cloud/subscription/launchCancellationFlow.test.ts b/src/platform/cloud/subscription/launchCancellationFlow.test.ts index 471b0dcfed3..9a47d71d098 100644 --- a/src/platform/cloud/subscription/launchCancellationFlow.test.ts +++ b/src/platform/cloud/subscription/launchCancellationFlow.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -39,15 +40,10 @@ vi.mock(import('@/platform/cloud/churnkey/churnkeyClient'), () => ({ prepareChurnkey: mocks.prepare })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackSubscriptionCancellation: mocks.trackCancellation - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackSubscriptionCancellation = mocks.trackCancellation }) import { launchCancellationFlow } from './launchCancellationFlow' diff --git a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts index e421918a33a..c7ab5322831 100644 --- a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts +++ b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -34,16 +35,11 @@ vi.mock(import('@/platform/workspace/api/workspaceApi'), () => ({ } } })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackBeginCheckout: mockTrackBeginCheckout, - trackBillingEvent: mockTrackBillingEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackBeginCheckout = mockTrackBeginCheckout + telemetryMock.trackBillingEvent = mockTrackBillingEvent }) import { performTeamSubscriptionCheckout } from './teamSubscriptionCheckoutUtil' diff --git a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts index f65334b8b41..4c49c57b709 100644 --- a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts +++ b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useSettingStore } from '@/platform/settings/settingStore' import { useAppModeStore } from '@/stores/appModeStore' import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest' @@ -12,13 +13,10 @@ import type { SpotlightStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' const telemetry = vi.hoisted(() => ({ track: vi.fn() })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackOnboardingTour: telemetry.track }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackOnboardingTour = telemetry.track }) const appModeMock = vi.hoisted(() => ({ mode: null as Ref | null })) diff --git a/src/platform/onboarding/onboardingTourStore.test.ts b/src/platform/onboarding/onboardingTourStore.test.ts index 4a66d6c699f..59702392792 100644 --- a/src/platform/onboarding/onboardingTourStore.test.ts +++ b/src/platform/onboarding/onboardingTourStore.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAppModeStore } from '@/stores/appModeStore' import { useSettingStore } from '@/platform/settings/settingStore' import type { DetachedWindowAPI } from 'happy-dom' @@ -19,13 +20,10 @@ import type { CoachId, CoachStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' const telemetry = vi.hoisted(() => ({ track: vi.fn() })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackOnboardingTour: telemetry.track }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackOnboardingTour = telemetry.track }) const appModeMock = vi.hoisted((): { mode: Ref | null } => ({ diff --git a/src/platform/settings/composables/useSettingsDialog.test.ts b/src/platform/settings/composables/useSettingsDialog.test.ts index 86035728f47..93ecf2ab963 100644 --- a/src/platform/settings/composables/useSettingsDialog.test.ts +++ b/src/platform/settings/composables/useSettingsDialog.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { useDialogStore } from '@/stores/dialogStore' /** * Settings dialog migration regression net: `useSettingsDialog().show()` must @@ -20,9 +21,11 @@ vi.mock(import('@/i18n'), () => ({ t: (k: string) => k })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: () => ({ diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index b4b0fc5d005..f0f837f1297 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -13,16 +14,10 @@ const { trackSettingChanged } = vi.hoisted(() => ({ trackSettingChanged: vi.fn() })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: vi.fn(() => - createTelemetryMock({ - trackSettingChanged - }) - ) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackSettingChanged = trackSettingChanged }) // Mock the api diff --git a/src/platform/support/feedbackDialog.test.ts b/src/platform/support/feedbackDialog.test.ts index c06c498f818..03e34ed61a8 100644 --- a/src/platform/support/feedbackDialog.test.ts +++ b/src/platform/support/feedbackDialog.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { beforeEach, describe, expect, it, vi } from 'vitest' import { openTypeformDialog } from '@/platform/surveys/openTypeformDialog' @@ -15,12 +16,10 @@ vi.mock(import('@/platform/surveys/openTypeformDialog'), () => ({ })) const trackUiButtonClicked = vi.fn() -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: vi.fn(() => createTelemetryMock({ trackUiButtonClicked })) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUiButtonClicked = trackUiButtonClicked }) const userEmail = vi.hoisted((): { value: string | undefined } => ({ diff --git a/src/platform/telemetry/__mocks__/index.ts b/src/platform/telemetry/__mocks__/index.ts new file mode 100644 index 00000000000..5004491e648 --- /dev/null +++ b/src/platform/telemetry/__mocks__/index.ts @@ -0,0 +1,11 @@ +import { vi } from 'vitest' + +import type { + setTelemetryRegistry as realSetTelemetryRegistry, + useTelemetry as realUseTelemetry +} from '../index' +import { TelemetryRegistry } from '../TelemetryRegistry' + +export const telemetryMock = vi.mockObject(new TelemetryRegistry()) +export const useTelemetry = vi.fn(() => telemetryMock) +export const setTelemetryRegistry = vi.fn() diff --git a/src/platform/telemetry/__mocks__/telemetry.ts b/src/platform/telemetry/__mocks__/telemetry.ts deleted file mode 100644 index 382cb8a8dfb..00000000000 --- a/src/platform/telemetry/__mocks__/telemetry.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { vi } from 'vitest' - -import { TelemetryRegistry } from '../TelemetryRegistry' -import type { TelemetryDispatcher, TelemetryProvider } from '../types' - -export function createTelemetryMock( - overrides: TelemetryProvider = {} -): TelemetryDispatcher { - return Object.assign(vi.mockObject(new TelemetryRegistry()), overrides) -} diff --git a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts index 2ebb86b6d0d..4a1a23345ea 100644 --- a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts +++ b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { EffectScope, Ref } from 'vue' import { effectScope, ref } from 'vue' @@ -6,13 +7,10 @@ const hoisted = vi.hoisted(() => ({ trackSearchQuery: vi.fn() })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackSearchQuery: hoisted.trackSearchQuery }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackSearchQuery = hoisted.trackSearchQuery }) import { useSearchQueryTracking } from './useSearchQueryTracking' diff --git a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts index 4cf158b4a67..1e9a6d830a8 100644 --- a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts +++ b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowDraftStoreV2 } from '@/platform/workflow/persistence/stores/workflowDraftStoreV2' import { useDomWidgetStore } from '@/stores/domWidgetStore' import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore' @@ -51,17 +52,12 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackDefaultViewSet: vi.fn(), - trackWorkflowSaved: vi.fn(), - trackEnterLinear: vi.fn() - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackDefaultViewSet = vi.fn() + telemetryMock.trackWorkflowSaved = vi.fn() + telemetryMock.trackEnterLinear = vi.fn() }) const PROBE_NODE_TYPE = 'test/insert-workflow-probe' diff --git a/src/platform/workflow/core/services/workflowService.test.ts b/src/platform/workflow/core/services/workflowService.test.ts index 7e1c40c4a2d..55b8c871777 100644 --- a/src/platform/workflow/core/services/workflowService.test.ts +++ b/src/platform/workflow/core/services/workflowService.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore' import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' // eslint-disable-line import-x/no-restricted-paths import { useWorkflowDraftStoreV2 } from '@/platform/workflow/persistence/stores/workflowDraftStoreV2' @@ -131,17 +132,12 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: reportErrorMock })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackDefaultViewSet: vi.fn(), - trackWorkflowSaved: mockTrackWorkflowSaved, - trackEnterLinear: vi.fn() - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackDefaultViewSet = vi.fn() + telemetryMock.trackWorkflowSaved = mockTrackWorkflowSaved + telemetryMock.trackEnterLinear = vi.fn() }) function createWorkflow( diff --git a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts index 194e444c603..7a7f6c52dc6 100644 --- a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts +++ b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' @@ -9,15 +10,10 @@ import ShareWorkflowDialogContent from '@/platform/workflow/sharing/components/S const mockTrackShareFlow = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackShareFlow: mockTrackShareFlow - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackShareFlow = mockTrackShareFlow }) const mockToast = vi.hoisted(() => ({ add: vi.fn() })) diff --git a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts index 651edf4f84c..2a7a839d4b2 100644 --- a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts +++ b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useDialogStore } from '@/stores/dialogStore' import { fromPartial } from '@total-typescript/shoehorn' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -49,15 +50,10 @@ vi.mock(import('@/composables/useAppMode'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackShareLinkOpened: mockTrackShareLinkOpened - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackShareLinkOpened = mockTrackShareLinkOpened }) vi.mock( diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts index 9e6db502bad..839eecdf62f 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { getActivePinia } from 'pinia' import { render, screen, waitFor } from '@testing-library/vue' @@ -127,9 +128,11 @@ vi.mock(import('@/services/dialogService'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ diff --git a/src/platform/workspace/components/InviteMembersForm.test.ts b/src/platform/workspace/components/InviteMembersForm.test.ts index acb306cecc7..f40ba968cb6 100644 --- a/src/platform/workspace/components/InviteMembersForm.test.ts +++ b/src/platform/workspace/components/InviteMembersForm.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { render, screen, waitFor } from '@testing-library/vue' import userEvent from '@testing-library/user-event' @@ -33,16 +34,11 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackWorkspaceInviteSent: mockTrackInviteSent, - trackWorkspaceInviteFailed: mockTrackInviteFailed - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackWorkspaceInviteSent = mockTrackInviteSent + telemetryMock.trackWorkspaceInviteFailed = mockTrackInviteFailed }) const i18n = createI18n({ diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index 0401d2d5a0a..9dabeff74dc 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -4,6 +4,7 @@ import { setPersistence } from 'firebase/auth' +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { @@ -96,17 +97,13 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, - trackBillingEvent: mockTrackBillingEvent, - trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackApiCreditTopupButtonPurchaseClicked = + mockTrackTopUpPurchase + telemetryMock.trackBillingEvent = mockTrackBillingEvent + telemetryMock.trackCheckoutJourneyEvent = mockTrackCheckoutJourneyEvent }) vi.mock(import('firebase/auth'), { spy: true }) diff --git a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts index 269e7ec0a80..184ad8bfd5a 100644 --- a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts +++ b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useDialogStore } from '@/stores/dialogStore' import { render, screen, waitFor } from '@testing-library/vue' @@ -36,16 +37,11 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackWorkspaceInviteSent: mockTrackInviteSent, - trackWorkspaceInviteFailed: mockTrackInviteFailed - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackWorkspaceInviteSent = mockTrackInviteSent + telemetryMock.trackWorkspaceInviteFailed = mockTrackInviteFailed }) vi.mock( diff --git a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts index d5ef24e7c59..00737af8b50 100644 --- a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts +++ b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { getActivePinia } from 'pinia' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -104,15 +105,10 @@ vi.mock(import('@/config/comfyApi'), () => ({ getComfyPlatformBaseUrl: () => 'https://platform.test' })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackBillingEvent: mockTrackBillingEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackBillingEvent = mockTrackBillingEvent }) function createMember( diff --git a/src/platform/workspace/composables/useResubscribe.test.ts b/src/platform/workspace/composables/useResubscribe.test.ts index b089fc75129..6c3b000af73 100644 --- a/src/platform/workspace/composables/useResubscribe.test.ts +++ b/src/platform/workspace/composables/useResubscribe.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { createApp, defineComponent } from 'vue' import type { App } from 'vue' @@ -67,16 +68,11 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackResubscribeClicked: state.trackResubscribeClicked, - trackBillingEvent: state.trackBillingEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackResubscribeClicked = state.trackResubscribeClicked + telemetryMock.trackBillingEvent = state.trackBillingEvent }) vi.mock( diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index c965ae3708d..8d1919f1eee 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { render } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { computed } from 'vue' @@ -381,19 +382,15 @@ const mockTrackResubscribeClicked = vi.hoisted(() => vi.fn()) const mockTrackMonthlySubscriptionSucceeded = vi.hoisted(() => vi.fn()) const mockTrackCheckoutJourneyEvent = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackBillingEvent: mockTrackBillingEvent, - trackResubscribeClicked: mockTrackResubscribeClicked, - trackBeginCheckout: mockTrackBeginCheckout, - trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded, - trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackBillingEvent = mockTrackBillingEvent + telemetryMock.trackResubscribeClicked = mockTrackResubscribeClicked + telemetryMock.trackBeginCheckout = mockTrackBeginCheckout + telemetryMock.trackMonthlySubscriptionSucceeded = + mockTrackMonthlySubscriptionSucceeded + telemetryMock.trackCheckoutJourneyEvent = mockTrackCheckoutJourneyEvent }) vi.mock(import('@/platform/telemetry/reportError'), () => ({ diff --git a/src/platform/workspace/composables/useWorkspaceBilling.test.ts b/src/platform/workspace/composables/useWorkspaceBilling.test.ts index b6a30944b3b..53a59d39efb 100644 --- a/src/platform/workspace/composables/useWorkspaceBilling.test.ts +++ b/src/platform/workspace/composables/useWorkspaceBilling.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { billingOperation } from './billingOperationTestUtils' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' @@ -85,15 +86,10 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ const mockTrackBillingEvent = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackBillingEvent: mockTrackBillingEvent - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackBillingEvent = mockTrackBillingEvent }) let scope: ReturnType | undefined diff --git a/src/platform/workspace/stores/billingOperationStore.test.ts b/src/platform/workspace/stores/billingOperationStore.test.ts index 81d87bda8ad..171338a0cba 100644 --- a/src/platform/workspace/stores/billingOperationStore.test.ts +++ b/src/platform/workspace/stores/billingOperationStore.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { bindOperationToCheckoutJourney, @@ -83,16 +84,12 @@ vi.mock(import('@/platform/settings/composables/useSettingsDialog'), () => ({ const mockTrackBillingEvent = vi.fn() const mockTrackMonthlySubscriptionSucceeded = vi.fn() -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackBillingEvent: mockTrackBillingEvent, - trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackBillingEvent = mockTrackBillingEvent + telemetryMock.trackMonthlySubscriptionSucceeded = + mockTrackMonthlySubscriptionSucceeded }) import { workspaceApi } from '@/platform/workspace/api/workspaceApi' diff --git a/src/platform/workspace/stores/useWorkspaceAuth.test.ts b/src/platform/workspace/stores/useWorkspaceAuth.test.ts index 1ece78555e8..f8bec73a121 100644 --- a/src/platform/workspace/stores/useWorkspaceAuth.test.ts +++ b/src/platform/workspace/stores/useWorkspaceAuth.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useToastStore } from '@/platform/updates/common/toastStore' @@ -70,15 +71,10 @@ vi.mock(import('@/platform/auth/session/useSessionCookie'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackUnifiedAuthRefresh: mockTrackUnifiedAuthRefresh - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackUnifiedAuthRefresh = mockTrackUnifiedAuthRefresh }) vi.mock(import('@/platform/workspace/api/workspaceApiUrl'), () => ({ diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts index 043a16df152..13851dc6a0f 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useDialogStore } from '@/stores/dialogStore' import { fromPartial } from '@total-typescript/shoehorn' import userEvent from '@testing-library/user-event' @@ -40,13 +41,10 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ trackOnboardingTour: mocks.trackOnboardingTour }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackOnboardingTour = mocks.trackOnboardingTour }) const i18n = createI18n({ diff --git a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts index ec9aaa08223..e4f1bbd0191 100644 --- a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts +++ b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts @@ -1,9 +1,10 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' /* eslint-disable testing-library/no-container, testing-library/no-node-access */ /* eslint-disable testing-library/prefer-user-event */ import { render, screen, fireEvent } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import { getActivePinia } from 'pinia' -import { describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' @@ -20,15 +21,10 @@ vi.mock(import('@/services/hdrViewerService'), () => ({ })) const mockTrackImageLoadFailed = vi.fn() -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackImageLoadFailed: mockTrackImageLoadFailed - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackImageLoadFailed = mockTrackImageLoadFailed }) const i18n = createI18n({ diff --git a/src/services/dialogService.downgrade.test.ts b/src/services/dialogService.downgrade.test.ts index e61943fcca4..aff7993550c 100644 --- a/src/services/dialogService.downgrade.test.ts +++ b/src/services/dialogService.downgrade.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import type { Component } from 'vue' import type DowngradeContent from '@/platform/workspace/components/dialogs/DowngradeRemoveMembersDialogContent.vue' @@ -38,9 +39,11 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false diff --git a/src/services/dialogService.renderer.test.ts b/src/services/dialogService.renderer.test.ts index b8b44f4cd45..bafa31633d9 100644 --- a/src/services/dialogService.renderer.test.ts +++ b/src/services/dialogService.renderer.test.ts @@ -1,17 +1,20 @@ +import { useTelemetry } from '@/platform/telemetry' /** * Dialog migration regression net: when callers in `dialogService` open a * Reka-migrated dialog, the dialog stack item must carry `renderer: 'reka'`. * Catches accidental reverts of the Reka renderer flip. */ -import { describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false diff --git a/src/services/dialogService.topUpCredits.test.ts b/src/services/dialogService.topUpCredits.test.ts index c61090a3305..c982a1c5acf 100644 --- a/src/services/dialogService.topUpCredits.test.ts +++ b/src/services/dialogService.topUpCredits.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { useDialogStore } from '@/stores/dialogStore' /** * showTopUpCreditsDialog routes the paired server capabilities to purchase, @@ -17,9 +18,11 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) const mockIsCloud = vi.hoisted(() => ({ value: true })) vi.mock(import('@/platform/distribution/types'), () => ({ diff --git a/src/stores/__tests__/authTokenPriority.test.ts b/src/stores/__tests__/authTokenPriority.test.ts index 1d26c58d9e6..00a1d404f5c 100644 --- a/src/stores/__tests__/authTokenPriority.test.ts +++ b/src/stores/__tests__/authTokenPriority.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useWorkspaceAuthStore } from '@/platform/workspace/stores/workspaceAuthStore' @@ -33,12 +34,10 @@ vi.mock(import('vuefire'), () => ({ vi.mock(import('firebase/auth')) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => createTelemetryMock({ trackAuth: vi.fn() }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackAuth = vi.fn() }) vi.mock(import('@/services/dialogService')) diff --git a/src/stores/apiKeyAuthStore.integration.test.ts b/src/stores/apiKeyAuthStore.integration.test.ts index 71087dc5a34..6d27e7c3402 100644 --- a/src/stores/apiKeyAuthStore.integration.test.ts +++ b/src/stores/apiKeyAuthStore.integration.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import type { User } from 'firebase/auth' import * as firebaseAuth from 'firebase/auth' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -30,12 +31,10 @@ vi.mock(import('@/composables/useFeatureFlags'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => createTelemetryMock({ trackAuth: vi.fn() }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackAuth = vi.fn() }) vi.mock(import('@/services/dialogService'), () => ({ diff --git a/src/stores/authStore.test.ts b/src/stores/authStore.test.ts index bc8429c9b5a..cd2826be2b9 100644 --- a/src/stores/authStore.test.ts +++ b/src/stores/authStore.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { FirebaseError } from 'firebase/app' @@ -95,15 +96,10 @@ vi.mock(import('vuefire'), () => ({ vi.mock(import('firebase/auth')) const mockTrackAuth = vi.fn() -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackAuth: mockTrackAuth - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackAuth = mockTrackAuth }) let mockResetSocket: Mock diff --git a/src/stores/executionStore.test.ts b/src/stores/executionStore.test.ts index a15bfae4978..fefc28ba1bf 100644 --- a/src/stores/executionStore.test.ts +++ b/src/stores/executionStore.test.ts @@ -1,3 +1,4 @@ +import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import type { LoadedComfyWorkflow } from '@/platform/workflow/management/stores/comfyWorkflow' import { fromPartial } from '@total-typescript/shoehorn' @@ -57,18 +58,13 @@ vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: true })) -vi.mock(import('@/platform/telemetry'), async () => { - const { createTelemetryMock } = - await import('@/platform/telemetry/__mocks__/telemetry') - return { - useTelemetry: () => - createTelemetryMock({ - trackExecutionError: mockTrackExecutionError, - trackExecutionOutcome: mockTrackExecutionOutcome, - trackExecutionSuccess: mockTrackExecutionSuccess, - trackSharedWorkflowRun: mockTrackSharedWorkflowRun - }) - } +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + telemetryMock.trackExecutionError = mockTrackExecutionError + telemetryMock.trackExecutionOutcome = mockTrackExecutionOutcome + telemetryMock.trackExecutionSuccess = mockTrackExecutionSuccess + telemetryMock.trackSharedWorkflowRun = mockTrackSharedWorkflowRun }) // Remove any previous global types diff --git a/src/views/GraphView.test.ts b/src/views/GraphView.test.ts index f901084f966..62c8a2c2bcb 100644 --- a/src/views/GraphView.test.ts +++ b/src/views/GraphView.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { render, screen } from '@testing-library/vue' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' @@ -115,9 +116,11 @@ vi.mock(import('@/composables/useProgressFavicon'), () => ({ })) vi.mock(import('@/platform/distribution/types'), () => distribution) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) vi.mock( import('@/platform/updates/common/useFrontendVersionMismatchWarning'), () => ({ diff --git a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts index de925a63569..a2f6d6732f7 100644 --- a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts +++ b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import userEvent from '@testing-library/user-event' import { fireEvent, render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -13,9 +14,11 @@ import { useAgentRunModeStore } from '@/workbench/extensions/agent/stores/agent/ import DockedAgentPanel from './DockedAgentPanel.vue' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: vi.fn() })) diff --git a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts index a21bcabbcf1..15f78f629a8 100644 --- a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts +++ b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { render, screen } from '@testing-library/vue' import { createI18n } from 'vue-i18n' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -11,9 +12,11 @@ import DockedAgentPanel from './DockedAgentPanel.vue' vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) // The mocked module factory throws, so the dynamic import itself rejects - // the chunk-load failure path, distinct from a runtime error inside a diff --git a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts index ee33d420364..89599d7a969 100644 --- a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts +++ b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts @@ -1,12 +1,15 @@ +import { useTelemetry } from '@/platform/telemetry' import { beforeEach, describe, expect, it, vi } from 'vitest' import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore' import { useAgentDockMount } from './useAgentDockMount' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) const { loadDockedAgentPanel } = vi.hoisted(() => ({ loadDockedAgentPanel: vi.fn(() => ({ name: 'DockedAgentPanel' })) })) diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts index 49c7f6667c5..1fd5ea75b5a 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts @@ -1,3 +1,4 @@ +import { useTelemetry } from '@/platform/telemetry' import { getActivePinia } from 'pinia' import type { Pinia } from 'pinia' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -8,9 +9,11 @@ import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useA import { useAgentPanelStore } from './agentPanelStore' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => null -})) +vi.mock(import('@/platform/telemetry')) + +beforeEach(() => { + vi.mocked(useTelemetry).mockReturnValue(null) +}) /** * Regression pin for the duplicate Pinia id `agentPanel`. From 9f453181aa2d7b7242001d4eeda9bb24fa3a949a Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 15 Sep 2026 01:26:43 +0000 Subject: [PATCH 3/6] test: access telemetry spies through the real module API --- src/components/TopMenuSection.test.ts | 14 +- .../builder/builderViewOptions.test.ts | 16 +- src/components/builder/useBuilderSave.test.ts | 22 ++- .../common/WorkflowActionsDropdown.test.ts | 17 +-- .../TopUpCreditsDialogContentLegacy.test.ts | 23 ++- .../content/setting/CreditsPanel.test.ts | 5 - .../CancelSubscriptionDialogContent.test.ts | 55 +++---- .../graph/selectionToolbox/InfoButton.test.ts | 19 ++- .../helpcenter/HelpCenterMenuContent.test.ts | 7 - .../errors/ErrorNodeCard.test.ts | 15 +- .../parameters/SectionWidgets.test.ts | 18 +-- .../parameters/WidgetActions.test.ts | 22 +-- .../rightSidePanelTabTelemetry.test.ts | 18 +-- src/components/sidebar/SideToolbar.test.ts | 13 +- .../topbar/CurrentUserPopoverLegacy.test.ts | 5 - src/composables/auth/useAuthActions.test.ts | 22 +-- src/composables/useCoreCommands.test.ts | 17 +-- src/composables/useTemplateFiltering.test.ts | 14 +- src/platform/auth/unified/remintRetry.test.ts | 31 ++-- .../components/PricingTable.test.ts | 25 ++-- .../composables/useSubscriptionDialog.test.ts | 36 ++--- .../composables/useTopUpUrlLoader.test.ts | 19 +-- .../launchCancellationFlow.test.ts | 43 +++--- .../teamSubscriptionCheckoutUtil.test.ts | 32 ++-- ...onboardingTourStore.registeredTour.test.ts | 34 +++-- .../onboarding/onboardingTourStore.test.ts | 50 ++++--- src/platform/settings/settingStore.test.ts | 36 ++--- src/platform/support/feedbackDialog.test.ts | 14 +- src/platform/telemetry/__mocks__/index.ts | 2 +- .../useSearchQueryTracking.test.ts | 22 ++- .../workflowService.insertWorkflow.test.ts | 7 - .../core/services/workflowService.test.ts | 25 ++-- .../ShareWorkflowDialogContent.test.ts | 16 +- .../useSharedWorkflowUrlLoader.test.ts | 17 +-- .../components/InviteMembersForm.test.ts | 32 ++-- ...TopUpCreditsDialogContentWorkspace.test.ts | 58 ++++--- .../dialogs/InviteMemberDialogContent.test.ts | 45 +++--- .../useDowngradeToPersonal.test.ts | 31 ++-- .../composables/useResubscribe.test.ts | 45 +++--- .../useSubscriptionCheckout.test.ts | 125 ++++++++-------- .../composables/useWorkspaceBilling.test.ts | 26 ++-- .../stores/billingOperationStore.test.ts | 141 ++++++++++-------- .../workspace/stores/useWorkspaceAuth.test.ts | 30 ++-- .../nudge/FirstRunTourNudge.test.ts | 26 ++-- .../vueNodes/components/ImagePreview.test.ts | 13 +- .../__tests__/authTokenPriority.test.ts | 5 - .../apiKeyAuthStore.integration.test.ts | 5 - src/stores/authStore.test.ts | 27 ++-- src/stores/executionStore.test.ts | 61 +++----- 49 files changed, 646 insertions(+), 755 deletions(-) diff --git a/src/components/TopMenuSection.test.ts b/src/components/TopMenuSection.test.ts index 403224e4bdf..d1e16417872 100644 --- a/src/components/TopMenuSection.test.ts +++ b/src/components/TopMenuSection.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' /* eslint-disable testing-library/no-container */ /* eslint-disable testing-library/no-node-access */ import { getActivePinia } from 'pinia' @@ -6,11 +5,13 @@ import type { Pinia } from 'pinia' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import type { MenuItem } from 'primevue/menuitem' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { computed, defineComponent, h, nextTick, onMounted, ref } from 'vue' import type { Component } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import QueueNotificationBannerHost from '@/components/queue/QueueNotificationBannerHost.vue' import TopMenuSection from '@/components/TopMenuSection.vue' import type { @@ -81,13 +82,10 @@ vi.mock(import('@/scripts/app'), () => ({ } })) -const mockTrackUiButtonClicked = vi.hoisted(() => vi.fn()) - vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = mockTrackUiButtonClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) type WrapperOptions = { pinia?: Pinia @@ -285,7 +283,7 @@ describe('TopMenuSection', () => { screen.getByRole('button', { name: 'Toggle properties panel' }) ) - expect(mockTrackUiButtonClicked).toHaveBeenCalledWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'right_side_panel_opened', element_group: 'top_menu' }) diff --git a/src/components/builder/builderViewOptions.test.ts b/src/components/builder/builderViewOptions.test.ts index 19637c1bcd0..c2cc42cc690 100644 --- a/src/components/builder/builderViewOptions.test.ts +++ b/src/components/builder/builderViewOptions.test.ts @@ -1,20 +1,18 @@ -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { app } from '@/scripts/app' import { createMockLoadedWorkflow } from '@/utils/__tests__/litegraphTestUtils' import { setWorkflowDefaultView } from './builderViewOptions' -const mockTrackDefaultViewSet = vi.hoisted(() => vi.fn()) - vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackDefaultViewSet = mockTrackDefaultViewSet -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/scripts/app'), () => { const rootGraph = { extra: {} } @@ -56,12 +54,12 @@ describe('setWorkflowDefaultView', () => { it('tracks telemetry with correct default_view', () => { const workflow = createMockLoadedWorkflow() setWorkflowDefaultView(workflow, true) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'app' }) setWorkflowDefaultView(workflow, false) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'graph' }) }) diff --git a/src/components/builder/useBuilderSave.test.ts b/src/components/builder/useBuilderSave.test.ts index dbf2ccd5966..970b33cc74a 100644 --- a/src/components/builder/useBuilderSave.test.ts +++ b/src/components/builder/useBuilderSave.test.ts @@ -1,8 +1,9 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { fromPartial } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { useAppModeStore } from '@/stores/appModeStore' import { useDialogStore } from '@/stores/dialogStore' @@ -16,8 +17,7 @@ beforeEach(() => { const mockSetMode = vi.hoisted(() => vi.fn()) const mockToastErrorHandler = vi.hoisted(() => vi.fn()) -const mockTrackEnterLinear = vi.hoisted(() => vi.fn()) -const mockTrackDefaultViewSet = vi.hoisted(() => vi.fn()) + const mockSaveWorkflow = vi.hoisted(() => vi.fn<() => Promise>()) const mockSaveWorkflowAs = vi.hoisted(() => vi.fn<() => Promise>() @@ -41,10 +41,8 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackEnterLinear = mockTrackEnterLinear - telemetryMock.trackDefaultViewSet = mockTrackDefaultViewSet -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('@/platform/workflow/core/services/workflowService'), @@ -215,7 +213,7 @@ describe('useBuilderSave', () => { isApp: true } ) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'app' }) }) @@ -233,7 +231,7 @@ describe('useBuilderSave', () => { isApp: false } ) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'graph' }) }) @@ -244,7 +242,7 @@ describe('useBuilderSave', () => { await onSave('new-name', false) - expect(mockTrackDefaultViewSet).not.toHaveBeenCalled() + expect(dispatcher.trackDefaultViewSet).not.toHaveBeenCalled() expect(useDialogStore().closeDialog).not.toHaveBeenCalled() }) @@ -356,7 +354,7 @@ describe('useBuilderSave', () => { expect(useDialogStore().closeDialog).toHaveBeenCalledWith({ key: SUCCESS_DIALOG_KEY }) - expect(mockTrackEnterLinear).toHaveBeenCalledWith({ + expect(dispatcher.trackEnterLinear).toHaveBeenCalledWith({ source: 'app_builder' }) expect(mockSetMode).toHaveBeenCalledWith('app') diff --git a/src/components/common/WorkflowActionsDropdown.test.ts b/src/components/common/WorkflowActionsDropdown.test.ts index 0553bab3442..ad56787db11 100644 --- a/src/components/common/WorkflowActionsDropdown.test.ts +++ b/src/components/common/WorkflowActionsDropdown.test.ts @@ -1,10 +1,11 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { KeybindingImpl } from '@/platform/keybindings/keybinding' import { useKeybindingStore } from '@/platform/keybindings/keybindingStore' import { useAppModeStore } from '@/stores/appModeStore' @@ -23,15 +24,13 @@ beforeEach(() => { }) const spies = vi.hoisted(() => ({ - trackUiButtonClicked: vi.fn(), markAsSeen: vi.fn() })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = spies.trackUiButtonClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/composables/useWorkflowActionsMenu'), async () => { const { ref } = await import('vue') @@ -162,7 +161,7 @@ describe('WorkflowActionsDropdown', () => { expect( screen.getByRole('button', { name: /workflow actions/ }) ).toHaveAttribute('aria-expanded', 'false') - expect(spies.trackUiButtonClicked).not.toHaveBeenCalled() + expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() expect(spies.markAsSeen).not.toHaveBeenCalled() }) @@ -175,7 +174,7 @@ describe('WorkflowActionsDropdown', () => { expect(vi.mocked(useCommandStore().execute)).not.toHaveBeenCalled() expect(active).toHaveAttribute('aria-expanded', 'true') expect(spies.markAsSeen).toHaveBeenCalled() - expect(spies.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'test', element_group: 'workflow_actions' }) @@ -208,7 +207,7 @@ describe('WorkflowActionsDropdown', () => { expect( screen.getByRole('button', { name: /workflow actions/ }) ).toHaveAttribute('aria-expanded', 'false') - expect(spies.trackUiButtonClicked).not.toHaveBeenCalled() + expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() }) it('lets non-trigger keys bubble past the inactive segment', async () => { diff --git a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts index b7fbccd91d8..7efd638be46 100644 --- a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts +++ b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts @@ -1,9 +1,10 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { AuthStoreError } from '@/stores/authStore' import { useDialogStore } from '@/stores/dialogStore' @@ -12,8 +13,7 @@ import TopUpCreditsDialogContentLegacy from './TopUpCreditsDialogContentLegacy.v const mockPurchaseCreditsDirect = vi.fn() const mockShowSettings = vi.fn() const mockToastAdd = vi.fn() -const mockTrackTopUpPurchase = vi.fn() -const mockTrackBillingEvent = vi.fn() + const mockIsSubscriptionEnabled = vi.fn(() => true) const mockShouldUseWorkspaceBilling = vi.hoisted(() => ({ value: false })) @@ -51,11 +51,8 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackApiCreditTopupButtonPurchaseClicked = - mockTrackTopUpPurchase - telemetryMock.trackBillingEvent = mockTrackBillingEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const mockClearPendingTopup = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ @@ -187,7 +184,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -212,7 +209,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -227,7 +224,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -241,7 +238,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', diff --git a/src/components/dialog/content/setting/CreditsPanel.test.ts b/src/components/dialog/content/setting/CreditsPanel.test.ts index 600e2139350..5f4bb29194a 100644 --- a/src/components/dialog/content/setting/CreditsPanel.test.ts +++ b/src/components/dialog/content/setting/CreditsPanel.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -50,10 +49,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackHelpResourceClicked = vi.fn() -}) - vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ buildDocsUrl: () => 'https://docs.comfy.org', diff --git a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts index cc6ebdfbf89..606adbd5a9c 100644 --- a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts +++ b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts @@ -1,9 +1,10 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import enMessages from '@/locales/en/main.json' with { type: 'json' } import { useDialogStore } from '@/stores/dialogStore' @@ -54,7 +55,7 @@ const mockFetchStatus = vi.hoisted(() => vi.fn()) const mockToastAdd = vi.hoisted(() => vi.fn()) const mockTier = vi.hoisted(() => ({ value: 'STANDARD' as string | null })) -const mockTrackCancellation = vi.hoisted(() => vi.fn()) + const mockShouldUseWorkspaceBilling = vi.hoisted(() => ({ value: false })) const mockCanCancel = vi.hoisted(() => ({ value: true })) const mockCanManageSubscriptionLifecycle = vi.hoisted(() => ({ value: true })) @@ -104,9 +105,8 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackSubscriptionCancellation = mockTrackCancellation -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports @@ -159,12 +159,15 @@ describe('CancelSubscriptionDialogContent', () => { renderComponent() - expect(mockTrackCancellation).toHaveBeenCalledWith('flow_opened', { - source: 'cancel_plan_menu', - current_tier: 'standard', - cycle: 'yearly', - end_date: '2026-08-01T00:00:00.000Z' - }) + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( + 'flow_opened', + { + source: 'cancel_plan_menu', + current_tier: 'standard', + cycle: 'yearly', + end_date: '2026-08-01T00:00:00.000Z' + } + ) }) it('does not repeat flow_opened when continuing a fallback flow', () => { @@ -172,7 +175,7 @@ describe('CancelSubscriptionDialogContent', () => { renderComponent({ flowAlreadyOpened: true }) - expect(mockTrackCancellation).not.toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( 'flow_opened', expect.anything() ) @@ -191,11 +194,11 @@ describe('CancelSubscriptionDialogContent', () => { expect(vi.mocked(useDialogStore().closeDialog)).toHaveBeenCalled() ) unmount() - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( 'confirmed', expect.objectContaining({ current_tier: 'standard' }) ) - expect(mockTrackCancellation).not.toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( 'abandoned', expect.anything() ) @@ -211,12 +214,12 @@ describe('CancelSubscriptionDialogContent', () => { ) await waitFor(() => - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( 'failed', expect.not.objectContaining({ error_message: expect.anything() }) ) ) - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( 'confirmed', expect.anything() ) @@ -237,7 +240,7 @@ describe('CancelSubscriptionDialogContent', () => { expect.objectContaining({ severity: 'error' }) ) ) - expect(mockTrackCancellation).not.toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( 'failed', expect.anything() ) @@ -255,7 +258,7 @@ describe('CancelSubscriptionDialogContent', () => { key: 'cancel-subscription' }) unmount() - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( 'abandoned', expect.objectContaining({ current_tier: 'standard' }) ) @@ -266,10 +269,10 @@ describe('CancelSubscriptionDialogContent', () => { mockSubscription.value = null const { unmount } = renderComponent() - mockTrackCancellation.mockClear() + dispatcher.trackSubscriptionCancellation.mockClear() unmount() - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( 'abandoned', expect.objectContaining({ current_tier: 'standard' }) ) @@ -331,7 +334,7 @@ describe('CancelSubscriptionDialogContent', () => { ) expect(mockCancelSubscription).not.toHaveBeenCalled() - expect(mockTrackCancellation).not.toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( 'confirmed', expect.anything() ) @@ -368,7 +371,7 @@ describe('CancelSubscriptionDialogContent', () => { ) expect(mockCancelSubscription).not.toHaveBeenCalled() - expect(mockTrackCancellation).not.toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( 'confirmed', expect.anything() ) @@ -393,11 +396,13 @@ describe('CancelSubscriptionDialogContent', () => { key: 'cancel-subscription' }) expect( - mockTrackCancellation.mock.calls.some(([stage]) => stage === 'failed') + dispatcher.trackSubscriptionCancellation.mock.calls.some( + ([stage]) => stage === 'failed' + ) ).toBe(false) unmount() - expect(mockTrackCancellation).not.toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( 'abandoned', expect.anything() ) diff --git a/src/components/graph/selectionToolbox/InfoButton.test.ts b/src/components/graph/selectionToolbox/InfoButton.test.ts index 92154c65132..bd1c82e565f 100644 --- a/src/components/graph/selectionToolbox/InfoButton.test.ts +++ b/src/components/graph/selectionToolbox/InfoButton.test.ts @@ -1,17 +1,17 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import PrimeVue from 'primevue/config' import Tooltip from 'primevue/tooltip' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import InfoButton from '@/components/graph/selectionToolbox/InfoButton.vue' import Button from '@/components/ui/button/Button.vue' -const { openNodeInfoMock, trackUiButtonClickedMock } = vi.hoisted(() => ({ - openNodeInfoMock: vi.fn(), - trackUiButtonClickedMock: vi.fn() +const { openNodeInfoMock } = vi.hoisted(() => ({ + openNodeInfoMock: vi.fn() })) vi.mock(import('@/composables/graph/useSelectionState'), () => ({ @@ -22,9 +22,8 @@ vi.mock(import('@/composables/graph/useSelectionState'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = trackUiButtonClickedMock -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) describe('InfoButton', () => { const i18n = createI18n({ @@ -64,7 +63,7 @@ describe('InfoButton', () => { await clickNodeInfoButton() expect(openNodeInfoMock).toHaveBeenCalled() - expect(trackUiButtonClickedMock).toHaveBeenCalledWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'selection_toolbox_node_info_opened', element_group: 'selection_toolbox' }) @@ -77,6 +76,6 @@ describe('InfoButton', () => { await clickNodeInfoButton() expect(openNodeInfoMock).toHaveBeenCalled() - expect(trackUiButtonClickedMock).not.toHaveBeenCalled() + expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() }) }) diff --git a/src/components/helpcenter/HelpCenterMenuContent.test.ts b/src/components/helpcenter/HelpCenterMenuContent.test.ts index 67489704c12..dc6b5471f4b 100644 --- a/src/components/helpcenter/HelpCenterMenuContent.test.ts +++ b/src/components/helpcenter/HelpCenterMenuContent.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -47,12 +46,6 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackHelpResourceClicked = vi.fn() - telemetryMock.trackHelpCenterOpened = vi.fn() - telemetryMock.trackHelpCenterClosed = vi.fn() -}) - vi.mock(import('@/utils/envUtil'), () => ({ electronAPI: () => null })) diff --git a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts index a170f7dee59..f4f3c22e813 100644 --- a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts +++ b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts @@ -1,11 +1,12 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { getActivePinia } from 'pinia' import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' import PrimeVue from 'primevue/config' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { resolveRunErrorMessage } from '@/platform/errorCatalog/errorMessageResolver' import { useCommandStore } from '@/stores/commandStore' import { useSystemStatsStore } from '@/stores/systemStatsStore' @@ -40,14 +41,10 @@ vi.mock(import('@/utils/errorReportUtil'), () => ({ generateErrorReport: (data: unknown) => mockGenerateErrorReport(data) })) -const mockTrackHelpResourceClicked = vi.fn() - vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = vi.fn() - telemetryMock.trackHelpResourceClicked = mockTrackHelpResourceClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: vi.fn(() => ({ @@ -405,7 +402,7 @@ describe('ErrorNodeCard.vue', () => { expect(useCommandStore().execute).toHaveBeenCalledWith( 'Comfy.ContactSupport' ) - expect(mockTrackHelpResourceClicked).toHaveBeenCalledWith( + expect(dispatcher.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'help_feedback', source: 'error_dialog' diff --git a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts index a5917f790af..42ecf023a5c 100644 --- a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts +++ b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts @@ -1,11 +1,12 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' import { fromPartial } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { defineComponent } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { promoteValueWidgetViaSubgraphInput } from '@/core/graph/subgraph/promotionUtils' import { LGraphNode } from '@/lib/litegraph/src/litegraph' import type { LGraph } from '@/lib/litegraph/src/litegraph' @@ -24,19 +25,14 @@ import { getExecutionIdByNode } from '@/utils/graphTraversalUtil' import SectionWidgets from './SectionWidgets.vue' -const { mockTrackUiButtonClicked } = vi.hoisted(() => ({ - mockTrackUiButtonClicked: vi.fn() -})) - const setDirty = vi.fn() const getNodeById = vi.fn() const animateToBounds = vi.fn() vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = mockTrackUiButtonClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const WidgetItemStub = defineComponent({ inheritAttrs: false, @@ -239,7 +235,7 @@ describe('SectionWidgets', () => { await user.click(screen.getByRole('button', { name: 'Locate' })) - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_locate_node_clicked', element_group: 'right_side_panel_nodes' }) @@ -271,7 +267,7 @@ describe('SectionWidgets', () => { await user.click(screen.getByRole('button', { name: 'Reset all' })) - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_reset_all_parameters_clicked', element_group: 'right_side_panel_nodes' }) diff --git a/src/components/rightSidePanel/parameters/WidgetActions.test.ts b/src/components/rightSidePanel/parameters/WidgetActions.test.ts index 4a8ed67788f..c1ca56cf435 100644 --- a/src/components/rightSidePanel/parameters/WidgetActions.test.ts +++ b/src/components/rightSidePanel/parameters/WidgetActions.test.ts @@ -1,12 +1,13 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { fromPartial, fromAny } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import type { Slots } from 'vue' import { h } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { promoteWidget } from '@/core/graph/subgraph/promotionUtils' import type { LGraphNode } from '@/lib/litegraph/src/litegraph' import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' @@ -19,19 +20,14 @@ import { widgetId } from '@/types/widgetId' import WidgetActions from './WidgetActions.vue' -const { mockTrackWidgetFavoriteToggled } = vi.hoisted(() => ({ - mockTrackWidgetFavoriteToggled: vi.fn() -})) - vi.mock(import('@/core/graph/subgraph/promotionUtils'), () => ({ promoteWidget: vi.fn() })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackWidgetFavoriteToggled = mockTrackWidgetFavoriteToggled -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ @@ -229,7 +225,9 @@ describe('WidgetActions', () => { await user.click(screen.getByRole('button', { name: /Favorite/ })) - expect(mockTrackWidgetFavoriteToggled).toHaveBeenCalledExactlyOnceWith({ + expect( + dispatcher.trackWidgetFavoriteToggled + ).toHaveBeenCalledExactlyOnceWith({ node_type: 'TestNode', widget_name: 'test_widget', widget_type: 'number', @@ -251,7 +249,9 @@ describe('WidgetActions', () => { await user.click(screen.getByRole('button', { name: /Unfavorite/ })) - expect(mockTrackWidgetFavoriteToggled).toHaveBeenCalledExactlyOnceWith({ + expect( + dispatcher.trackWidgetFavoriteToggled + ).toHaveBeenCalledExactlyOnceWith({ node_type: 'TestNode', widget_name: 'test_widget', widget_type: 'number', diff --git a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts index 263df294f82..049b340eb90 100644 --- a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts +++ b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts @@ -1,15 +1,11 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, describe, expect, it, vi } from 'vitest' -const { mockTrackUiButtonClicked } = vi.hoisted(() => ({ - mockTrackUiButtonClicked: vi.fn() -})) +import { useTelemetry } from '@/platform/telemetry' vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = mockTrackUiButtonClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) import { trackRightSidePanelTabOpened } from './rightSidePanelTabTelemetry' @@ -17,7 +13,7 @@ describe('trackRightSidePanelTabOpened', () => { it('tracks opening the settings tab', () => { trackRightSidePanelTabOpened('settings') - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_settings_tab_opened', element_group: 'right_side_panel' }) @@ -26,7 +22,7 @@ describe('trackRightSidePanelTabOpened', () => { it('tracks opening the info tab', () => { trackRightSidePanelTabOpened('info') - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_info_tab_opened', element_group: 'right_side_panel' }) @@ -37,7 +33,7 @@ describe('trackRightSidePanelTabOpened', () => { (tab) => { trackRightSidePanelTabOpened(tab) - expect(mockTrackUiButtonClicked).not.toHaveBeenCalled() + expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() } ) }) diff --git a/src/components/sidebar/SideToolbar.test.ts b/src/components/sidebar/SideToolbar.test.ts index 100e09b653f..cc60a58855a 100644 --- a/src/components/sidebar/SideToolbar.test.ts +++ b/src/components/sidebar/SideToolbar.test.ts @@ -1,11 +1,12 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import PrimeVue from 'primevue/config' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import type { ComponentProps } from 'vue-component-type-helpers' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { useSettingStore } from '@/platform/settings/settingStore' import { useCommandStore } from '@/stores/commandStore' import { useUserStore } from '@/stores/userStore' @@ -30,7 +31,6 @@ beforeEach(() => { }) const spies = vi.hoisted(() => ({ - trackUiButtonClicked: vi.fn(), toggleAssets: vi.fn() })) @@ -42,9 +42,8 @@ vi.mock(import('@/platform/distribution/types'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = spies.trackUiButtonClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const i18n = createI18n({ legacy: false, @@ -151,7 +150,7 @@ describe('SideToolbar', () => { await user.click(screen.getByRole('button', { name: 'Assets' })) - expect(spies.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'sidebar_tab_assets_media_selected', element_group: 'sidebar' }) diff --git a/src/components/topbar/CurrentUserPopoverLegacy.test.ts b/src/components/topbar/CurrentUserPopoverLegacy.test.ts index 5f13311a132..a70abe4a721 100644 --- a/src/components/topbar/CurrentUserPopoverLegacy.test.ts +++ b/src/components/topbar/CurrentUserPopoverLegacy.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { getActivePinia } from 'pinia' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' @@ -122,10 +121,6 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackAddApiCreditButtonClicked = vi.fn() -}) - describe('CurrentUserPopoverLegacy', () => { beforeEach(() => { mockCanAccessSubscriptionFeatures.value = true diff --git a/src/composables/auth/useAuthActions.test.ts b/src/composables/auth/useAuthActions.test.ts index e6e49ec9094..f5371e1a707 100644 --- a/src/composables/auth/useAuthActions.test.ts +++ b/src/composables/auth/useAuthActions.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' import { useToastStore } from '@/platform/updates/common/toastStore' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' @@ -11,7 +10,9 @@ import { } from 'firebase/auth' import type { UserCredential } from 'firebase/auth' import { fromPartial } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import { useAuthActions } from '@/composables/auth/useAuthActions' import enLocale from '@/locales/en/main.json' @@ -36,7 +37,7 @@ const mockDialogService = vi.hoisted(() => ({ })) const mockToastErrorHandler = vi.hoisted(() => vi.fn()) -const mockTrackAuthFailed = vi.hoisted(() => vi.fn()) + const mockStartPendingTopup = vi.hoisted(() => vi.fn()) const mockDistributionState = vi.hoisted(() => ({ isCloud: false })) const mockBillingState = vi.hoisted(() => ({ @@ -80,9 +81,8 @@ vi.mock(import('@/platform/distribution/types'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackAuthFailed = mockTrackAuthFailed -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ startPendingTopup: mockStartPendingTopup }) @@ -387,7 +387,7 @@ describe('useAuthActions auth flow error telemetry', () => { signInWithEmail('user@example.com', 'password') ).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/user-not-found', auth_action: 'email_sign_in' }) @@ -407,7 +407,7 @@ describe('useAuthActions auth flow error telemetry', () => { signUpWithEmail('user@example.com', 'password') ).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'unknown', auth_action: 'email_sign_up' }) @@ -420,7 +420,7 @@ describe('useAuthActions auth flow error telemetry', () => { await expect(signInWithGoogle({ isNewUser: true })).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/popup-closed-by-user', auth_action: 'google_sign_up' }) @@ -433,7 +433,7 @@ describe('useAuthActions auth flow error telemetry', () => { await expect(signInWithGithub({ isNewUser: true })).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/popup-closed-by-user', auth_action: 'github_sign_up' }) @@ -446,7 +446,7 @@ describe('useAuthActions auth flow error telemetry', () => { await logout() - expect(mockTrackAuthFailed).not.toHaveBeenCalled() + expect(dispatcher.trackAuthFailed).not.toHaveBeenCalled() }) }) diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index 0bf05a823ff..52235b2adfb 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -1,6 +1,7 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import { useCoreCommands } from '@/composables/useCoreCommands' import { useExternalLink } from '@/composables/useExternalLink' @@ -117,14 +118,10 @@ vi.mock(import('@/services/litegraphService'), () => ({ })) })) -const mockTrackHelpResourceClicked = vi.hoisted(() => vi.fn()) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackHelpResourceClicked = mockTrackHelpResourceClicked - telemetryMock.trackRunButton = vi.fn() - telemetryMock.trackWorkflowExecution = vi.fn() -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const mockShowAbout = vi.hoisted(() => vi.fn()) const mockShowSettings = vi.hoisted(() => vi.fn()) @@ -747,7 +744,7 @@ describe('useCoreCommands', () => { it('Comfy.Help.OpenComfyUIIssues opens the GitHub issues URL and tracks telemetry', async () => { await findCmd('Comfy.Help.OpenComfyUIIssues').function() - expect(mockTrackHelpResourceClicked).toHaveBeenCalledWith( + expect(dispatcher.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'github', is_external: true, @@ -760,7 +757,7 @@ describe('useCoreCommands', () => { it('Comfy.Help.OpenComfyOrgDiscord opens the Discord URL and tracks telemetry', async () => { await findCmd('Comfy.Help.OpenComfyOrgDiscord').function() - expect(mockTrackHelpResourceClicked).toHaveBeenCalledWith( + expect(dispatcher.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'discord' }) diff --git a/src/composables/useTemplateFiltering.test.ts b/src/composables/useTemplateFiltering.test.ts index 75ee81487fc..0915c8028c9 100644 --- a/src/composables/useTemplateFiltering.test.ts +++ b/src/composables/useTemplateFiltering.test.ts @@ -1,12 +1,13 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useSettingStore } from '@/platform/settings/settingStore' import { useTemplateRankingStore } from '@/stores/templateRankingStore' import { useSystemStatsStore } from '@/stores/systemStatsStore' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick, ref } from 'vue' import { fromPartial } from '@total-typescript/shoehorn' import { until } from '@vueuse/core' +import { useTelemetry } from '@/platform/telemetry' + import type { TemplateInfo } from '@/platform/workflow/templates/types/template' import { TemplateIncludeOnDistributionEnum } from '@/platform/workflow/templates/types/template' import { useTemplateFiltering } from '@/composables/useTemplateFiltering' @@ -18,13 +19,10 @@ let defaultRankingStore: ReturnType let mockSystemStatsStore: ReturnType -const trackTemplateFilterChanged = vi.hoisted(() => vi.fn()) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackTemplateFilterChanged = trackTemplateFilterChanged - telemetryMock.trackSearchQuery = vi.fn() -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('@/platform/telemetry/searchQuery/useSearchQueryTracking'), @@ -613,7 +611,7 @@ describe('useTemplateFiltering', () => { await vi.runOnlyPendingTimersAsync() expect( - trackTemplateFilterChanged, + dispatcher.trackTemplateFilterChanged, 'telemetry must report the search default, not the persisted browse sort' ).toHaveBeenLastCalledWith( expect.objectContaining({ sort_by: 'popular' }) diff --git a/src/platform/auth/unified/remintRetry.test.ts b/src/platform/auth/unified/remintRetry.test.ts index 96a42f1c2ce..dd891fe565d 100644 --- a/src/platform/auth/unified/remintRetry.test.ts +++ b/src/platform/auth/unified/remintRetry.test.ts @@ -1,25 +1,24 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkspaceAuthStore } from '@/platform/workspace/stores/workspaceAuthStore' import type { AxiosAdapter } from 'axios' import axios, { AxiosError } from 'axios' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import { attachUnifiedRemintInterceptor, fetchWithUnifiedRemint } from '@/platform/auth/unified/remintRetry' -const { mockRemint, mockTrackUnifiedAuthRetry, flagState } = vi.hoisted(() => ({ +const { mockRemint, flagState } = vi.hoisted(() => ({ mockRemint: vi.fn(), - mockTrackUnifiedAuthRetry: vi.fn(), flagState: { unifiedCloudAuthEnabled: true } })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUnifiedAuthRetry = mockTrackUnifiedAuthRetry -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/composables/useFeatureFlags'), () => ({ useFeatureFlags: () => ({ @@ -74,7 +73,7 @@ describe('fetchWithUnifiedRemint', () => { const retryHeaders = new Headers(mockFetch.mock.calls[1][1].headers) expect(retryHeaders.get('Authorization')).toBe('Bearer tokenB') expect(retryHeaders.get('Comfy-User')).toBe('u1') - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'succeeded', final_status: 200 @@ -97,7 +96,7 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(secondUnauthorized) expect(mockFetch).toHaveBeenCalledTimes(2) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -117,7 +116,7 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).not.toHaveBeenCalled() + expect(dispatcher.trackUnifiedAuthRetry).not.toHaveBeenCalled() }) it('does not retry a non-401 response', async () => { @@ -148,7 +147,7 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -206,7 +205,7 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -246,7 +245,7 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -351,7 +350,7 @@ describe('attachUnifiedRemintInterceptor', () => { expect(String(adapter.mock.calls[1][0].headers.Authorization)).toBe( 'Bearer tokenB' ) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ transport: 'axios', outcome: 'succeeded', final_status: 200 @@ -370,7 +369,7 @@ describe('attachUnifiedRemintInterceptor', () => { expect(adapter).toHaveBeenCalledTimes(2) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ transport: 'axios', outcome: 'failed', final_status: 401, @@ -390,7 +389,7 @@ describe('attachUnifiedRemintInterceptor', () => { expect(adapter).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).not.toHaveBeenCalled() + expect(dispatcher.trackUnifiedAuthRetry).not.toHaveBeenCalled() }) it('does not re-mint a request flagged __skipUnifiedRemint (acceptInvite)', async () => { diff --git a/src/platform/cloud/subscription/components/PricingTable.test.ts b/src/platform/cloud/subscription/components/PricingTable.test.ts index 0b119d7c80a..2271ca89425 100644 --- a/src/platform/cloud/subscription/components/PricingTable.test.ts +++ b/src/platform/cloud/subscription/components/PricingTable.test.ts @@ -1,11 +1,12 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { computed, nextTick, ref } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import PricingTable from '@/platform/cloud/subscription/components/PricingTable.vue' import Button from '@/components/ui/button/Button.vue' import type { IngestSubscriptionTier } from '@/platform/cloud/subscription/constants/tierPricing' @@ -29,8 +30,6 @@ const mockSubscriptionTier = ref(null) const mockSubscriptionDuration = ref<'MONTHLY' | 'ANNUAL'>('MONTHLY') const mockAccessBillingPortal = vi.fn() const mockReportError = vi.fn() -const mockTrackBeginCheckout = vi.fn() -const mockTrackBillingEvent = vi.fn() const mockGetAuthHeader = vi.fn(() => Promise.resolve({ Authorization: 'Bearer test-token' as const }) @@ -117,10 +116,8 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackBeginCheckout = mockTrackBeginCheckout - telemetryMock.trackBillingEvent = mockTrackBillingEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('@/platform/telemetry/utils/checkoutAttribution'), @@ -266,7 +263,7 @@ describe('PricingTable', () => { await userEvent.click(creatorButton!) await flushPromises() - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-123', tier: 'creator', cycle: 'yearly', @@ -352,7 +349,7 @@ describe('PricingTable', () => { expect( window.localStorage.getItem(PENDING_SUBSCRIPTION_CHECKOUT_STORAGE_KEY) ).toBeNull() - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() + expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() }) it('should use the latest userId value when it changes after mount', async () => { @@ -372,8 +369,8 @@ describe('PricingTable', () => { await userEvent.click(creatorButton!) await flushPromises() - expect(mockTrackBeginCheckout).toHaveBeenCalledTimes(1) - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(dispatcher.trackBeginCheckout).toHaveBeenCalledTimes(1) + expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-late', tier: 'creator', cycle: 'yearly', @@ -468,7 +465,7 @@ describe('PricingTable', () => { await userEvent.click(subscribeButton!) await flushPromises() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -497,7 +494,7 @@ describe('PricingTable', () => { await userEvent.click(subscribeButton!) await flushPromises() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'network' }) ) }) diff --git a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts index 3d941350e06..cac71a77c25 100644 --- a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts +++ b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts @@ -1,9 +1,10 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useDialogStore } from '@/stores/dialogStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' import { useAuthStore } from '@/stores/authStore' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import type { SubscriptionInfo } from '@/composables/billing/types' import type { @@ -21,7 +22,6 @@ import { useSubscriptionDialog } from './useSubscriptionDialog' const mockCloseDialog = vi.fn() const mockShowLayoutDialog = vi.fn() const mockShowTeamWorkspacesDialog = vi.fn() -const mockTrackSubscription = vi.hoisted(() => vi.fn()) const mockIsFreeTier = vi.hoisted(() => ({ value: false })) const mockTier = vi.hoisted(() => ({ value: 'FREE' as string | null })) @@ -108,9 +108,8 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackSubscription = mockTrackSubscription -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('@/platform/workspace/composables/useWorkspaceUI'), @@ -336,7 +335,7 @@ describe('useSubscriptionDialog', () => { expect(props).not.toHaveProperty('initialCheckout') const { dialogComponentProps } = mockShowLayoutDialog.mock.calls[0][0] expectRekaPricingDialogProps(dialogComponentProps) - expect(mockTrackSubscription).toHaveBeenCalledWith( + expect(dispatcher.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'deep_link' }) ) @@ -434,10 +433,13 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'upgrade_to_add_credits' }) - expect(mockTrackSubscription).toHaveBeenCalledWith('modal_opened', { - current_tier: 'standard', - reason: 'upgrade_to_add_credits' - }) + expect(dispatcher.trackSubscription).toHaveBeenCalledWith( + 'modal_opened', + { + current_tier: 'standard', + reason: 'upgrade_to_add_credits' + } + ) }) it('tracks modal_opened on the workspace (unified) path too', () => { @@ -446,7 +448,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) - expect(mockTrackSubscription).toHaveBeenCalledWith( + expect(dispatcher.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'subscribe_to_run' }) ) @@ -461,7 +463,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) expect(mockShowLayoutDialog).toHaveBeenCalledTimes(1) - expect(mockTrackSubscription).not.toHaveBeenCalled() + expect(dispatcher.trackSubscription).not.toHaveBeenCalled() }) it('shows the read-only member dialog for out-of-credits too, not the pricing table', () => { @@ -485,7 +487,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) - expect(mockTrackSubscription).not.toHaveBeenCalled() + expect(dispatcher.trackSubscription).not.toHaveBeenCalled() }) }) @@ -514,7 +516,7 @@ describe('useSubscriptionDialog', () => { expect(mockShowLayoutDialog).toHaveBeenCalledWith( expect.objectContaining({ key: 'subscription-required' }) ) - expect(mockTrackSubscription).not.toHaveBeenCalled() + expect(dispatcher.trackSubscription).not.toHaveBeenCalled() }) it('falls back to the pricing table for a non-free-tier user', () => { @@ -547,8 +549,8 @@ describe('useSubscriptionDialog', () => { show({ reason: 'out_of_credits' }) - expect(mockTrackSubscription).toHaveBeenCalledTimes(1) - expect(mockTrackSubscription).toHaveBeenCalledWith( + expect(dispatcher.trackSubscription).toHaveBeenCalledTimes(1) + expect(dispatcher.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'out_of_credits' }) ) diff --git a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts index b6e82a53fdb..a2d8553051f 100644 --- a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts +++ b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts @@ -1,6 +1,7 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { fromAny } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import { useTopUpUrlLoader } from './useTopUpUrlLoader' @@ -54,14 +55,10 @@ vi.mock( }) ) -const mockTrackAddApiCreditButtonClicked = vi.hoisted(() => vi.fn()) - vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackAddApiCreditButtonClicked = - mockTrackAddApiCreditButtonClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) describe('useTopUpUrlLoader', () => { beforeEach(() => { @@ -99,7 +96,7 @@ describe('useTopUpUrlLoader', () => { const { loadTopUpFromUrl } = useTopUpUrlLoader() await loadTopUpFromUrl() - expect(mockTrackAddApiCreditButtonClicked).toHaveBeenCalledWith({ + expect(dispatcher.trackAddApiCreditButtonClicked).toHaveBeenCalledWith({ source: 'deep_link' }) }) @@ -138,7 +135,7 @@ describe('useTopUpUrlLoader', () => { await loadTopUpFromUrl() expect(mockShowTopUpCreditsDialog).not.toHaveBeenCalled() - expect(mockTrackAddApiCreditButtonClicked).not.toHaveBeenCalled() + expect(dispatcher.trackAddApiCreditButtonClicked).not.toHaveBeenCalled() }) it('opens the subscription path without top-up telemetry', async () => { @@ -150,7 +147,7 @@ describe('useTopUpUrlLoader', () => { await loadTopUpFromUrl() expect(mockShowTopUpCreditsDialog).toHaveBeenCalledOnce() - expect(mockTrackAddApiCreditButtonClicked).not.toHaveBeenCalled() + expect(dispatcher.trackAddApiCreditButtonClicked).not.toHaveBeenCalled() }) it('denies, strips, and clears together when the user is not eligible', async () => { diff --git a/src/platform/cloud/subscription/launchCancellationFlow.test.ts b/src/platform/cloud/subscription/launchCancellationFlow.test.ts index 9a47d71d098..052e7820ad3 100644 --- a/src/platform/cloud/subscription/launchCancellationFlow.test.ts +++ b/src/platform/cloud/subscription/launchCancellationFlow.test.ts @@ -1,6 +1,7 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import type { SubscriptionInfo } from '@/composables/billing/types' import type { @@ -19,8 +20,7 @@ const mocks = vi.hoisted(() => ({ activeWorkspaceId: 'workspace-1' as string | null, billingRail: 'stripe' as BillingRail | null, cancelSubscription: vi.fn(), - prepare: vi.fn(), - trackCancellation: vi.fn() + prepare: vi.fn() })) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ @@ -42,9 +42,8 @@ vi.mock(import('@/platform/cloud/churnkey/churnkeyClient'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackSubscriptionCancellation = mocks.trackCancellation -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) import { launchCancellationFlow } from './launchCancellationFlow' @@ -110,7 +109,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback }) expect(showFallback).toHaveBeenCalledOnce() - expect(mocks.trackCancellation).not.toHaveBeenCalled() + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalled() }) it('cancels workspace billing through the existing API callback', async () => { @@ -128,13 +127,17 @@ describe('launchCancellationFlow', () => { }) expect(mocks.cancelSubscription).toHaveBeenCalledOnce() - expect(mocks.trackCancellation).toHaveBeenNthCalledWith(1, 'flow_opened', { - source: 'cancel_plan_menu', - current_tier: 'pro', - cycle: 'yearly', - end_date: '2026-08-02T00:00:00Z' - }) - expect(mocks.trackCancellation).toHaveBeenNthCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenNthCalledWith( + 1, + 'flow_opened', + { + source: 'cancel_plan_menu', + current_tier: 'pro', + cycle: 'yearly', + end_date: '2026-08-02T00:00:00Z' + } + ) + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenNthCalledWith( 2, 'confirmed', expect.objectContaining({ @@ -150,7 +153,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: vi.fn() }) - expect(mocks.trackCancellation).toHaveBeenLastCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenLastCalledWith( 'abandoned', expect.objectContaining({ cycle: 'yearly', @@ -169,7 +172,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: preparationFallback }) expect(preparationFallback).toHaveBeenCalledWith() - expect(mocks.trackCancellation).not.toHaveBeenCalled() + expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalled() expect(warn).toHaveBeenCalledWith( 'Failed to prepare Churnkey cancellation flow:', preparationError @@ -185,7 +188,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: runtimeFallback }) expect(runtimeFallback).toHaveBeenCalledWith({ flowAlreadyOpened: true }) - expect(mocks.trackCancellation).toHaveBeenLastCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenLastCalledWith( 'failed', expect.objectContaining({ cycle: 'yearly', @@ -207,11 +210,11 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback }) - expect(mocks.trackCancellation).toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( 'confirmed', expect.anything() ) - expect(mocks.trackCancellation).toHaveBeenCalledWith( + expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( 'failed', expect.objectContaining({ error_message: 'API down' }) ) diff --git a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts index c7ab5322831..aedd7341ac2 100644 --- a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts +++ b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts @@ -1,17 +1,11 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' -import { beforeEach, describe, expect, it, vi } from 'vitest' - -const { - mockIsCloud, - mockSubscribe, - mockTrackBeginCheckout, - mockTrackBillingEvent -} = vi.hoisted(() => ({ +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' + +const { mockIsCloud, mockSubscribe } = vi.hoisted(() => ({ mockIsCloud: { value: true }, - mockSubscribe: vi.fn(), - mockTrackBeginCheckout: vi.fn(), - mockTrackBillingEvent: vi.fn() + mockSubscribe: vi.fn() })) vi.mock(import('@/platform/distribution/types'), () => ({ @@ -37,10 +31,8 @@ vi.mock(import('@/platform/workspace/api/workspaceApi'), () => ({ })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackBeginCheckout = mockTrackBeginCheckout - telemetryMock.trackBillingEvent = mockTrackBillingEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) import { performTeamSubscriptionCheckout } from './teamSubscriptionCheckoutUtil' @@ -83,7 +75,7 @@ describe('performTeamSubscriptionCheckout', () => { teamCreditStopId: 'team_700' }) expect(assignedHref).toBe('https://stripe.test/pay') - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-1', tier: 'team', cycle: 'yearly', @@ -120,7 +112,7 @@ describe('performTeamSubscriptionCheckout', () => { ).rejects.toThrow(/payment URL/) expect(assignedHref).toBeUndefined() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -141,8 +133,8 @@ describe('performTeamSubscriptionCheckout', () => { }) ).rejects.toThrow('subscribe failed') - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', diff --git a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts index 4c49c57b709..5522ed0656d 100644 --- a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts +++ b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts @@ -1,10 +1,15 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useSettingStore } from '@/platform/settings/settingStore' import { useAppModeStore } from '@/stores/appModeStore' -import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, afterEach, describe, expect, it, vi } from 'vitest' import { nextTick, ref } from 'vue' import type { Ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' +import type { + OnboardingTourStepStage, + OnboardingTourStepMetadata +} from '@/platform/telemetry/types' + import type { AppMode } from '@/utils/appMode' import { clearCoachmarks } from './coachmarkRegistry' @@ -12,12 +17,13 @@ import { TOUR_SEEN_SETTING, registerTour } from './onboardingTours' import type { SpotlightStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' -const telemetry = vi.hoisted(() => ({ track: vi.fn() })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackOnboardingTour = telemetry.track -}) +const dispatcher = useTelemetry() +assert.exists(dispatcher) +const trackOnboardingTour = vi.mocked< + (stage: OnboardingTourStepStage, metadata: OnboardingTourStepMetadata) => void +>(dispatcher.trackOnboardingTour) const appModeMock = vi.hoisted(() => ({ mode: null as Ref | null })) vi.mock(import('@/composables/useAppMode'), async () => { @@ -48,7 +54,7 @@ function step( } function stages(): string[] { - return telemetry.track.mock.calls.map(([stage]) => stage) + return trackOnboardingTour.mock.calls.map(([stage]) => stage) } function mountStore() { @@ -69,7 +75,7 @@ beforeEach(() => { describe('onboardingTourStore — runtime-resolved tours', () => { afterEach(() => { clearCoachmarks() - telemetry.track.mockClear() + trackOnboardingTour.mockClear() }) it('reports no start for an entry no one registered', async () => { @@ -104,7 +110,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { await expect(store.startTour('firstRun')).resolves.toBe(false) expect( - telemetry.track, + trackOnboardingTour, 'counted as a plain no-start, a repeat user reads as a tour that failed to open' ).toHaveBeenCalledWith( 'not_started', @@ -146,7 +152,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { await expect(store.startTour('firstRun')).resolves.toBe(false) expect( - telemetry.track, + trackOnboardingTour, 'sharing a reason with an empty pin set reports the tour crash rate as zero' ).toHaveBeenCalledWith( 'not_started', @@ -163,7 +169,9 @@ describe('onboardingTourStore — runtime-resolved tours', () => { await store.startTour('firstRun') expect( - telemetry.track.mock.calls.filter(([stage]) => stage === 'not_started'), + trackOnboardingTour.mock.calls.filter( + ([stage]) => stage === 'not_started' + ), 'the trigger re-fires on every mode change, so the funnel would count edges not users' ).toHaveLength(1) }) @@ -193,7 +201,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { store.activeTour, 'a tour whose targets are no longer laid out points at nothing' ).toBeNull() - expect(telemetry.track).toHaveBeenCalledWith( + expect(trackOnboardingTour).toHaveBeenCalledWith( 'skipped', expect.objectContaining({ skip_reason: 'trigger_lost' }) ) @@ -314,7 +322,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { store.postpone() expect( - telemetry.track, + trackOnboardingTour, 'a postponement counted as a plain skip reads as a user who refused the tour' ).toHaveBeenCalledWith( 'skipped', diff --git a/src/platform/onboarding/onboardingTourStore.test.ts b/src/platform/onboarding/onboardingTourStore.test.ts index 59702392792..7ecd5d5d520 100644 --- a/src/platform/onboarding/onboardingTourStore.test.ts +++ b/src/platform/onboarding/onboardingTourStore.test.ts @@ -1,11 +1,16 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAppModeStore } from '@/stores/appModeStore' import { useSettingStore } from '@/platform/settings/settingStore' import type { DetachedWindowAPI } from 'happy-dom' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import type { Ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' +import type { + OnboardingTourStepStage, + OnboardingTourStepMetadata +} from '@/platform/telemetry/types' + import { useToastStore } from '@/platform/updates/common/toastStore' import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore' import type { AppMode } from '@/utils/appMode' @@ -19,12 +24,13 @@ import { TOUR_SEEN_SETTING, tourDefinition } from './onboardingTours' import type { CoachId, CoachStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' -const telemetry = vi.hoisted(() => ({ track: vi.fn() })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackOnboardingTour = telemetry.track -}) +const dispatcher = useTelemetry() +assert.exists(dispatcher) +const trackOnboardingTour = vi.mocked< + (stage: OnboardingTourStepStage, metadata: OnboardingTourStepMetadata) => void +>(dispatcher.trackOnboardingTour) const appModeMock = vi.hoisted((): { mode: Ref | null } => ({ mode: null @@ -74,7 +80,7 @@ function mountStore() { } function startedCount() { - return telemetry.track.mock.calls.filter(([stage]) => stage === 'started') + return trackOnboardingTour.mock.calls.filter(([stage]) => stage === 'started') .length } @@ -83,7 +89,7 @@ function shownCoachId(step: CoachStep | null | undefined) { } function shownCount(coachId?: CoachId) { - return telemetry.track.mock.calls.filter( + return trackOnboardingTour.mock.calls.filter( ([stage, meta]) => stage === 'step_shown' && (!coachId || meta.coach_id === coachId) ).length @@ -116,7 +122,7 @@ describe('onboardingTourStore', () => { appendedTargets.length = 0 setViewport({ width: 1024, height: 768 }) if (appModeMock.mode) appModeMock.mode.value = 'graph' - telemetry.track.mockClear() + trackOnboardingTour.mockClear() }) /** Register one laid-out element for a coach id, so its step resolves at once. */ @@ -209,7 +215,7 @@ describe('onboardingTourStore', () => { await nextTick() expect(store.step).toBeNull() - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'trigger_lost' }) @@ -236,7 +242,7 @@ describe('onboardingTourStore', () => { expect(seenTours()).toContain('appMode') // A deliberate dismissal reports the user as the skip reason. - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'user' }) @@ -367,7 +373,7 @@ describe('onboardingTourStore', () => { // The skipped event reports the timed-out step, not the prior landing, // and attributes the skip to the timeout rather than the user. - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ @@ -422,7 +428,7 @@ describe('onboardingTourStore', () => { store.skip() await vi.advanceTimersByTimeAsync(8000) - const skipped = telemetry.track.mock.calls.filter( + const skipped = trackOnboardingTour.mock.calls.filter( ([stage]) => stage === 'skipped' ) expect(skipped).toHaveLength(1) @@ -442,7 +448,7 @@ describe('onboardingTourStore', () => { expect(store.step).toBeNull() expect(seenTours()).not.toContain('appMode') - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'trigger_lost' }) @@ -463,7 +469,7 @@ describe('onboardingTourStore', () => { await vi.advanceTimersByTimeAsync(8000) expect(useToastStore().messagesToAdd).toHaveLength(0) - const skipReasons = telemetry.track.mock.calls + const skipReasons = trackOnboardingTour.mock.calls .filter(([stage]) => stage === 'skipped') .map(([, meta]) => meta.skip_reason) expect(skipReasons).toEqual(['trigger_lost']) @@ -490,7 +496,7 @@ describe('onboardingTourStore', () => { } expect(seenTours()).toContain('appMode') - const completed = telemetry.track.mock.calls.find( + const completed = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'completed' ) expect(completed).toBeTruthy() @@ -608,19 +614,19 @@ describe('onboardingTourStore', () => { await nextTick() // The landing isn't numbered, so the four spotlight steps carry the count. - const started = telemetry.track.mock.calls.find( + const started = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'started' ) expect(started?.[1]).toEqual({ tour: 'appMode', step_count: 4 }) - const landingShown = telemetry.track.mock.calls.find( + const landingShown = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'step_shown' ) expect(landingShown?.[1]).toEqual({ tour: 'appMode', step_count: 4 }) store.next() await nextTick() - const shown = telemetry.track.mock.calls + const shown = trackOnboardingTour.mock.calls .filter(([stage]) => stage === 'step_shown') .at(-1) expect(shown?.[1]).toEqual({ @@ -642,7 +648,7 @@ describe('onboardingTourStore', () => { await nextTick() expect(store.step?.kind).not.toBe('landing') - const skipped = telemetry.track.mock.calls.some( + const skipped = trackOnboardingTour.mock.calls.some( ([stage]) => stage === 'skipped' ) expect(skipped).toBe(false) @@ -692,7 +698,7 @@ describe('onboardingTourStore', () => { useToastStore().messagesToAdd, 'leaving app mode is an ordinary thing to do, so it must not read as an error' ).toEqual([]) - const skipped = telemetry.track.mock.calls.findLast( + const skipped = trackOnboardingTour.mock.calls.findLast( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'trigger_lost' }) @@ -908,7 +914,7 @@ describe('onboardingTourStore', () => { ).not.toBeNull() expect(useToastStore().messagesToAdd).toHaveLength(0) expect( - telemetry.track.mock.calls.filter(([stage]) => stage === 'skipped') + trackOnboardingTour.mock.calls.filter(([stage]) => stage === 'skipped') ).toHaveLength(0) }) }) diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index f0f837f1297..a95c55374dc 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -1,5 +1,6 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import { getSettingInfo, @@ -10,15 +11,10 @@ import type { Settings } from '@/schemas/apiSchema' import { api } from '@/scripts/api' import { app } from '@/scripts/app' -const { trackSettingChanged } = vi.hoisted(() => ({ - trackSettingChanged: vi.fn() -})) - vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackSettingChanged = trackSettingChanged -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) // Mock the api vi.mock(import('@/scripts/api'), () => ({ @@ -630,7 +626,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting', previous_value: 'default', new_value: 'newvalue' @@ -647,7 +643,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() }) it('does not track visible settings that opt out', async () => { @@ -661,7 +657,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() }) it('tracks visible settings without values when values opt out', async () => { @@ -675,7 +671,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting' }) }) @@ -690,13 +686,13 @@ describe('useSettingStore', () => { }) await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting' }) // Setting the same value again is a no-op and should not re-emit await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledTimes(1) + expect(dispatcher.trackSettingChanged).toHaveBeenCalledTimes(1) }) it('ships previous/new values when the setting opts into includeValues', async () => { @@ -710,7 +706,7 @@ describe('useSettingStore', () => { await store.set('Comfy.ColorPalette', 'light') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'Comfy.ColorPalette', previous_value: 'dark', new_value: 'light' @@ -731,7 +727,7 @@ describe('useSettingStore', () => { 'failed' ) - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() }) describe('object mutation prevention', () => { @@ -881,8 +877,8 @@ describe('useSettingStore', () => { 'Comfy.Release.Version': '1.0.0' }) - expect(trackSettingChanged).toHaveBeenCalledTimes(1) - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(dispatcher.trackSettingChanged).toHaveBeenCalledTimes(1) + expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'Comfy.ColorPalette', previous_value: 'dark', new_value: 'light' @@ -928,7 +924,7 @@ describe('useSettingStore', () => { await store.setMany({ 'Comfy.Release.Version': 'existing' }) expect(api.storeSettings).not.toHaveBeenCalled() - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() }) }) }) diff --git a/src/platform/support/feedbackDialog.test.ts b/src/platform/support/feedbackDialog.test.ts index 03e34ed61a8..2739e27c8ba 100644 --- a/src/platform/support/feedbackDialog.test.ts +++ b/src/platform/support/feedbackDialog.test.ts @@ -1,9 +1,9 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' -import { openTypeformDialog } from '@/platform/surveys/openTypeformDialog' import { useTelemetry } from '@/platform/telemetry' +import { openTypeformDialog } from '@/platform/surveys/openTypeformDialog' + import { FEEDBACK_TYPEFORM_ID } from './config' import { openFeedbackDialog } from './feedbackDialog' @@ -15,12 +15,10 @@ vi.mock(import('@/platform/surveys/openTypeformDialog'), () => ({ openTypeformDialog: vi.fn() })) -const trackUiButtonClicked = vi.fn() vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUiButtonClicked = trackUiButtonClicked -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const userEmail = vi.hoisted((): { value: string | undefined } => ({ value: undefined @@ -66,7 +64,7 @@ describe('openFeedbackDialog', () => { it('tracks the button click tagged with the opening source', () => { openFeedbackDialog('topbar') - expect(trackUiButtonClicked).toHaveBeenCalledWith({ + expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'feedback_button_clicked', element_group: 'topbar' }) diff --git a/src/platform/telemetry/__mocks__/index.ts b/src/platform/telemetry/__mocks__/index.ts index 5004491e648..a06b5a450d1 100644 --- a/src/platform/telemetry/__mocks__/index.ts +++ b/src/platform/telemetry/__mocks__/index.ts @@ -6,6 +6,6 @@ import type { } from '../index' import { TelemetryRegistry } from '../TelemetryRegistry' -export const telemetryMock = vi.mockObject(new TelemetryRegistry()) +const telemetryMock = vi.mockObject(new TelemetryRegistry()) export const useTelemetry = vi.fn(() => telemetryMock) export const setTelemetryRegistry = vi.fn() diff --git a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts index 4a1a23345ea..6c42860d32c 100644 --- a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts +++ b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts @@ -1,17 +1,13 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { EffectScope, Ref } from 'vue' import { effectScope, ref } from 'vue' -const hoisted = vi.hoisted(() => ({ - trackSearchQuery: vi.fn() -})) +import { useTelemetry } from '@/platform/telemetry' vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackSearchQuery = hoisted.trackSearchQuery -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) import { useSearchQueryTracking } from './useSearchQueryTracking' @@ -45,7 +41,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = ' hello ' await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'hello', query_length: 5, @@ -60,7 +56,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = 'nothingmatches' await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'nothingmatches', query_length: 14, @@ -75,7 +71,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = ' ' await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).not.toHaveBeenCalled() + expect(dispatcher.trackSearchQuery).not.toHaveBeenCalled() }) it('cancels a pending debounced call when the scope is disposed', async () => { @@ -85,7 +81,7 @@ describe('useSearchQueryTracking', () => { query.value = 'hello' scope.stop() await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).not.toHaveBeenCalled() + expect(dispatcher.trackSearchQuery).not.toHaveBeenCalled() }) it('truncates query to 100 chars while preserving original length', async () => { @@ -95,7 +91,7 @@ describe('useSearchQueryTracking', () => { const long = 'x'.repeat(250) query.value = long await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'x'.repeat(100), query_length: 250, diff --git a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts index 1e9a6d830a8..1c3445d4cf8 100644 --- a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts +++ b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowDraftStoreV2 } from '@/platform/workflow/persistence/stores/workflowDraftStoreV2' import { useDomWidgetStore } from '@/stores/domWidgetStore' import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore' @@ -54,12 +53,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackDefaultViewSet = vi.fn() - telemetryMock.trackWorkflowSaved = vi.fn() - telemetryMock.trackEnterLinear = vi.fn() -}) - const PROBE_NODE_TYPE = 'test/insert-workflow-probe' class InsertWorkflowProbeNode extends LGraphNode { diff --git a/src/platform/workflow/core/services/workflowService.test.ts b/src/platform/workflow/core/services/workflowService.test.ts index 55b8c871777..d37417a1c08 100644 --- a/src/platform/workflow/core/services/workflowService.test.ts +++ b/src/platform/workflow/core/services/workflowService.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore' import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' // eslint-disable-line import-x/no-restricted-paths import { useWorkflowDraftStoreV2 } from '@/platform/workflow/persistence/stores/workflowDraftStoreV2' @@ -8,7 +7,9 @@ import { onIdTokenChanged, setPersistence } from 'firebase/auth' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import type { LoadedComfyWorkflow, @@ -88,9 +89,8 @@ function makeWorkflowDataWithId(id: string): ComfyWorkflowJSON { return { ...makeWorkflowData(), id } } -const { mockConfirm, mockTrackWorkflowSaved } = vi.hoisted(() => ({ - mockConfirm: vi.fn(), - mockTrackWorkflowSaved: vi.fn() +const { mockConfirm } = vi.hoisted(() => ({ + mockConfirm: vi.fn() })) vi.mock(import('@/services/dialogService'), () => ({ @@ -134,11 +134,8 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackDefaultViewSet = vi.fn() - telemetryMock.trackWorkflowSaved = mockTrackWorkflowSaved - telemetryMock.trackEnterLinear = vi.fn() -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) function createWorkflow( warnings: PendingWarnings | null = null, @@ -2531,8 +2528,8 @@ describe('useWorkflowService', () => { 'workflows/test.app.json' ) expect(workflowStore.saveWorkflow).toHaveBeenCalledWith(copy) - expect(mockTrackWorkflowSaved).toHaveBeenCalledTimes(1) - expect(mockTrackWorkflowSaved).toHaveBeenCalledWith({ + expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledTimes(1) + expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledWith({ is_app: true, is_new: true }) @@ -2569,8 +2566,8 @@ describe('useWorkflowService', () => { isApp: true }) - expect(mockTrackWorkflowSaved).toHaveBeenCalledTimes(1) - expect(mockTrackWorkflowSaved).toHaveBeenCalledWith({ + expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledTimes(1) + expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledWith({ is_app: true, is_new: true }) diff --git a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts index 7a7f6c52dc6..45659e27ece 100644 --- a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts +++ b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts @@ -1,20 +1,18 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' -import ShareWorkflowDialogContent from '@/platform/workflow/sharing/components/ShareWorkflowDialogContent.vue' +import { useTelemetry } from '@/platform/telemetry' -const mockTrackShareFlow = vi.hoisted(() => vi.fn()) +import ShareWorkflowDialogContent from '@/platform/workflow/sharing/components/ShareWorkflowDialogContent.vue' vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackShareFlow = mockTrackShareFlow -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const mockToast = vi.hoisted(() => ({ add: vi.fn() })) @@ -380,7 +378,7 @@ describe('ShareWorkflowDialogContent', () => { 'workflows/test.json', initialShareableAssets ) - expect(mockTrackShareFlow).toHaveBeenCalledWith({ + expect(dispatcher.trackShareFlow).toHaveBeenCalledWith({ step: 'link_created', source: 'graph_mode', view_mode: 'graph', @@ -402,7 +400,7 @@ describe('ShareWorkflowDialogContent', () => { await userEvent.click(screen.getByRole('button', { name: /Copy link/i })) - expect(mockTrackShareFlow).toHaveBeenCalledWith({ + expect(dispatcher.trackShareFlow).toHaveBeenCalledWith({ step: 'link_copied', source: 'graph_mode', view_mode: 'graph', diff --git a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts index 2a7a839d4b2..6d07d5074f9 100644 --- a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts +++ b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts @@ -1,10 +1,11 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useDialogStore } from '@/stores/dialogStore' import { fromPartial } from '@total-typescript/shoehorn' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { App } from 'vue' import { createApp, defineComponent } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { i18n } from '@/i18n' import { useSharedWorkflowUrlLoader as createSharedWorkflowUrlLoader } from '@/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader' import type { SharedWorkflowPayload } from '@/platform/workflow/sharing/types/shareTypes' @@ -35,7 +36,6 @@ vi.mock(import('vue-router'), () => ({ const mockImportPublishedAssets = vi.fn() const mockIsLoggedIn = vi.hoisted(() => ({ value: false })) -const mockTrackShareLinkOpened = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/auth/useCurrentUser'), () => ({ useCurrentUser: () => ({ @@ -52,9 +52,8 @@ vi.mock(import('@/composables/useAppMode'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackShareLinkOpened = mockTrackShareLinkOpened -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('@/platform/workflow/sharing/services/workflowShareService'), @@ -250,7 +249,7 @@ describe('useSharedWorkflowUrlLoader', () => { expect(loaded).toBe('not-present') expect(mockShowLayoutDialog).not.toHaveBeenCalled() expect(mockLoadGraphData).not.toHaveBeenCalled() - expect(mockTrackShareLinkOpened).not.toHaveBeenCalled() + expect(dispatcher.trackShareLinkOpened).not.toHaveBeenCalled() }) it('opens dialog immediately with shareId and loads graph on confirm', async () => { @@ -274,7 +273,7 @@ describe('useSharedWorkflowUrlLoader', () => { 'Test Workflow', { openSource: 'shared_url', shareId: 'share-id-1' } ) - expect(mockTrackShareLinkOpened).toHaveBeenCalledWith({ + expect(dispatcher.trackShareLinkOpened).toHaveBeenCalledWith({ share_id: 'share-id-1', is_authenticated: false, view_mode: 'graph', @@ -298,7 +297,7 @@ describe('useSharedWorkflowUrlLoader', () => { const loaded = await loadSharedWorkflowFromUrl() expect(loaded).toBe('loaded') - expect(mockTrackShareLinkOpened).toHaveBeenCalledWith({ + expect(dispatcher.trackShareLinkOpened).toHaveBeenCalledWith({ share_id: 'share-id-1', is_authenticated: true, view_mode: 'graph', diff --git a/src/platform/workspace/components/InviteMembersForm.test.ts b/src/platform/workspace/components/InviteMembersForm.test.ts index f40ba968cb6..c6e61fe5deb 100644 --- a/src/platform/workspace/components/InviteMembersForm.test.ts +++ b/src/platform/workspace/components/InviteMembersForm.test.ts @@ -1,24 +1,18 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { render, screen, waitFor } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import InviteMembersForm from './InviteMembersForm.vue' import type { WorkspacePendingInvite } from '@/platform/workspace/stores/teamWorkspaceStore' -const { - mockFetchStatus, - mockToastAdd, - mockTrackInviteSent, - mockTrackInviteFailed -} = vi.hoisted(() => ({ +const { mockFetchStatus, mockToastAdd } = vi.hoisted(() => ({ mockFetchStatus: vi.fn(), - mockToastAdd: vi.fn(), - mockTrackInviteSent: vi.fn(), - mockTrackInviteFailed: vi.fn() + mockToastAdd: vi.fn() })) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ @@ -36,10 +30,8 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackWorkspaceInviteSent = mockTrackInviteSent - telemetryMock.trackWorkspaceInviteFailed = mockTrackInviteFailed -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const i18n = createI18n({ legacy: false, @@ -130,7 +122,7 @@ describe('InviteMembersForm', () => { ) expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('a@b.com') expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('c@d.com') - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'post_upgrade_success', count: 2 }) @@ -229,7 +221,7 @@ describe('InviteMembersForm', () => { expect.objectContaining({ severity: 'error' }) ) expect(emitted().submitted).toBeUndefined() - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'post_upgrade_success', count: 1 }) @@ -240,8 +232,8 @@ describe('InviteMembersForm', () => { expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledTimes(3) ) expect(emitted().submitted).toEqual([[['ok@x.com', 'fail@x.com']]]) - expect(mockTrackInviteSent).toHaveBeenCalledTimes(2) - expect(mockTrackInviteSent).toHaveBeenLastCalledWith({ + expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledTimes(2) + expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenLastCalledWith({ source: 'post_upgrade_success', count: 1 }) @@ -265,7 +257,7 @@ describe('InviteMembersForm', () => { expect.objectContaining({ severity: 'error' }) ) expect(emitted().submitted).toBeUndefined() - expect(mockTrackInviteSent).not.toHaveBeenCalled() + expect(dispatcher.trackWorkspaceInviteSent).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() }) diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index 9dabeff74dc..8c1c99a03be 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -4,7 +4,6 @@ import { setPersistence } from 'firebase/auth' -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { @@ -16,10 +15,12 @@ import { useAuthStore } from '@/stores/authStore' import { useDialogStore } from '@/stores/dialogStore' import { render, screen, waitFor } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import enMessages from '@/locales/en/main.json' with { type: 'json' } import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' @@ -43,9 +44,6 @@ const mockTopup = const mockShowSettings = vi.fn() const mockToastAdd = vi.fn() -const mockTrackTopUpPurchase = vi.fn() -const mockTrackBillingEvent = vi.fn() -const mockTrackCheckoutJourneyEvent = vi.hoisted(() => vi.fn()) const mockCanTopUp = vi.hoisted(() => ({ ref: undefined as { value: boolean } | undefined })) @@ -99,12 +97,8 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackApiCreditTopupButtonPurchaseClicked = - mockTrackTopUpPurchase - telemetryMock.trackBillingEvent = mockTrackBillingEvent - telemetryMock.trackCheckoutJourneyEvent = mockTrackCheckoutJourneyEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('firebase/auth'), { spy: true }) @@ -205,7 +199,7 @@ beforeEach(() => { vi.mocked(useDialogStore().closeDialog).mockImplementation(() => {}) Object.assign(useAuthStore(), { userId: 'user-1' }) Object.assign(useTeamWorkspaceStore(), { activeWorkspaceId: 'workspace-1' }) - mockTrackCheckoutJourneyEvent.mockClear() + dispatcher.trackCheckoutJourneyEvent.mockClear() sessionStorage.clear() clearCheckoutJourney() }) @@ -254,13 +248,13 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'started', outcome: 'pending' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -273,7 +267,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { renderDialog() await waitFor(() => - expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(dispatcher.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'entered', entry_flow: 'topup' }) ) ) @@ -282,14 +276,14 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(dispatcher.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'operation_linked', billing_op_id: 'op-1' }) ) ) - const phases = mockTrackCheckoutJourneyEvent.mock.calls.map( + const phases = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( ([event]) => event.phase ) expect(phases.indexOf('submitted')).toBeLessThan( @@ -299,7 +293,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { // One denominator: every phase of a top-up must carry the same journey. const journeyIds = new Set( - mockTrackCheckoutJourneyEvent.mock.calls.map( + dispatcher.trackCheckoutJourneyEvent.mock.calls.map( ([event]) => event.checkout_journey_id ) ) @@ -318,7 +312,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(dispatcher.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'submitted' }) ) ) @@ -336,7 +330,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { resolveTopup(topupResponse('completed')) await waitFor(() => expect(mockFetchBalance).toHaveBeenCalled()) - const phases = mockTrackCheckoutJourneyEvent.mock.calls.map( + const phases = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( ([event]) => event.phase ) expect(phases).toContain('submitted') @@ -353,7 +347,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -706,7 +700,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { summary: 'Purchase Failed', detail: 'Failed to purchase credits: An unknown error occurred' }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -728,14 +722,14 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockFetchBalance).toHaveBeenCalledOnce() expect(mockFetchStatus).toHaveBeenCalledOnce() expect(mockShowSettings).toHaveBeenCalledWith('workspace') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', billing_op_id: 'op-1', duration_ms: expect.any(Number) }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -774,8 +768,8 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) - expect(mockTrackBillingEvent).toHaveBeenCalledTimes(4) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledTimes(4) + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', @@ -802,7 +796,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { ) expect(mockFetchBalance).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -816,7 +810,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockFetchBalance).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -824,7 +818,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { failure_category: 'provider_decline', duration_ms: expect.any(Number) }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -844,7 +838,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -863,7 +857,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(screen.getByRole('button', { name: 'Pay $50.00' })).toBeDisabled() expect(mockTopup).not.toHaveBeenCalled() - expect(mockTrackTopUpPurchase).not.toHaveBeenCalled() + expect( + dispatcher.trackApiCreditTopupButtonPurchaseClicked + ).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() expect(useDialogStore().closeDialog).not.toHaveBeenCalled() }) diff --git a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts index 184ad8bfd5a..b63b9dfa9ea 100644 --- a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts +++ b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts @@ -1,33 +1,26 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useDialogStore } from '@/stores/dialogStore' import { render, screen, waitFor } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import InviteMemberDialogContent from './InviteMemberDialogContent.vue' import type { WorkspacePendingInvite } from '@/platform/workspace/stores/teamWorkspaceStore' -const { - mockToastAdd, - mockTrackInviteSent, - mockTrackInviteFailed, - mockFetchStatus, - mockMaxSeats, - mockOccupiedSeats -} = vi.hoisted(() => { - const nullableNumber = (value: number | null) => ({ value }) - return { - mockToastAdd: vi.fn(), - mockTrackInviteSent: vi.fn(), - mockTrackInviteFailed: vi.fn(), - mockFetchStatus: vi.fn(), - mockMaxSeats: nullableNumber(73), - mockOccupiedSeats: nullableNumber(0) - } -}) +const { mockToastAdd, mockFetchStatus, mockMaxSeats, mockOccupiedSeats } = + vi.hoisted(() => { + const nullableNumber = (value: number | null) => ({ value }) + return { + mockToastAdd: vi.fn(), + mockFetchStatus: vi.fn(), + mockMaxSeats: nullableNumber(73), + mockOccupiedSeats: nullableNumber(0) + } + }) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: () => ({ @@ -39,10 +32,8 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackWorkspaceInviteSent = mockTrackInviteSent - telemetryMock.trackWorkspaceInviteFailed = mockTrackInviteFailed -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports @@ -206,7 +197,7 @@ describe('InviteMemberDialogContent', () => { expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledTimes(2) expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('a@b.com') expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('c@d.com') - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'settings_members', count: 2 }) @@ -241,7 +232,7 @@ describe('InviteMemberDialogContent', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'settings_members', count: 1 }) @@ -268,7 +259,7 @@ describe('InviteMemberDialogContent', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackInviteSent).not.toHaveBeenCalled() + expect(dispatcher.trackWorkspaceInviteSent).not.toHaveBeenCalled() expect(inviteButton()).toBeEnabled() }) diff --git a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts index 00737af8b50..46dbf21d21c 100644 --- a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts +++ b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts @@ -1,9 +1,10 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { getActivePinia } from 'pinia' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' import type { ListMembersParams } from '@/platform/workspace/api/workspaceApi' import type { WorkspaceMember } from '@/platform/workspace/stores/teamWorkspaceStore' @@ -25,7 +26,6 @@ const mockSubscribe = vi.hoisted(() => vi.fn()) const mockPreviewSubscribe = vi.hoisted(() => vi.fn()) const mockFetchStatus = vi.hoisted(() => vi.fn()) -const mockTrackBillingEvent = vi.hoisted(() => vi.fn()) const mockPermissions = vi.hoisted(() => ({ value: { canManageSubscription: true, @@ -107,9 +107,8 @@ vi.mock(import('@/config/comfyApi'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackBillingEvent = mockTrackBillingEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) function createMember( overrides: Partial = {} @@ -504,7 +503,7 @@ describe('useDowngradeToPersonal', () => { calls.push('remove') return Promise.resolve() }) - mockTrackBillingEvent.mockImplementation((event) => { + dispatcher.trackBillingEvent.mockImplementation((event) => { if ( event.stage === 'started' && (event.operation === 'subscription_checkout' || @@ -564,7 +563,7 @@ describe('useDowngradeToPersonal', () => { const result = await downgradeToPersonal('creator-annual') expect(result).toStrictEqual({ preview, response }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'succeeded', outcome: 'success', @@ -690,7 +689,7 @@ describe('useDowngradeToPersonal', () => { attemptStartedAt: expect.any(Number) } ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -738,7 +737,7 @@ describe('useDowngradeToPersonal', () => { await downgradeToPersonal('founder-monthly') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'started', outcome: 'pending', @@ -758,7 +757,7 @@ describe('useDowngradeToPersonal', () => { 'm2@example.com' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -769,7 +768,7 @@ describe('useDowngradeToPersonal', () => { error_code: 'member_removal_failed', duration_ms: expect.any(Number) }) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -781,7 +780,7 @@ describe('useDowngradeToPersonal', () => { await expect(downgradeToPersonal('founder-monthly')).rejects.toBe('boom') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -804,7 +803,7 @@ describe('useDowngradeToPersonal', () => { 'offline' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -825,7 +824,7 @@ describe('useDowngradeToPersonal', () => { 'offline' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -846,7 +845,7 @@ describe('useDowngradeToPersonal', () => { 'm1@example.com' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', diff --git a/src/platform/workspace/composables/useResubscribe.test.ts b/src/platform/workspace/composables/useResubscribe.test.ts index 6c3b000af73..d505e6c2c91 100644 --- a/src/platform/workspace/composables/useResubscribe.test.ts +++ b/src/platform/workspace/composables/useResubscribe.test.ts @@ -1,9 +1,10 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { createApp, defineComponent } from 'vue' import type { App } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { AuthStoreError } from '@/stores/authStore' import { useResubscribe as createResubscribe } from './useResubscribe' @@ -14,9 +15,7 @@ const state = vi.hoisted(() => ({ canReactivate: true, canReactivatePlan: true, resubscribe: vi.fn(), - toastAdd: vi.fn(), - trackResubscribeClicked: vi.fn(), - trackBillingEvent: vi.fn() + toastAdd: vi.fn() })) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ @@ -70,10 +69,8 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackResubscribeClicked = state.trackResubscribeClicked - telemetryMock.trackBillingEvent = state.trackBillingEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports @@ -123,7 +120,7 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).not.toHaveBeenCalled() - expect(state.trackResubscribeClicked).not.toHaveBeenCalled() + expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() expect(state.toastAdd).not.toHaveBeenCalled() expect(isResubscribing.value).toBe(false) }) @@ -137,7 +134,7 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).not.toHaveBeenCalled() - expect(state.trackResubscribeClicked).not.toHaveBeenCalled() + expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() expect(state.toastAdd).not.toHaveBeenCalled() expect(isResubscribing.value).toBe(false) }) @@ -172,7 +169,7 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -191,11 +188,11 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).toHaveBeenCalledOnce() - expect(state.trackResubscribeClicked).toHaveBeenCalledOnce() - expect(state.trackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackResubscribeClicked).toHaveBeenCalledOnce() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -203,7 +200,7 @@ describe('useResubscribe', () => { }) // Exactly one started event on the legacy success rail: the pre-call start, // with no duplicate post-await started/pending emitted after resubscribe() resolves. - expect(state.trackBillingEvent).toHaveBeenCalledTimes(1) + expect(dispatcher.trackBillingEvent).toHaveBeenCalledTimes(1) expect(state.toastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'success' }) ) @@ -224,7 +221,7 @@ describe('useResubscribe', () => { detail: 'Resubscribe failed for person@example.com' }) ) - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -245,10 +242,10 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(state.trackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -265,7 +262,7 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -279,9 +276,11 @@ describe('useResubscribe', () => { state.resubscribe.mockImplementation(async () => { callOrder.push('resubscribe') }) - state.trackBillingEvent.mockImplementation((event: { stage: string }) => { - callOrder.push(`trackBillingEvent:${event.stage}`) - }) + dispatcher.trackBillingEvent.mockImplementation( + (event: { stage: string }) => { + callOrder.push(`trackBillingEvent:${event.stage}`) + } + ) const { handleResubscribe } = useResubscribe() await handleResubscribe() diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 8d1919f1eee..8d92b5dc296 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -1,6 +1,5 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { render } from '@testing-library/vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { computed } from 'vue' import { billingOperation } from './billingOperationTestUtils' import type { BillingOperation } from './billingOperationTestUtils' @@ -13,6 +12,8 @@ import { } from 'firebase/auth' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import type { PaymentIntentSource } from '@/platform/telemetry/types' import { clearCheckoutJourney, @@ -189,8 +190,6 @@ const { mockResubscribe, mockToastAdd, mockListSavedPaymentMethods, - mockTrackBeginCheckout, - mockTrackBillingEvent, mockShowDowngradeToPersonalDialog, mockIsTeamPlan, mockShouldUseWorkspaceBilling, @@ -215,8 +214,6 @@ const { mockResubscribe: vi.fn(), mockToastAdd: vi.fn(), mockListSavedPaymentMethods: vi.fn(), - mockTrackBeginCheckout: vi.fn(), - mockTrackBillingEvent: vi.fn(), mockShowDowngradeToPersonalDialog: vi.fn(), mockIsTeamPlan: { value: false }, mockShouldUseWorkspaceBilling: { value: true }, @@ -237,7 +234,11 @@ const { canDowngradeToPersonal: true } }, - mockSubscription: { value: null as { isCancelled: boolean } | null }, + mockSubscription: { + value: null as { + isCancelled: boolean + } | null + }, mockBillingStatus: { value: null as BillingStatus | null } } }) @@ -378,20 +379,10 @@ vi.mock( }) ) -const mockTrackResubscribeClicked = vi.hoisted(() => vi.fn()) -const mockTrackMonthlySubscriptionSucceeded = vi.hoisted(() => vi.fn()) -const mockTrackCheckoutJourneyEvent = vi.hoisted(() => vi.fn()) - vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackBillingEvent = mockTrackBillingEvent - telemetryMock.trackResubscribeClicked = mockTrackResubscribeClicked - telemetryMock.trackBeginCheckout = mockTrackBeginCheckout - telemetryMock.trackMonthlySubscriptionSucceeded = - mockTrackMonthlySubscriptionSucceeded - telemetryMock.trackCheckoutJourneyEvent = mockTrackCheckoutJourneyEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: mockReportError @@ -541,14 +532,14 @@ describe('useSubscriptionCheckout', () => { } mockCanReactivatePlan.value = true mockSubscription.value = null - mockTrackCheckoutJourneyEvent.mockClear() + dispatcher.trackCheckoutJourneyEvent.mockClear() sessionStorage.clear() clearCheckoutJourney() }) describe('checkout journey instrumentation', () => { function journeyPhases() { - return mockTrackCheckoutJourneyEvent.mock.calls.map( + return dispatcher.trackCheckoutJourneyEvent.mock.calls.map( ([event]) => event.phase ) } @@ -577,7 +568,7 @@ describe('useSubscriptionCheckout', () => { phases.indexOf('operation_linked') ) - const events = mockTrackCheckoutJourneyEvent.mock.calls.map( + const events = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( ([event]) => event ) const opLinked = events.find( @@ -662,7 +653,7 @@ describe('useSubscriptionCheckout', () => { }) await checkout.handleConfirmTransition() - const events = mockTrackCheckoutJourneyEvent.mock.calls.map( + const events = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( ([event]) => event ) expect(events.some((event) => event.phase === 'operation_linked')).toBe( @@ -673,7 +664,7 @@ describe('useSubscriptionCheckout', () => { it('records a correlated preview failure with no operation id', async () => { await submitRejectedPreview('PREVIEW_FAILED') - const events = mockTrackCheckoutJourneyEvent.mock.calls.map( + const events = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( ([event]) => event ) const entered = events.find((event) => event.phase === 'entered') @@ -1442,9 +1433,9 @@ describe('useSubscriptionCheckout', () => { expect(checkout.previewData.value).toStrictEqual(preview) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() - expect(mockTrackBeginCheckout).toHaveBeenCalledWith( + expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith( expect.objectContaining({ tier: 'creator', cycle: 'monthly', @@ -1471,7 +1462,7 @@ describe('useSubscriptionCheckout', () => { }) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() }) }) @@ -2148,7 +2139,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleTeamSubscribe() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'started', outcome: 'pending', @@ -2157,7 +2148,7 @@ describe('useSubscriptionCheckout', () => { checkout_type: 'new', payment_intent_source: undefined }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -2197,7 +2188,7 @@ describe('useSubscriptionCheckout', () => { confirmReactivation: false }) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBeginCheckout).toHaveBeenCalledWith( + expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith( expect.objectContaining({ tier: 'team', checkout_type: 'new', @@ -2385,7 +2376,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'subscription_checkout', stage: 'failed', @@ -2444,7 +2435,7 @@ describe('useSubscriptionCheckout', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() }) it('refuses to bill a team reactivation when a fresh preview no longer matches the confirmed charge', async () => { @@ -2532,7 +2523,7 @@ describe('useSubscriptionCheckout', () => { detail: 'status unavailable' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() }) it('bounces to pricing when a required reactivation refresh cannot collect consent', async () => { @@ -2631,7 +2622,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) @@ -2652,14 +2643,14 @@ describe('useSubscriptionCheckout', () => { ) expect(checkout.checkoutStep.value).toBe('success') expect( - mockTrackBillingEvent.mock.calls.filter( + dispatcher.trackBillingEvent.mock.calls.filter( ([event]) => event.operation === 'subscription_checkout' && event.stage === 'started' ) ).toHaveLength(1) expect( - mockTrackBillingEvent.mock.calls.filter( + dispatcher.trackBillingEvent.mock.calls.filter( ([event]) => event.operation === 'operation' && event.stage === 'started' ) @@ -2758,8 +2749,8 @@ describe('useSubscriptionCheckout', () => { detail: 'Team payment failed' }) ) - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3120,7 +3111,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'started', outcome: 'pending', @@ -3129,7 +3120,7 @@ describe('useSubscriptionCheckout', () => { checkout_type: 'new', payment_intent_source: undefined }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -3160,7 +3151,7 @@ describe('useSubscriptionCheckout', () => { confirmReactivation: false }) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'succeeded', outcome: 'success', @@ -3171,7 +3162,9 @@ describe('useSubscriptionCheckout', () => { billing_op_id: 'op-1', duration_ms: expect.any(Number) }) - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() + expect( + dispatcher.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() expect(mockFetchStatus).toHaveBeenCalledTimes(1) expect(mockFetchBalance).not.toHaveBeenCalled() }) @@ -3190,7 +3183,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() + expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() Object.assign(useAuthStore(), { userId: 'user-1' }) }) @@ -3207,7 +3200,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-1', tier: 'standard', cycle: 'yearly', @@ -3682,8 +3675,8 @@ describe('useSubscriptionCheckout', () => { detail: 'Payment failed' }) ) - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3704,7 +3697,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3727,7 +3720,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() }) it('does not submit when workspace ownership is revoked', async () => { @@ -3759,7 +3752,9 @@ describe('useSubscriptionCheckout', () => { await checkout.handleConfirmTransition() expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() + expect( + dispatcher.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() }) it('shows error toast on failure', async () => { @@ -3887,7 +3882,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) }) @@ -4004,7 +3999,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation amount changed' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'subscription_checkout', stage: 'failed', @@ -4089,7 +4084,7 @@ describe('useSubscriptionCheckout', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() }) it('refuses to bill when a fresh preview no longer matches the confirmed charge', async () => { @@ -4192,7 +4187,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleConfirmTransition() expect(mockSubscribe).not.toHaveBeenCalled() - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() + expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() expect(emit).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() }) @@ -4265,7 +4260,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -4287,11 +4282,11 @@ describe('useSubscriptionCheckout', () => { expect(mockResubscribe).toHaveBeenCalled() expect(emit).toHaveBeenCalledWith('close', true) - expect(mockTrackResubscribeClicked).toHaveBeenCalledWith({ + expect(dispatcher.trackResubscribeClicked).toHaveBeenCalledWith({ source: 'pricing_dialog', payment_intent_source: 'subscribe_to_run' }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'succeeded', outcome: 'success', @@ -4314,7 +4309,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Resubscribe failed for person@example.com' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -4332,18 +4327,18 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).toHaveBeenCalledOnce() - expect(mockTrackResubscribeClicked).toHaveBeenCalledOnce() - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackResubscribeClicked).toHaveBeenCalledOnce() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', source: 'pricing_dialog', payment_intent_source: 'subscribe_to_run' }) - expect(mockTrackBillingEvent).toHaveBeenCalledTimes(1) + expect(dispatcher.trackBillingEvent).toHaveBeenCalledTimes(1) }) it('fires resubscribe failure telemetry on the legacy rail too', async () => { @@ -4354,7 +4349,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -4390,7 +4385,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).not.toHaveBeenCalled() - expect(mockTrackResubscribeClicked).not.toHaveBeenCalled() + expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() }) it('does not resubscribe when the server denies reactivation to a client-side owner', async () => { @@ -4401,7 +4396,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).not.toHaveBeenCalled() - expect(mockTrackResubscribeClicked).not.toHaveBeenCalled() + expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() }) it('emits started before the awaited resubscribe call resolves', async () => { @@ -4410,7 +4405,7 @@ describe('useSubscriptionCheckout', () => { callOrder.push('resubscribe') return { billing_op_id: 'op-4', status: 'active' } }) - mockTrackBillingEvent.mockImplementationOnce( + dispatcher.trackBillingEvent.mockImplementationOnce( (event: { stage: string }) => { callOrder.push(`trackBillingEvent:${event.stage}`) } diff --git a/src/platform/workspace/composables/useWorkspaceBilling.test.ts b/src/platform/workspace/composables/useWorkspaceBilling.test.ts index 53a59d39efb..eafb94ee741 100644 --- a/src/platform/workspace/composables/useWorkspaceBilling.test.ts +++ b/src/platform/workspace/composables/useWorkspaceBilling.test.ts @@ -1,10 +1,11 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { billingOperation } from './billingOperationTestUtils' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { effectScope } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import type { BillingStatusResponse, SubscribeResponse @@ -84,13 +85,10 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: mockReportError })) -const mockTrackBillingEvent = vi.hoisted(() => vi.fn()) - vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackBillingEvent = mockTrackBillingEvent -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) let scope: ReturnType | undefined @@ -1177,7 +1175,7 @@ describe('useWorkspaceBilling', () => { const billing = setupBilling() await billing.cancelSubscription() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -1195,7 +1193,7 @@ describe('useWorkspaceBilling', () => { await expect(billing.cancelSubscription()).rejects.toThrow( 'Upstream failure' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -1213,7 +1211,7 @@ describe('useWorkspaceBilling', () => { const billing = setupBilling() await expect(billing.cancelSubscription()).rejects.toThrow() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'network' }) ) }) @@ -1235,7 +1233,7 @@ describe('useWorkspaceBilling', () => { await expect(billing.cancelSubscription()).rejects.toThrow( 'processor rejected' ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) }) @@ -1273,16 +1271,16 @@ describe('useWorkspaceBilling', () => { expect(billing.subscription.value?.tier).toBe('CREATOR') expect(useBillingOperationStore().startOperation).not.toHaveBeenCalled() expect(billing.isLoading.value).toBe(false) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', operation_type: 'cancel' }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', diff --git a/src/platform/workspace/stores/billingOperationStore.test.ts b/src/platform/workspace/stores/billingOperationStore.test.ts index 171338a0cba..303d3172b63 100644 --- a/src/platform/workspace/stores/billingOperationStore.test.ts +++ b/src/platform/workspace/stores/billingOperationStore.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { bindOperationToCheckoutJourney, @@ -8,7 +7,9 @@ import { } from '@/platform/workspace/utils/checkoutJourney' import { useToastStore } from '@/platform/updates/common/toastStore' import { useDialogStore } from '@/stores/dialogStore' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import type { BillingOpStatusResponse } from '@/platform/workspace/api/workspaceApi' @@ -81,16 +82,10 @@ vi.mock(import('@/platform/settings/composables/useSettingsDialog'), () => ({ }) })) -const mockTrackBillingEvent = vi.fn() -const mockTrackMonthlySubscriptionSucceeded = vi.fn() - vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackBillingEvent = mockTrackBillingEvent - telemetryMock.trackMonthlySubscriptionSucceeded = - mockTrackMonthlySubscriptionSucceeded -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) import { workspaceApi } from '@/platform/workspace/api/workspaceApi' @@ -392,7 +387,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent.mock.calls).toEqual([ + expect(dispatcher.trackBillingEvent.mock.calls).toEqual([ [ { operation: 'operation', @@ -435,7 +430,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent.mock.calls).toEqual([ + expect(dispatcher.trackBillingEvent.mock.calls).toEqual([ [ { operation: 'operation', @@ -562,7 +557,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'succeeded', outcome: 'success', @@ -593,13 +588,15 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackMonthlySubscriptionSucceeded).toHaveBeenCalledWith({ - tier: 'creator', - cycle: 'yearly', - checkout_type: 'new', - payment_intent_source: undefined, - billing_op_id: 'op-1' - }) + expect(dispatcher.trackMonthlySubscriptionSucceeded).toHaveBeenCalledWith( + { + tier: 'creator', + cycle: 'yearly', + checkout_type: 'new', + payment_intent_source: undefined, + billing_op_id: 'op-1' + } + ) }) it('does not fire the generic subscription-success event for topup or cancel', async () => { @@ -614,7 +611,9 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() + expect( + dispatcher.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() }) it('does not fire the generic subscription-success event for a downgrade-to-personal success', async () => { @@ -642,8 +641,10 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect( + dispatcher.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal' }) ) }) @@ -669,10 +670,10 @@ describe('billingOperationStore', () => { } }) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'succeeded', outcome: 'success', @@ -697,7 +698,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', @@ -728,7 +729,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -781,11 +782,13 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - const successCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => - event.operation === 'operation' && event.stage === 'succeeded' - ) - expect(successCall?.[0].duration_ms).toBeGreaterThanOrEqual(1500) + const successEvent = dispatcher.trackBillingEvent.mock.calls + .map(([event]) => event) + .find( + (event) => + event.operation === 'operation' && event.stage === 'succeeded' + ) + expect(successEvent?.duration_ms).toBeGreaterThanOrEqual(1500) }) it('computes duration_ms from the caller-supplied attemptStartedAt, not from when startOperation() itself ran', async () => { @@ -810,12 +813,14 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - const successCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => event.operation === 'topup' && event.stage === 'succeeded' - ) + const successEvent = dispatcher.trackBillingEvent.mock.calls + .map(([event]) => event) + .find( + (event) => event.operation === 'topup' && event.stage === 'succeeded' + ) // Poll-observed time alone is ~1500ms; duration_ms must also include the // 300ms initiation latency that preceded startOperation() running. - expect(successCall?.[0].duration_ms).toBeGreaterThanOrEqual(1800) + expect(successEvent?.duration_ms).toBeGreaterThanOrEqual(1800) }) it('removes the received toast when operation succeeds', async () => { @@ -927,7 +932,7 @@ describe('billingOperationStore', () => { detail: 'billingOperation.subscriptionFailedDetail', life: 7000 }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -954,7 +959,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'topup', failure_category: 'provider_decline' @@ -979,7 +984,7 @@ describe('billingOperationStore', () => { expect(useToastStore().add).not.toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed', billing_op_id: 'op-1', @@ -1000,7 +1005,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'cancel', failure_category: 'api_rejected' @@ -1030,21 +1035,21 @@ describe('billingOperationStore', () => { // Both emissions must agree: a downgrade that was merely replaced is not // an unexplained billing failure in either event stream. - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', failure_category: 'stale_operation' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal', stage: 'failed', failure_category: 'stale_operation' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'unknown' }) ) }) @@ -1068,17 +1073,19 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', duration_ms: expect.any(Number) }) ) - const failureCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => event.operation === 'operation' && event.stage === 'failed' - ) - expect(failureCall?.[0].duration_ms).toBeGreaterThanOrEqual(1500) + const failureEvent = dispatcher.trackBillingEvent.mock.calls + .map(([event]) => event) + .find( + (event) => event.operation === 'operation' && event.stage === 'failed' + ) + expect(failureEvent?.duration_ms).toBeGreaterThanOrEqual(1500) }) it('uses default message when no error_message in response', async () => { @@ -1122,20 +1129,20 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', operation_type: 'subscription', failure_category: 'api_rejected' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal', failure_category: 'api_rejected' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'provider_decline' }) ) }) @@ -1153,7 +1160,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'subscription', failure_category: 'network' @@ -1901,7 +1908,7 @@ describe('billingOperationStore', () => { }) await vi.advanceTimersByTimeAsync(60_000) expect(workspaceApi.getBillingOpStatus).toHaveBeenCalledOnce() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -1914,7 +1921,7 @@ describe('billingOperationStore', () => { failure_category: 'reconciliation_needed', duration_ms: 0 }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -2058,18 +2065,20 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(121_000) await vi.runAllTimersAsync() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'timeout', duration_ms: expect.any(Number) }) ) - const timeoutCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => - event.operation === 'operation' && event.stage === 'timeout' - ) - expect(timeoutCall?.[0].duration_ms).toBeGreaterThanOrEqual(120_000) + const timeoutEvent = dispatcher.trackBillingEvent.mock.calls + .map(([event]) => event) + .find( + (event) => + event.operation === 'operation' && event.stage === 'timeout' + ) + expect(timeoutEvent?.duration_ms).toBeGreaterThanOrEqual(120_000) }) it('keeps a valid action URL pending past discovery and clears it on success', async () => { @@ -2113,9 +2122,9 @@ describe('billingOperationStore', () => { expect( JSON.stringify(vi.mocked(useToastStore().add).mock.calls) ).not.toContain(actionUrl) - expect(JSON.stringify(mockTrackBillingEvent.mock.calls)).not.toContain( - actionUrl - ) + expect( + JSON.stringify(dispatcher.trackBillingEvent.mock.calls) + ).not.toContain(actionUrl) }) it('replaces the processing toast when the operation parks on a bank challenge', async () => { @@ -2469,7 +2478,7 @@ describe('billingOperationStore', () => { ).toHaveBeenCalledWith({ isSubscribed: false }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -2532,7 +2541,7 @@ describe('billingOperationStore', () => { useTeamWorkspaceStore().updateActiveWorkspace ).not.toHaveBeenCalled() expect(useToastStore().add).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', @@ -2568,7 +2577,7 @@ describe('billingOperationStore', () => { useTeamWorkspaceStore().updateActiveWorkspace ).not.toHaveBeenCalled() expect(useToastStore().add).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'timeout', diff --git a/src/platform/workspace/stores/useWorkspaceAuth.test.ts b/src/platform/workspace/stores/useWorkspaceAuth.test.ts index f8bec73a121..3594819db30 100644 --- a/src/platform/workspace/stores/useWorkspaceAuth.test.ts +++ b/src/platform/workspace/stores/useWorkspaceAuth.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useAuthStore } from '@/stores/authStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useToastStore } from '@/platform/updates/common/toastStore' @@ -10,7 +9,9 @@ import { } from 'firebase/auth' import { storeToRefs } from 'pinia' import { nextTick } from 'vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useTelemetry } from '@/platform/telemetry' import { useWorkspaceAuthStore, @@ -25,8 +26,6 @@ import { WORKSPACE_STORAGE_KEYS } from '@/platform/workspace/workspaceConstants' vi.mock(import('firebase/auth'), { spy: true }) -const mockTrackUnifiedAuthRefresh = vi.fn() - /** * Stands in for Firebase behind the store's identity entry: assigning * `value` moves the store's user AND fires the port, the way a real @@ -73,9 +72,8 @@ vi.mock(import('@/platform/auth/session/useSessionCookie'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackUnifiedAuthRefresh = mockTrackUnifiedAuthRefresh -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) vi.mock(import('@/platform/workspace/api/workspaceApiUrl'), () => ({ workspaceApiUrl: (route: string) => `https://api.example.com/api${route}` @@ -3062,7 +3060,7 @@ describe('useWorkspaceAuthStore', () => { expect(useToastStore().add).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error', detail: detailKey }) ) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'permanent_failure', retry_count: 0 }) @@ -3199,7 +3197,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(refreshDelay) expect(mockFetch).toHaveBeenCalledTimes(2) expect(useAuthStore().notifyTokenRefreshed).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', retry_count: 1 }) @@ -3208,7 +3206,7 @@ describe('useWorkspaceAuthStore', () => { expect(mockFetch).toHaveBeenCalledTimes(3) expect(useAuthStore().notifyTokenRefreshed).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'succeeded' }) expect(unifiedToken.value).toBe('unified-token-1') @@ -3252,7 +3250,7 @@ describe('useWorkspaceAuthStore', () => { const store = useWorkspaceAuthStore() await store.mintAtLogin() await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', retry_count: 1 }) @@ -3263,7 +3261,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) expect( - mockTrackUnifiedAuthRefresh, + dispatcher.trackUnifiedAuthRefresh, 'a successful mint starts a fresh retry chain; a stale count here poisons the exhaustion signal' ).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', @@ -3306,7 +3304,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(20000) expect(mockFetch).toHaveBeenCalledTimes(5) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retries_exhausted', retry_count: 3 }) @@ -3319,7 +3317,7 @@ describe('useWorkspaceAuthStore', () => { expect(mockFetch).toHaveBeenCalledTimes(5) expect(useToastStore().add).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'expired', retry_count: 3 }) @@ -3379,7 +3377,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) await vi.advanceTimersByTimeAsync(5000 + 10_000 + 20_000) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retries_exhausted', retry_count: 3 }) @@ -3392,7 +3390,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(5 * 60 * 1000) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'expired', retry_count: 3 }) diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts index 13851dc6a0f..bf737447d30 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts @@ -1,11 +1,12 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useDialogStore } from '@/stores/dialogStore' import { fromPartial } from '@total-typescript/shoehorn' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import enMessages from '@/locales/en/main.json' with { type: 'json' } import FirstRunTourNudge from './FirstRunTourNudge.vue' @@ -17,12 +18,10 @@ const mocks = await vi.hoisted(async () => { return { nudgeArmed: ref(false), tourWasCompleted: ref(true), - dismissNudge: vi.fn(() => { mocks.nudgeArmed.value = false }), - showTemplates: vi.fn(), - trackOnboardingTour: vi.fn() + showTemplates: vi.fn() } }) @@ -43,9 +42,8 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackOnboardingTour = mocks.trackOnboardingTour -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const i18n = createI18n({ legacy: false, @@ -86,7 +84,7 @@ describe('FirstRunTourNudge', () => { nudge(), 'a nudge armed before this mounted still has to appear' ).not.toBeNull() - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { + expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { tour: 'firstRun', tour_completed: true }) @@ -125,7 +123,7 @@ describe('FirstRunTourNudge', () => { 'a nudge that came due behind a dialog would land on top of the modal' ).toBeNull() expect( - mocks.trackOnboardingTour, + dispatcher.trackOnboardingTour, 'a nudge nobody can see has not been shown' ).not.toHaveBeenCalledWith('nudge_shown', expect.anything()) }) @@ -140,7 +138,7 @@ describe('FirstRunTourNudge', () => { useDialogStore().dialogStack = [] await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - const shown = mocks.trackOnboardingTour.mock.calls.filter( + const shown = dispatcher.trackOnboardingTour.mock.calls.filter( ([stage]) => stage === 'nudge_shown' ) expect( @@ -222,7 +220,7 @@ describe('FirstRunTourNudge', () => { 'the source is what separates a nudge conversion from a command-palette one, and it defaults to command' ).toHaveBeenCalledWith('first_run_nudge') expect(mocks.dismissNudge).toHaveBeenCalled() - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( + expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', { tour: 'firstRun', tour_completed: true } ) @@ -240,11 +238,11 @@ describe('FirstRunTourNudge', () => { // Both events carry it, so the funnel can be read end to end: without it // a conversion from a finished tour and one from a tour that never // started are indistinguishable. - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { + expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { tour: 'firstRun', tour_completed: false }) - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( + expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', { tour: 'firstRun', tour_completed: false } ) diff --git a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts index e4f1bbd0191..d93ed732878 100644 --- a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts +++ b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts @@ -1,13 +1,14 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' /* eslint-disable testing-library/no-container, testing-library/no-node-access */ /* eslint-disable testing-library/prefer-user-event */ import { render, screen, fireEvent } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import { getActivePinia } from 'pinia' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { downloadFile } from '@/base/common/downloadUtil' import ImagePreview from '@/renderer/extensions/vueNodes/components/ImagePreview.vue' @@ -20,12 +21,10 @@ vi.mock(import('@/services/hdrViewerService'), () => ({ openHdrViewer: vi.fn() })) -const mockTrackImageLoadFailed = vi.fn() vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackImageLoadFailed = mockTrackImageLoadFailed -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) const i18n = createI18n({ legacy: false, @@ -171,7 +170,7 @@ describe('ImagePreview', () => { expect( screen.queryByRole('button', { name: 'Download image' }) ).not.toBeInTheDocument() - expect(mockTrackImageLoadFailed).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackImageLoadFailed).toHaveBeenCalledExactlyOnceWith({ source: 'node_image_preview' }) }) diff --git a/src/stores/__tests__/authTokenPriority.test.ts b/src/stores/__tests__/authTokenPriority.test.ts index 00a1d404f5c..3cd21bb2226 100644 --- a/src/stores/__tests__/authTokenPriority.test.ts +++ b/src/stores/__tests__/authTokenPriority.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useWorkspaceAuthStore } from '@/platform/workspace/stores/workspaceAuthStore' @@ -36,10 +35,6 @@ vi.mock(import('firebase/auth')) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackAuth = vi.fn() -}) - vi.mock(import('@/services/dialogService')) vi.mock(import('@/platform/distribution/types'), () => mockDistributionTypes) diff --git a/src/stores/apiKeyAuthStore.integration.test.ts b/src/stores/apiKeyAuthStore.integration.test.ts index 6d27e7c3402..23af20e45c1 100644 --- a/src/stores/apiKeyAuthStore.integration.test.ts +++ b/src/stores/apiKeyAuthStore.integration.test.ts @@ -1,4 +1,3 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import type { User } from 'firebase/auth' import * as firebaseAuth from 'firebase/auth' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -33,10 +32,6 @@ vi.mock(import('@/composables/useFeatureFlags'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackAuth = vi.fn() -}) - vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ showErrorDialog: vi.fn() }) })) diff --git a/src/stores/authStore.test.ts b/src/stores/authStore.test.ts index cd2826be2b9..85df3b54be9 100644 --- a/src/stores/authStore.test.ts +++ b/src/stores/authStore.test.ts @@ -1,13 +1,14 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { FirebaseError } from 'firebase/app' import type { User, UserCredential } from 'firebase/auth' import * as firebaseAuth from 'firebase/auth' import type { Mock } from 'vitest' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import * as vuefire from 'vuefire' +import { useTelemetry } from '@/platform/telemetry' + import { i18n } from '@/i18n' import { capturePreservedQuery, @@ -95,12 +96,10 @@ vi.mock(import('vuefire'), () => ({ vi.mock(import('firebase/auth')) -const mockTrackAuth = vi.fn() vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackAuth = mockTrackAuth -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) let mockResetSocket: Mock @@ -1536,7 +1535,7 @@ describe('useAuthStore', () => { await store[method]() - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(dispatcher.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: true }) ) } @@ -1553,7 +1552,7 @@ describe('useAuthStore', () => { await store[method]({ isNewUser: true }) - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(dispatcher.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: true }) ) } @@ -1570,7 +1569,7 @@ describe('useAuthStore', () => { await store[method]() - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(dispatcher.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: false }) ) } @@ -1583,7 +1582,7 @@ describe('useAuthStore', () => { await store[method]() - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(dispatcher.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: false }) ) } @@ -1634,7 +1633,7 @@ describe('useAuthStore', () => { await store.register('new@example.com', 'password') - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(dispatcher.trackAuth).toHaveBeenCalledWith({ method: 'email', is_new_user: true, user_id: 'test-user-id', @@ -1649,7 +1648,7 @@ describe('useAuthStore', () => { await store.login('test@example.com', 'password') - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(dispatcher.trackAuth).toHaveBeenCalledWith({ method: 'email', is_new_user: false, user_id: 'test-user-id', @@ -1664,7 +1663,7 @@ describe('useAuthStore', () => { await store.loginWithGoogle() - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(dispatcher.trackAuth).toHaveBeenCalledWith({ method: 'google', is_new_user: true, user_id: 'test-user-id', @@ -1679,7 +1678,7 @@ describe('useAuthStore', () => { await store.loginWithGithub() - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(dispatcher.trackAuth).toHaveBeenCalledWith({ method: 'github', is_new_user: true, user_id: 'test-user-id', diff --git a/src/stores/executionStore.test.ts b/src/stores/executionStore.test.ts index fefc28ba1bf..ff61ad1cb2c 100644 --- a/src/stores/executionStore.test.ts +++ b/src/stores/executionStore.test.ts @@ -1,10 +1,11 @@ -import { telemetryMock } from '@/platform/telemetry/__mocks__' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import type { LoadedComfyWorkflow } from '@/platform/workflow/management/stores/comfyWorkflow' import { fromPartial } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { app } from '@/scripts/app' import { api } from '@/scripts/api' import { MAX_PROGRESS_JOBS, useExecutionStore } from '@/stores/executionStore' @@ -18,19 +19,9 @@ import { executionIdToNodeLocatorId } from '@/utils/graphTraversalUtil' import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' import type { NodeProgressState } from '@/schemas/apiSchema' -const { - mockShowTextPreview, - mockTrackExecutionError, - mockTrackExecutionOutcome, - mockTrackExecutionSuccess, - mockTrackSharedWorkflowRun -} = await vi.hoisted(async () => { +const { mockShowTextPreview } = await vi.hoisted(async () => { return { - mockShowTextPreview: vi.fn(), - mockTrackExecutionError: vi.fn(), - mockTrackExecutionOutcome: vi.fn(), - mockTrackExecutionSuccess: vi.fn(), - mockTrackSharedWorkflowRun: vi.fn() + mockShowTextPreview: vi.fn() } }) @@ -60,12 +51,8 @@ vi.mock(import('@/platform/distribution/types'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - telemetryMock.trackExecutionError = mockTrackExecutionError - telemetryMock.trackExecutionOutcome = mockTrackExecutionOutcome - telemetryMock.trackExecutionSuccess = mockTrackExecutionSuccess - telemetryMock.trackSharedWorkflowRun = mockTrackSharedWorkflowRun -}) +const dispatcher = vi.mocked(useTelemetry(), { deep: true }) +assert.exists(dispatcher) // Remove any previous global types declare global { @@ -608,7 +595,7 @@ describe('useExecutionStore - workflowStatus', () => { callStoreJob('job-1', workflowA) fireExecutionStart('job-1') - expect(mockTrackExecutionOutcome).not.toHaveBeenCalled() + expect(dispatcher.trackExecutionOutcome).not.toHaveBeenCalled() expect(store.getWorkflowStatus(workflowA)).toBe('running') }) @@ -629,7 +616,7 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionSuccess('job-1') callStoreJob('job-1', workflowA) - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -652,7 +639,7 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionError('job-1') callStoreJob('job-1', workflowA) - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -683,7 +670,7 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -708,7 +695,7 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionSuccess('job-1') fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledOnce() + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledOnce() } finally { now.mockRestore() } @@ -726,7 +713,7 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -766,7 +753,7 @@ describe('useExecutionStore - workflowStatus', () => { }) fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledWith( + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledWith( expect.objectContaining({ startTime: 42, success: true, @@ -786,7 +773,7 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionError('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -810,7 +797,7 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionInterrupted('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -906,7 +893,7 @@ describe('useExecutionStore - workflowStatus', () => { }) ) - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -2485,8 +2472,8 @@ describe('useExecutionStore - WebSocket event handlers', () => { it('does not track success for jobs this client did not queue', () => { fire('execution_success', { prompt_id: 'foreign-job', timestamp: 0 }) - expect(mockTrackExecutionSuccess).not.toHaveBeenCalled() - expect(mockTrackSharedWorkflowRun).not.toHaveBeenCalled() + expect(dispatcher.trackExecutionSuccess).not.toHaveBeenCalled() + expect(dispatcher.trackSharedWorkflowRun).not.toHaveBeenCalled() }) it('tracks shared workflow run when the queued workflow has share attribution', () => { @@ -2505,10 +2492,10 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackExecutionSuccess).toHaveBeenCalledWith({ + expect(dispatcher.trackExecutionSuccess).toHaveBeenCalledWith({ jobId: 'job-1' }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2531,7 +2518,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2556,7 +2543,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { mockAppModeState.isAppMode.value = true fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2580,7 +2567,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'app', From b86dccb67f5059fed3edd92437169e8c63e2b23c Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 15 Sep 2026 02:09:32 +0000 Subject: [PATCH 4/6] test: declare the convention-loaded telemetry mock entry point --- .fallowrc.jsonc | 1 + 1 file changed, 1 insertion(+) diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc index f138ebc4694..f1d2223650a 100644 --- a/.fallowrc.jsonc +++ b/.fallowrc.jsonc @@ -5,6 +5,7 @@ // scripts / CI / tool CLIs / Storybook), not imported from the app graph. "entry": [ "src/main.ts", + "src/platform/telemetry/__mocks__/index.ts", "index.html", "scripts/**/*.{js,ts}", "apps/website/src/scripts/**/*.ts", From d5572387b8329b79a135f00c0bf313b64df9d08d Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 15 Sep 2026 02:17:02 +0000 Subject: [PATCH 5/6] test: read telemetry spies directly from the module --- src/components/TopMenuSection.test.ts | 7 +- .../builder/builderViewOptions.test.ts | 9 +- src/components/builder/useBuilderSave.test.ts | 13 +- .../common/WorkflowActionsDropdown.test.ts | 11 +- .../TopUpCreditsDialogContentLegacy.test.ts | 13 +- .../CancelSubscriptionDialogContent.test.ts | 95 +++++++------ .../graph/selectionToolbox/InfoButton.test.ts | 9 +- .../errors/ErrorNodeCard.test.ts | 7 +- .../parameters/SectionWidgets.test.ts | 13 +- .../parameters/WidgetActions.test.ts | 9 +- .../rightSidePanelTabTelemetry.test.ts | 15 ++- src/components/sidebar/SideToolbar.test.ts | 7 +- src/composables/auth/useAuthActions.test.ts | 15 +-- src/composables/useCoreCommands.test.ts | 9 +- src/composables/useTemplateFiltering.test.ts | 7 +- src/platform/auth/unified/remintRetry.test.ts | 37 +++-- .../components/PricingTable.test.ts | 17 +-- .../composables/useSubscriptionDialog.test.ts | 21 ++- .../composables/useTopUpUrlLoader.test.ts | 21 +-- .../launchCancellationFlow.test.ts | 43 +++--- .../teamSubscriptionCheckoutUtil.test.ts | 13 +- src/platform/settings/settingStore.test.ts | 27 ++-- src/platform/support/feedbackDialog.test.ts | 7 +- .../useSearchQueryTracking.test.ts | 15 +-- .../core/services/workflowService.test.ts | 13 +- .../ShareWorkflowDialogContent.test.ts | 9 +- .../useSharedWorkflowUrlLoader.test.ts | 11 +- .../components/InviteMembersForm.test.ts | 15 +-- ...TopUpCreditsDialogContentWorkspace.test.ts | 54 ++++---- .../dialogs/InviteMemberDialogContent.test.ts | 11 +- .../useDowngradeToPersonal.test.ts | 41 +++--- .../composables/useResubscribe.test.ts | 29 ++-- .../useSubscriptionCheckout.test.ts | 127 +++++++++--------- .../composables/useWorkspaceBilling.test.ts | 19 ++- .../stores/billingOperationStore.test.ts | 101 +++++++------- .../workspace/stores/useWorkspaceAuth.test.ts | 25 ++-- .../nudge/FirstRunTourNudge.test.ts | 39 +++--- .../vueNodes/components/ImagePreview.test.ts | 9 +- src/stores/authStore.test.ts | 21 ++- src/stores/executionStore.test.ts | 53 +++++--- 40 files changed, 481 insertions(+), 536 deletions(-) diff --git a/src/components/TopMenuSection.test.ts b/src/components/TopMenuSection.test.ts index d1e16417872..9e0e8285a92 100644 --- a/src/components/TopMenuSection.test.ts +++ b/src/components/TopMenuSection.test.ts @@ -5,7 +5,7 @@ import type { Pinia } from 'pinia' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import type { MenuItem } from 'primevue/menuitem' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { computed, defineComponent, h, nextTick, onMounted, ref } from 'vue' import type { Component } from 'vue' import { createI18n } from 'vue-i18n' @@ -84,9 +84,6 @@ vi.mock(import('@/scripts/app'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - type WrapperOptions = { pinia?: Pinia stubs?: Record @@ -283,7 +280,7 @@ describe('TopMenuSection', () => { screen.getByRole('button', { name: 'Toggle properties panel' }) ) - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'right_side_panel_opened', element_group: 'top_menu' }) diff --git a/src/components/builder/builderViewOptions.test.ts b/src/components/builder/builderViewOptions.test.ts index c2cc42cc690..708e2495a6e 100644 --- a/src/components/builder/builderViewOptions.test.ts +++ b/src/components/builder/builderViewOptions.test.ts @@ -1,4 +1,4 @@ -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -11,9 +11,6 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/scripts/app'), () => { const rootGraph = { extra: {} } return { app: { rootGraph, rootGraphOrUndefined: rootGraph } } @@ -54,12 +51,12 @@ describe('setWorkflowDefaultView', () => { it('tracks telemetry with correct default_view', () => { const workflow = createMockLoadedWorkflow() setWorkflowDefaultView(workflow, true) - expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'app' }) setWorkflowDefaultView(workflow, false) - expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'graph' }) }) diff --git a/src/components/builder/useBuilderSave.test.ts b/src/components/builder/useBuilderSave.test.ts index 970b33cc74a..3b65dce5108 100644 --- a/src/components/builder/useBuilderSave.test.ts +++ b/src/components/builder/useBuilderSave.test.ts @@ -1,5 +1,5 @@ import { fromPartial } from '@total-typescript/shoehorn' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { ref } from 'vue' import { useTelemetry } from '@/platform/telemetry' @@ -41,9 +41,6 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('@/platform/workflow/core/services/workflowService'), () => ({ @@ -213,7 +210,7 @@ describe('useBuilderSave', () => { isApp: true } ) - expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'app' }) }) @@ -231,7 +228,7 @@ describe('useBuilderSave', () => { isApp: false } ) - expect(dispatcher.trackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'graph' }) }) @@ -242,7 +239,7 @@ describe('useBuilderSave', () => { await onSave('new-name', false) - expect(dispatcher.trackDefaultViewSet).not.toHaveBeenCalled() + expect(useTelemetry()?.trackDefaultViewSet).not.toHaveBeenCalled() expect(useDialogStore().closeDialog).not.toHaveBeenCalled() }) @@ -354,7 +351,7 @@ describe('useBuilderSave', () => { expect(useDialogStore().closeDialog).toHaveBeenCalledWith({ key: SUCCESS_DIALOG_KEY }) - expect(dispatcher.trackEnterLinear).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackEnterLinear).toHaveBeenCalledWith({ source: 'app_builder' }) expect(mockSetMode).toHaveBeenCalledWith('app') diff --git a/src/components/common/WorkflowActionsDropdown.test.ts b/src/components/common/WorkflowActionsDropdown.test.ts index ad56787db11..1b87236f259 100644 --- a/src/components/common/WorkflowActionsDropdown.test.ts +++ b/src/components/common/WorkflowActionsDropdown.test.ts @@ -1,6 +1,6 @@ import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' @@ -29,9 +29,6 @@ const spies = vi.hoisted(() => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/composables/useWorkflowActionsMenu'), async () => { const { ref } = await import('vue') return { useWorkflowActionsMenu: () => ({ menuItems: ref([]) }) } @@ -161,7 +158,7 @@ describe('WorkflowActionsDropdown', () => { expect( screen.getByRole('button', { name: /workflow actions/ }) ).toHaveAttribute('aria-expanded', 'false') - expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() expect(spies.markAsSeen).not.toHaveBeenCalled() }) @@ -174,7 +171,7 @@ describe('WorkflowActionsDropdown', () => { expect(vi.mocked(useCommandStore().execute)).not.toHaveBeenCalled() expect(active).toHaveAttribute('aria-expanded', 'true') expect(spies.markAsSeen).toHaveBeenCalled() - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'test', element_group: 'workflow_actions' }) @@ -207,7 +204,7 @@ describe('WorkflowActionsDropdown', () => { expect( screen.getByRole('button', { name: /workflow actions/ }) ).toHaveAttribute('aria-expanded', 'false') - expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() }) it('lets non-trigger keys bubble past the inactive segment', async () => { diff --git a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts index 7efd638be46..a5b27ae54e2 100644 --- a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts +++ b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts @@ -1,6 +1,6 @@ import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@/platform/telemetry' @@ -51,9 +51,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const mockClearPendingTopup = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ clearPendingTopup: mockClearPendingTopup }) @@ -184,7 +181,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -209,7 +206,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -224,7 +221,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -238,7 +235,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', diff --git a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts index 606adbd5a9c..45ea1f41a5d 100644 --- a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts +++ b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts @@ -1,6 +1,6 @@ import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@/platform/telemetry' @@ -105,9 +105,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports @@ -159,15 +156,14 @@ describe('CancelSubscriptionDialogContent', () => { renderComponent() - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( - 'flow_opened', - { - source: 'cancel_plan_menu', - current_tier: 'standard', - cycle: 'yearly', - end_date: '2026-08-01T00:00:00.000Z' - } - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith('flow_opened', { + source: 'cancel_plan_menu', + current_tier: 'standard', + cycle: 'yearly', + end_date: '2026-08-01T00:00:00.000Z' + }) }) it('does not repeat flow_opened when continuing a fallback flow', () => { @@ -175,10 +171,9 @@ describe('CancelSubscriptionDialogContent', () => { renderComponent({ flowAlreadyOpened: true }) - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( - 'flow_opened', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('flow_opened', expect.anything()) }) it('tracks confirmed before the cancel request and no abandoned on success', async () => { @@ -194,14 +189,15 @@ describe('CancelSubscriptionDialogContent', () => { expect(vi.mocked(useDialogStore().closeDialog)).toHaveBeenCalled() ) unmount() - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'confirmed', expect.objectContaining({ current_tier: 'standard' }) ) - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( - 'abandoned', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('abandoned', expect.anything()) }) it('tracks confirmed and failed with message-carrying rejection values', async () => { @@ -214,15 +210,16 @@ describe('CancelSubscriptionDialogContent', () => { ) await waitFor(() => - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'failed', expect.not.objectContaining({ error_message: expect.anything() }) ) ) - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( - 'confirmed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith('confirmed', expect.anything()) }) it('leaves workspace terminal failure telemetry to the billing poller', async () => { @@ -240,10 +237,9 @@ describe('CancelSubscriptionDialogContent', () => { expect.objectContaining({ severity: 'error' }) ) ) - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( - 'failed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('failed', expect.anything()) }) it('tracks abandoned when the user keeps the subscription', async () => { @@ -258,7 +254,9 @@ describe('CancelSubscriptionDialogContent', () => { key: 'cancel-subscription' }) unmount() - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'abandoned', expect.objectContaining({ current_tier: 'standard' }) ) @@ -269,10 +267,12 @@ describe('CancelSubscriptionDialogContent', () => { mockSubscription.value = null const { unmount } = renderComponent() - dispatcher.trackSubscriptionCancellation.mockClear() + vi.mocked(useTelemetry()?.trackSubscriptionCancellation)?.mockClear() unmount() - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'abandoned', expect.objectContaining({ current_tier: 'standard' }) ) @@ -334,10 +334,9 @@ describe('CancelSubscriptionDialogContent', () => { ) expect(mockCancelSubscription).not.toHaveBeenCalled() - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( - 'confirmed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('confirmed', expect.anything()) expect(mockToastAdd).not.toHaveBeenCalled() expect(vi.mocked(useDialogStore().closeDialog)).not.toHaveBeenCalled() }) @@ -371,10 +370,9 @@ describe('CancelSubscriptionDialogContent', () => { ) expect(mockCancelSubscription).not.toHaveBeenCalled() - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( - 'confirmed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('confirmed', expect.anything()) }) it('does not track cancellation failure when status refresh fails after cancellation succeeds', async () => { @@ -396,16 +394,15 @@ describe('CancelSubscriptionDialogContent', () => { key: 'cancel-subscription' }) expect( - dispatcher.trackSubscriptionCancellation.mock.calls.some( - ([stage]) => stage === 'failed' - ) + vi + .mocked(useTelemetry()?.trackSubscriptionCancellation) + ?.mock.calls.some(([stage]) => stage === 'failed') ).toBe(false) unmount() - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalledWith( - 'abandoned', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('abandoned', expect.anything()) }) }) diff --git a/src/components/graph/selectionToolbox/InfoButton.test.ts b/src/components/graph/selectionToolbox/InfoButton.test.ts index bd1c82e565f..c9bd02bfe8a 100644 --- a/src/components/graph/selectionToolbox/InfoButton.test.ts +++ b/src/components/graph/selectionToolbox/InfoButton.test.ts @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import PrimeVue from 'primevue/config' import Tooltip from 'primevue/tooltip' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@/platform/telemetry' @@ -22,9 +22,6 @@ vi.mock(import('@/composables/graph/useSelectionState'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - describe('InfoButton', () => { const i18n = createI18n({ legacy: false, @@ -63,7 +60,7 @@ describe('InfoButton', () => { await clickNodeInfoButton() expect(openNodeInfoMock).toHaveBeenCalled() - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'selection_toolbox_node_info_opened', element_group: 'selection_toolbox' }) @@ -76,6 +73,6 @@ describe('InfoButton', () => { await clickNodeInfoButton() expect(openNodeInfoMock).toHaveBeenCalled() - expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() }) }) diff --git a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts index f4f3c22e813..4fb0630e40e 100644 --- a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts +++ b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts @@ -2,7 +2,7 @@ import { getActivePinia } from 'pinia' import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' import PrimeVue from 'primevue/config' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@/platform/telemetry' @@ -43,9 +43,6 @@ vi.mock(import('@/utils/errorReportUtil'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: vi.fn(() => ({ staticUrls: { @@ -402,7 +399,7 @@ describe('ErrorNodeCard.vue', () => { expect(useCommandStore().execute).toHaveBeenCalledWith( 'Comfy.ContactSupport' ) - expect(dispatcher.trackHelpResourceClicked).toHaveBeenCalledWith( + expect(useTelemetry()?.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'help_feedback', source: 'error_dialog' diff --git a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts index 42ecf023a5c..7504bea5561 100644 --- a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts +++ b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts @@ -1,7 +1,7 @@ import userEvent from '@testing-library/user-event' import { render, screen, waitFor } from '@testing-library/vue' import { fromPartial } from '@total-typescript/shoehorn' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { defineComponent } from 'vue' import { createI18n } from 'vue-i18n' @@ -31,9 +31,6 @@ const animateToBounds = vi.fn() vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const WidgetItemStub = defineComponent({ inheritAttrs: false, emits: ['update:widget-value', 'reset-to-default'], @@ -235,7 +232,9 @@ describe('SectionWidgets', () => { await user.click(screen.getByRole('button', { name: 'Locate' })) - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_locate_node_clicked', element_group: 'right_side_panel_nodes' }) @@ -267,7 +266,9 @@ describe('SectionWidgets', () => { await user.click(screen.getByRole('button', { name: 'Reset all' })) - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_reset_all_parameters_clicked', element_group: 'right_side_panel_nodes' }) diff --git a/src/components/rightSidePanel/parameters/WidgetActions.test.ts b/src/components/rightSidePanel/parameters/WidgetActions.test.ts index c1ca56cf435..a10ba64a0d7 100644 --- a/src/components/rightSidePanel/parameters/WidgetActions.test.ts +++ b/src/components/rightSidePanel/parameters/WidgetActions.test.ts @@ -1,7 +1,7 @@ import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { fromPartial, fromAny } from '@total-typescript/shoehorn' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import type { Slots } from 'vue' import { h } from 'vue' import { createI18n } from 'vue-i18n' @@ -26,9 +26,6 @@ vi.mock(import('@/core/graph/subgraph/promotionUtils'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ prompt: vi.fn() @@ -226,7 +223,7 @@ describe('WidgetActions', () => { await user.click(screen.getByRole('button', { name: /Favorite/ })) expect( - dispatcher.trackWidgetFavoriteToggled + useTelemetry()?.trackWidgetFavoriteToggled ).toHaveBeenCalledExactlyOnceWith({ node_type: 'TestNode', widget_name: 'test_widget', @@ -250,7 +247,7 @@ describe('WidgetActions', () => { await user.click(screen.getByRole('button', { name: /Unfavorite/ })) expect( - dispatcher.trackWidgetFavoriteToggled + useTelemetry()?.trackWidgetFavoriteToggled ).toHaveBeenCalledExactlyOnceWith({ node_type: 'TestNode', widget_name: 'test_widget', diff --git a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts index 049b340eb90..51c58c96fe1 100644 --- a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts +++ b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts @@ -1,19 +1,18 @@ -import { assert, describe, expect, it, vi } from 'vitest' +import { describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - import { trackRightSidePanelTabOpened } from './rightSidePanelTabTelemetry' describe('trackRightSidePanelTabOpened', () => { it('tracks opening the settings tab', () => { trackRightSidePanelTabOpened('settings') - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_settings_tab_opened', element_group: 'right_side_panel' }) @@ -22,7 +21,9 @@ describe('trackRightSidePanelTabOpened', () => { it('tracks opening the info tab', () => { trackRightSidePanelTabOpened('info') - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_info_tab_opened', element_group: 'right_side_panel' }) @@ -33,7 +34,7 @@ describe('trackRightSidePanelTabOpened', () => { (tab) => { trackRightSidePanelTabOpened(tab) - expect(dispatcher.trackUiButtonClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() } ) }) diff --git a/src/components/sidebar/SideToolbar.test.ts b/src/components/sidebar/SideToolbar.test.ts index cc60a58855a..1550f544728 100644 --- a/src/components/sidebar/SideToolbar.test.ts +++ b/src/components/sidebar/SideToolbar.test.ts @@ -1,7 +1,7 @@ import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import PrimeVue from 'primevue/config' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import type { ComponentProps } from 'vue-component-type-helpers' import { createI18n } from 'vue-i18n' @@ -42,9 +42,6 @@ vi.mock(import('@/platform/distribution/types'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const i18n = createI18n({ legacy: false, locale: 'en', @@ -150,7 +147,7 @@ describe('SideToolbar', () => { await user.click(screen.getByRole('button', { name: 'Assets' })) - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'sidebar_tab_assets_media_selected', element_group: 'sidebar' }) diff --git a/src/composables/auth/useAuthActions.test.ts b/src/composables/auth/useAuthActions.test.ts index f5371e1a707..c7258379940 100644 --- a/src/composables/auth/useAuthActions.test.ts +++ b/src/composables/auth/useAuthActions.test.ts @@ -10,7 +10,7 @@ import { } from 'firebase/auth' import type { UserCredential } from 'firebase/auth' import { fromPartial } from '@total-typescript/shoehorn' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -81,9 +81,6 @@ vi.mock(import('@/platform/distribution/types'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ startPendingTopup: mockStartPendingTopup }) })) @@ -387,7 +384,7 @@ describe('useAuthActions auth flow error telemetry', () => { signInWithEmail('user@example.com', 'password') ).resolves.toBeUndefined() - expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/user-not-found', auth_action: 'email_sign_in' }) @@ -407,7 +404,7 @@ describe('useAuthActions auth flow error telemetry', () => { signUpWithEmail('user@example.com', 'password') ).resolves.toBeUndefined() - expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'unknown', auth_action: 'email_sign_up' }) @@ -420,7 +417,7 @@ describe('useAuthActions auth flow error telemetry', () => { await expect(signInWithGoogle({ isNewUser: true })).resolves.toBeUndefined() - expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/popup-closed-by-user', auth_action: 'google_sign_up' }) @@ -433,7 +430,7 @@ describe('useAuthActions auth flow error telemetry', () => { await expect(signInWithGithub({ isNewUser: true })).resolves.toBeUndefined() - expect(dispatcher.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/popup-closed-by-user', auth_action: 'github_sign_up' }) @@ -446,7 +443,7 @@ describe('useAuthActions auth flow error telemetry', () => { await logout() - expect(dispatcher.trackAuthFailed).not.toHaveBeenCalled() + expect(useTelemetry()?.trackAuthFailed).not.toHaveBeenCalled() }) }) diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index 52235b2adfb..a0badf8d003 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -1,5 +1,5 @@ import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -120,9 +120,6 @@ vi.mock(import('@/services/litegraphService'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const mockShowAbout = vi.hoisted(() => vi.fn()) const mockShowSettings = vi.hoisted(() => vi.fn()) vi.mock( @@ -744,7 +741,7 @@ describe('useCoreCommands', () => { it('Comfy.Help.OpenComfyUIIssues opens the GitHub issues URL and tracks telemetry', async () => { await findCmd('Comfy.Help.OpenComfyUIIssues').function() - expect(dispatcher.trackHelpResourceClicked).toHaveBeenCalledWith( + expect(useTelemetry()?.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'github', is_external: true, @@ -757,7 +754,7 @@ describe('useCoreCommands', () => { it('Comfy.Help.OpenComfyOrgDiscord opens the Discord URL and tracks telemetry', async () => { await findCmd('Comfy.Help.OpenComfyOrgDiscord').function() - expect(dispatcher.trackHelpResourceClicked).toHaveBeenCalledWith( + expect(useTelemetry()?.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'discord' }) diff --git a/src/composables/useTemplateFiltering.test.ts b/src/composables/useTemplateFiltering.test.ts index 0915c8028c9..87e23c64d3a 100644 --- a/src/composables/useTemplateFiltering.test.ts +++ b/src/composables/useTemplateFiltering.test.ts @@ -1,7 +1,7 @@ import { useSettingStore } from '@/platform/settings/settingStore' import { useTemplateRankingStore } from '@/stores/templateRankingStore' import { useSystemStatsStore } from '@/stores/systemStatsStore' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick, ref } from 'vue' import { fromPartial } from '@total-typescript/shoehorn' import { until } from '@vueuse/core' @@ -21,9 +21,6 @@ let mockSystemStatsStore: ReturnType vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('@/platform/telemetry/searchQuery/useSearchQueryTracking'), () => ({ @@ -611,7 +608,7 @@ describe('useTemplateFiltering', () => { await vi.runOnlyPendingTimersAsync() expect( - dispatcher.trackTemplateFilterChanged, + useTelemetry()?.trackTemplateFilterChanged, 'telemetry must report the search default, not the persisted browse sort' ).toHaveBeenLastCalledWith( expect.objectContaining({ sort_by: 'popular' }) diff --git a/src/platform/auth/unified/remintRetry.test.ts b/src/platform/auth/unified/remintRetry.test.ts index dd891fe565d..69a232f1f38 100644 --- a/src/platform/auth/unified/remintRetry.test.ts +++ b/src/platform/auth/unified/remintRetry.test.ts @@ -1,7 +1,7 @@ import { useWorkspaceAuthStore } from '@/platform/workspace/stores/workspaceAuthStore' import type { AxiosAdapter } from 'axios' import axios, { AxiosError } from 'axios' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -17,9 +17,6 @@ const { mockRemint, flagState } = vi.hoisted(() => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/composables/useFeatureFlags'), () => ({ useFeatureFlags: () => ({ flags: { @@ -73,7 +70,9 @@ describe('fetchWithUnifiedRemint', () => { const retryHeaders = new Headers(mockFetch.mock.calls[1][1].headers) expect(retryHeaders.get('Authorization')).toBe('Bearer tokenB') expect(retryHeaders.get('Comfy-User')).toBe('u1') - expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'succeeded', final_status: 200 @@ -96,7 +95,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(secondUnauthorized) expect(mockFetch).toHaveBeenCalledTimes(2) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -116,7 +117,7 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(dispatcher.trackUnifiedAuthRetry).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUnifiedAuthRetry).not.toHaveBeenCalled() }) it('does not retry a non-401 response', async () => { @@ -147,7 +148,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -205,7 +208,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -245,7 +250,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -350,7 +357,9 @@ describe('attachUnifiedRemintInterceptor', () => { expect(String(adapter.mock.calls[1][0].headers.Authorization)).toBe( 'Bearer tokenB' ) - expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'axios', outcome: 'succeeded', final_status: 200 @@ -369,7 +378,9 @@ describe('attachUnifiedRemintInterceptor', () => { expect(adapter).toHaveBeenCalledTimes(2) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(dispatcher.trackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'axios', outcome: 'failed', final_status: 401, @@ -389,7 +400,7 @@ describe('attachUnifiedRemintInterceptor', () => { expect(adapter).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(dispatcher.trackUnifiedAuthRetry).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUnifiedAuthRetry).not.toHaveBeenCalled() }) it('does not re-mint a request flagged __skipUnifiedRemint (acceptInvite)', async () => { diff --git a/src/platform/cloud/subscription/components/PricingTable.test.ts b/src/platform/cloud/subscription/components/PricingTable.test.ts index 2271ca89425..9fa999aafea 100644 --- a/src/platform/cloud/subscription/components/PricingTable.test.ts +++ b/src/platform/cloud/subscription/components/PricingTable.test.ts @@ -1,7 +1,7 @@ import { useAuthStore } from '@/stores/authStore' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { computed, nextTick, ref } from 'vue' import { createI18n } from 'vue-i18n' @@ -116,9 +116,6 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('@/platform/telemetry/utils/checkoutAttribution'), () => ({ @@ -263,7 +260,7 @@ describe('PricingTable', () => { await userEvent.click(creatorButton!) await flushPromises() - expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-123', tier: 'creator', cycle: 'yearly', @@ -349,7 +346,7 @@ describe('PricingTable', () => { expect( window.localStorage.getItem(PENDING_SUBSCRIPTION_CHECKOUT_STORAGE_KEY) ).toBeNull() - expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() }) it('should use the latest userId value when it changes after mount', async () => { @@ -369,8 +366,8 @@ describe('PricingTable', () => { await userEvent.click(creatorButton!) await flushPromises() - expect(dispatcher.trackBeginCheckout).toHaveBeenCalledTimes(1) - expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-late', tier: 'creator', cycle: 'yearly', @@ -465,7 +462,7 @@ describe('PricingTable', () => { await userEvent.click(subscribeButton!) await flushPromises() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -494,7 +491,7 @@ describe('PricingTable', () => { await userEvent.click(subscribeButton!) await flushPromises() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'network' }) ) }) diff --git a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts index cac71a77c25..88198ea24ef 100644 --- a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts +++ b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts @@ -2,7 +2,7 @@ import { useDialogStore } from '@/stores/dialogStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' import { useAuthStore } from '@/stores/authStore' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -108,9 +108,6 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('@/platform/workspace/composables/useWorkspaceUI'), () => ({ @@ -335,7 +332,7 @@ describe('useSubscriptionDialog', () => { expect(props).not.toHaveProperty('initialCheckout') const { dialogComponentProps } = mockShowLayoutDialog.mock.calls[0][0] expectRekaPricingDialogProps(dialogComponentProps) - expect(dispatcher.trackSubscription).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'deep_link' }) ) @@ -433,7 +430,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'upgrade_to_add_credits' }) - expect(dispatcher.trackSubscription).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( 'modal_opened', { current_tier: 'standard', @@ -448,7 +445,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) - expect(dispatcher.trackSubscription).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'subscribe_to_run' }) ) @@ -463,7 +460,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) expect(mockShowLayoutDialog).toHaveBeenCalledTimes(1) - expect(dispatcher.trackSubscription).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscription).not.toHaveBeenCalled() }) it('shows the read-only member dialog for out-of-credits too, not the pricing table', () => { @@ -487,7 +484,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) - expect(dispatcher.trackSubscription).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscription).not.toHaveBeenCalled() }) }) @@ -516,7 +513,7 @@ describe('useSubscriptionDialog', () => { expect(mockShowLayoutDialog).toHaveBeenCalledWith( expect.objectContaining({ key: 'subscription-required' }) ) - expect(dispatcher.trackSubscription).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscription).not.toHaveBeenCalled() }) it('falls back to the pricing table for a non-free-tier user', () => { @@ -549,8 +546,8 @@ describe('useSubscriptionDialog', () => { show({ reason: 'out_of_credits' }) - expect(dispatcher.trackSubscription).toHaveBeenCalledTimes(1) - expect(dispatcher.trackSubscription).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'out_of_credits' }) ) diff --git a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts index a2d8553051f..8ad94ecd112 100644 --- a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts +++ b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts @@ -1,5 +1,5 @@ import { fromAny } from '@total-typescript/shoehorn' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -57,9 +57,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - describe('useTopUpUrlLoader', () => { beforeEach(() => { mockRouteQuery.value = {} @@ -96,9 +93,11 @@ describe('useTopUpUrlLoader', () => { const { loadTopUpFromUrl } = useTopUpUrlLoader() await loadTopUpFromUrl() - expect(dispatcher.trackAddApiCreditButtonClicked).toHaveBeenCalledWith({ - source: 'deep_link' - }) + expect(useTelemetry()?.trackAddApiCreditButtonClicked).toHaveBeenCalledWith( + { + source: 'deep_link' + } + ) }) it('retains the deep link until capability loading settles', async () => { @@ -135,7 +134,9 @@ describe('useTopUpUrlLoader', () => { await loadTopUpFromUrl() expect(mockShowTopUpCreditsDialog).not.toHaveBeenCalled() - expect(dispatcher.trackAddApiCreditButtonClicked).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackAddApiCreditButtonClicked + ).not.toHaveBeenCalled() }) it('opens the subscription path without top-up telemetry', async () => { @@ -147,7 +148,9 @@ describe('useTopUpUrlLoader', () => { await loadTopUpFromUrl() expect(mockShowTopUpCreditsDialog).toHaveBeenCalledOnce() - expect(dispatcher.trackAddApiCreditButtonClicked).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackAddApiCreditButtonClicked + ).not.toHaveBeenCalled() }) it('denies, strips, and clears together when the user is not eligible', async () => { diff --git a/src/platform/cloud/subscription/launchCancellationFlow.test.ts b/src/platform/cloud/subscription/launchCancellationFlow.test.ts index 052e7820ad3..1e864664a19 100644 --- a/src/platform/cloud/subscription/launchCancellationFlow.test.ts +++ b/src/platform/cloud/subscription/launchCancellationFlow.test.ts @@ -1,5 +1,5 @@ import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -42,9 +42,6 @@ vi.mock(import('@/platform/cloud/churnkey/churnkeyClient'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - import { launchCancellationFlow } from './launchCancellationFlow' function session( @@ -109,7 +106,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback }) expect(showFallback).toHaveBeenCalledOnce() - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscriptionCancellation).not.toHaveBeenCalled() }) it('cancels workspace billing through the existing API callback', async () => { @@ -127,17 +124,17 @@ describe('launchCancellationFlow', () => { }) expect(mocks.cancelSubscription).toHaveBeenCalledOnce() - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenNthCalledWith( - 1, - 'flow_opened', - { - source: 'cancel_plan_menu', - current_tier: 'pro', - cycle: 'yearly', - end_date: '2026-08-02T00:00:00Z' - } - ) - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenNthCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenNthCalledWith(1, 'flow_opened', { + source: 'cancel_plan_menu', + current_tier: 'pro', + cycle: 'yearly', + end_date: '2026-08-02T00:00:00Z' + }) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenNthCalledWith( 2, 'confirmed', expect.objectContaining({ @@ -153,7 +150,9 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: vi.fn() }) - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenLastCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenLastCalledWith( 'abandoned', expect.objectContaining({ cycle: 'yearly', @@ -172,7 +171,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: preparationFallback }) expect(preparationFallback).toHaveBeenCalledWith() - expect(dispatcher.trackSubscriptionCancellation).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscriptionCancellation).not.toHaveBeenCalled() expect(warn).toHaveBeenCalledWith( 'Failed to prepare Churnkey cancellation flow:', preparationError @@ -188,7 +187,9 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: runtimeFallback }) expect(runtimeFallback).toHaveBeenCalledWith({ flowAlreadyOpened: true }) - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenLastCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenLastCalledWith( 'failed', expect.objectContaining({ cycle: 'yearly', @@ -210,11 +211,11 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback }) - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscriptionCancellation).toHaveBeenCalledWith( 'confirmed', expect.anything() ) - expect(dispatcher.trackSubscriptionCancellation).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscriptionCancellation).toHaveBeenCalledWith( 'failed', expect.objectContaining({ error_message: 'API down' }) ) diff --git a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts index aedd7341ac2..811ebaf7dd7 100644 --- a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts +++ b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts @@ -1,5 +1,5 @@ import { useAuthStore } from '@/stores/authStore' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -31,9 +31,6 @@ vi.mock(import('@/platform/workspace/api/workspaceApi'), () => ({ })) vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - import { performTeamSubscriptionCheckout } from './teamSubscriptionCheckoutUtil' beforeEach(() => { @@ -75,7 +72,7 @@ describe('performTeamSubscriptionCheckout', () => { teamCreditStopId: 'team_700' }) expect(assignedHref).toBe('https://stripe.test/pay') - expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-1', tier: 'team', cycle: 'yearly', @@ -112,7 +109,7 @@ describe('performTeamSubscriptionCheckout', () => { ).rejects.toThrow(/payment URL/) expect(assignedHref).toBeUndefined() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -133,8 +130,8 @@ describe('performTeamSubscriptionCheckout', () => { }) ).rejects.toThrow('subscribe failed') - expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index a95c55374dc..f53544e2932 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -1,4 +1,4 @@ -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -13,9 +13,6 @@ import { app } from '@/scripts/app' vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - // Mock the api vi.mock(import('@/scripts/api'), () => ({ api: { @@ -626,7 +623,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting', previous_value: 'default', new_value: 'newvalue' @@ -643,7 +640,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) it('does not track visible settings that opt out', async () => { @@ -657,7 +654,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) it('tracks visible settings without values when values opt out', async () => { @@ -671,7 +668,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting' }) }) @@ -686,13 +683,13 @@ describe('useSettingStore', () => { }) await store.set('test.setting', 'newvalue') - expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting' }) // Setting the same value again is a no-op and should not re-emit await store.set('test.setting', 'newvalue') - expect(dispatcher.trackSettingChanged).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledTimes(1) }) it('ships previous/new values when the setting opts into includeValues', async () => { @@ -706,7 +703,7 @@ describe('useSettingStore', () => { await store.set('Comfy.ColorPalette', 'light') - expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'Comfy.ColorPalette', previous_value: 'dark', new_value: 'light' @@ -727,7 +724,7 @@ describe('useSettingStore', () => { 'failed' ) - expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) describe('object mutation prevention', () => { @@ -877,8 +874,8 @@ describe('useSettingStore', () => { 'Comfy.Release.Version': '1.0.0' }) - expect(dispatcher.trackSettingChanged).toHaveBeenCalledTimes(1) - expect(dispatcher.trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'Comfy.ColorPalette', previous_value: 'dark', new_value: 'light' @@ -924,7 +921,7 @@ describe('useSettingStore', () => { await store.setMany({ 'Comfy.Release.Version': 'existing' }) expect(api.storeSettings).not.toHaveBeenCalled() - expect(dispatcher.trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) }) }) diff --git a/src/platform/support/feedbackDialog.test.ts b/src/platform/support/feedbackDialog.test.ts index 2739e27c8ba..e40d88082f3 100644 --- a/src/platform/support/feedbackDialog.test.ts +++ b/src/platform/support/feedbackDialog.test.ts @@ -1,4 +1,4 @@ -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -17,9 +17,6 @@ vi.mock(import('@/platform/surveys/openTypeformDialog'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const userEmail = vi.hoisted((): { value: string | undefined } => ({ value: undefined })) @@ -64,7 +61,7 @@ describe('openFeedbackDialog', () => { it('tracks the button click tagged with the opening source', () => { openFeedbackDialog('topbar') - expect(dispatcher.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'feedback_button_clicked', element_group: 'topbar' }) diff --git a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts index 6c42860d32c..98e55ab31d2 100644 --- a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts +++ b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts @@ -1,4 +1,4 @@ -import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { EffectScope, Ref } from 'vue' import { effectScope, ref } from 'vue' @@ -6,9 +6,6 @@ import { useTelemetry } from '@/platform/telemetry' vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - import { useSearchQueryTracking } from './useSearchQueryTracking' describe('useSearchQueryTracking', () => { @@ -41,7 +38,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = ' hello ' await vi.advanceTimersByTimeAsync(500) - expect(dispatcher.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'hello', query_length: 5, @@ -56,7 +53,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = 'nothingmatches' await vi.advanceTimersByTimeAsync(500) - expect(dispatcher.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'nothingmatches', query_length: 14, @@ -71,7 +68,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = ' ' await vi.advanceTimersByTimeAsync(500) - expect(dispatcher.trackSearchQuery).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSearchQuery).not.toHaveBeenCalled() }) it('cancels a pending debounced call when the scope is disposed', async () => { @@ -81,7 +78,7 @@ describe('useSearchQueryTracking', () => { query.value = 'hello' scope.stop() await vi.advanceTimersByTimeAsync(500) - expect(dispatcher.trackSearchQuery).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSearchQuery).not.toHaveBeenCalled() }) it('truncates query to 100 chars while preserving original length', async () => { @@ -91,7 +88,7 @@ describe('useSearchQueryTracking', () => { const long = 'x'.repeat(250) query.value = long await vi.advanceTimersByTimeAsync(500) - expect(dispatcher.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'x'.repeat(100), query_length: 250, diff --git a/src/platform/workflow/core/services/workflowService.test.ts b/src/platform/workflow/core/services/workflowService.test.ts index d37417a1c08..e547cc9f13f 100644 --- a/src/platform/workflow/core/services/workflowService.test.ts +++ b/src/platform/workflow/core/services/workflowService.test.ts @@ -7,7 +7,7 @@ import { onIdTokenChanged, setPersistence } from 'firebase/auth' -import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -134,9 +134,6 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - function createWorkflow( warnings: PendingWarnings | null = null, options: { loadable?: boolean; path?: string } = {} @@ -2528,8 +2525,8 @@ describe('useWorkflowService', () => { 'workflows/test.app.json' ) expect(workflowStore.saveWorkflow).toHaveBeenCalledWith(copy) - expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledTimes(1) - expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledWith({ is_app: true, is_new: true }) @@ -2566,8 +2563,8 @@ describe('useWorkflowService', () => { isApp: true }) - expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledTimes(1) - expect(dispatcher.trackWorkflowSaved).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledWith({ is_app: true, is_new: true }) diff --git a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts index 45659e27ece..516ad0824a3 100644 --- a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts +++ b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts @@ -1,7 +1,7 @@ import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' @@ -11,9 +11,6 @@ import ShareWorkflowDialogContent from '@/platform/workflow/sharing/components/S vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const mockToast = vi.hoisted(() => ({ add: vi.fn() })) vi.mock( @@ -378,7 +375,7 @@ describe('ShareWorkflowDialogContent', () => { 'workflows/test.json', initialShareableAssets ) - expect(dispatcher.trackShareFlow).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareFlow).toHaveBeenCalledWith({ step: 'link_created', source: 'graph_mode', view_mode: 'graph', @@ -400,7 +397,7 @@ describe('ShareWorkflowDialogContent', () => { await userEvent.click(screen.getByRole('button', { name: /Copy link/i })) - expect(dispatcher.trackShareFlow).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareFlow).toHaveBeenCalledWith({ step: 'link_copied', source: 'graph_mode', view_mode: 'graph', diff --git a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts index 6d07d5074f9..0ec03a87f51 100644 --- a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts +++ b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts @@ -1,6 +1,6 @@ import { useDialogStore } from '@/stores/dialogStore' import { fromPartial } from '@total-typescript/shoehorn' -import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { App } from 'vue' import { createApp, defineComponent } from 'vue' @@ -52,9 +52,6 @@ vi.mock(import('@/composables/useAppMode'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('@/platform/workflow/sharing/services/workflowShareService'), () => ({ @@ -249,7 +246,7 @@ describe('useSharedWorkflowUrlLoader', () => { expect(loaded).toBe('not-present') expect(mockShowLayoutDialog).not.toHaveBeenCalled() expect(mockLoadGraphData).not.toHaveBeenCalled() - expect(dispatcher.trackShareLinkOpened).not.toHaveBeenCalled() + expect(useTelemetry()?.trackShareLinkOpened).not.toHaveBeenCalled() }) it('opens dialog immediately with shareId and loads graph on confirm', async () => { @@ -273,7 +270,7 @@ describe('useSharedWorkflowUrlLoader', () => { 'Test Workflow', { openSource: 'shared_url', shareId: 'share-id-1' } ) - expect(dispatcher.trackShareLinkOpened).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareLinkOpened).toHaveBeenCalledWith({ share_id: 'share-id-1', is_authenticated: false, view_mode: 'graph', @@ -297,7 +294,7 @@ describe('useSharedWorkflowUrlLoader', () => { const loaded = await loadSharedWorkflowFromUrl() expect(loaded).toBe('loaded') - expect(dispatcher.trackShareLinkOpened).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareLinkOpened).toHaveBeenCalledWith({ share_id: 'share-id-1', is_authenticated: true, view_mode: 'graph', diff --git a/src/platform/workspace/components/InviteMembersForm.test.ts b/src/platform/workspace/components/InviteMembersForm.test.ts index c6e61fe5deb..e3c401b374f 100644 --- a/src/platform/workspace/components/InviteMembersForm.test.ts +++ b/src/platform/workspace/components/InviteMembersForm.test.ts @@ -1,7 +1,7 @@ import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { render, screen, waitFor } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@/platform/telemetry' @@ -30,9 +30,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const i18n = createI18n({ legacy: false, locale: 'en', @@ -122,7 +119,7 @@ describe('InviteMembersForm', () => { ) expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('a@b.com') expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('c@d.com') - expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'post_upgrade_success', count: 2 }) @@ -221,7 +218,7 @@ describe('InviteMembersForm', () => { expect.objectContaining({ severity: 'error' }) ) expect(emitted().submitted).toBeUndefined() - expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'post_upgrade_success', count: 1 }) @@ -232,8 +229,8 @@ describe('InviteMembersForm', () => { expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledTimes(3) ) expect(emitted().submitted).toEqual([[['ok@x.com', 'fail@x.com']]]) - expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledTimes(2) - expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledTimes(2) + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenLastCalledWith({ source: 'post_upgrade_success', count: 1 }) @@ -257,7 +254,7 @@ describe('InviteMembersForm', () => { expect.objectContaining({ severity: 'error' }) ) expect(emitted().submitted).toBeUndefined() - expect(dispatcher.trackWorkspaceInviteSent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackWorkspaceInviteSent).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() }) diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index 8c1c99a03be..d67976ce102 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -15,7 +15,7 @@ import { useAuthStore } from '@/stores/authStore' import { useDialogStore } from '@/stores/dialogStore' import { render, screen, waitFor } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' @@ -97,11 +97,7 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('firebase/auth'), { spy: true }) - const mockClearPendingTopup = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ clearPendingTopup: mockClearPendingTopup }) @@ -199,7 +195,7 @@ beforeEach(() => { vi.mocked(useDialogStore().closeDialog).mockImplementation(() => {}) Object.assign(useAuthStore(), { userId: 'user-1' }) Object.assign(useTeamWorkspaceStore(), { activeWorkspaceId: 'workspace-1' }) - dispatcher.trackCheckoutJourneyEvent.mockClear() + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mockClear() sessionStorage.clear() clearCheckoutJourney() }) @@ -248,13 +244,13 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'started', outcome: 'pending' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -267,7 +263,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { renderDialog() await waitFor(() => - expect(dispatcher.trackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'entered', entry_flow: 'topup' }) ) ) @@ -276,16 +272,16 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(dispatcher.trackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'operation_linked', billing_op_id: 'op-1' }) ) ) - const phases = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event.phase - ) + const phases = ( + useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + ).map(([event]) => event.phase) expect(phases.indexOf('submitted')).toBeLessThan( phases.indexOf('operation_linked') ) @@ -293,7 +289,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { // One denominator: every phase of a top-up must carry the same journey. const journeyIds = new Set( - dispatcher.trackCheckoutJourneyEvent.mock.calls.map( + (useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? []).map( ([event]) => event.checkout_journey_id ) ) @@ -312,7 +308,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(dispatcher.trackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'submitted' }) ) ) @@ -330,9 +326,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { resolveTopup(topupResponse('completed')) await waitFor(() => expect(mockFetchBalance).toHaveBeenCalled()) - const phases = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event.phase - ) + const phases = ( + useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + ).map(([event]) => event.phase) expect(phases).toContain('submitted') expect(phases).not.toContain('operation_linked') expect(replacement.status).toBe('active') @@ -347,7 +343,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -700,7 +696,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { summary: 'Purchase Failed', detail: 'Failed to purchase credits: An unknown error occurred' }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -722,14 +718,14 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockFetchBalance).toHaveBeenCalledOnce() expect(mockFetchStatus).toHaveBeenCalledOnce() expect(mockShowSettings).toHaveBeenCalledWith('workspace') - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', billing_op_id: 'op-1', duration_ms: expect.any(Number) }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -768,8 +764,8 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledTimes(4) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledTimes(4) + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', @@ -796,7 +792,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { ) expect(mockFetchBalance).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -810,7 +806,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockFetchBalance).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -818,7 +814,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { failure_category: 'provider_decline', duration_ms: expect.any(Number) }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -838,7 +834,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -858,7 +854,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockTopup).not.toHaveBeenCalled() expect( - dispatcher.trackApiCreditTopupButtonPurchaseClicked + useTelemetry()?.trackApiCreditTopupButtonPurchaseClicked ).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() expect(useDialogStore().closeDialog).not.toHaveBeenCalled() diff --git a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts index b63b9dfa9ea..8029b40d6d4 100644 --- a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts +++ b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts @@ -2,7 +2,7 @@ import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspace import { useDialogStore } from '@/stores/dialogStore' import { render, screen, waitFor } from '@testing-library/vue' import userEvent from '@testing-library/user-event' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@/platform/telemetry' @@ -32,9 +32,6 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports () => ({ @@ -197,7 +194,7 @@ describe('InviteMemberDialogContent', () => { expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledTimes(2) expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('a@b.com') expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('c@d.com') - expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'settings_members', count: 2 }) @@ -232,7 +229,7 @@ describe('InviteMemberDialogContent', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(dispatcher.trackWorkspaceInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'settings_members', count: 1 }) @@ -259,7 +256,7 @@ describe('InviteMemberDialogContent', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(dispatcher.trackWorkspaceInviteSent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackWorkspaceInviteSent).not.toHaveBeenCalled() expect(inviteButton()).toBeEnabled() }) diff --git a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts index 46dbf21d21c..85e7949e0f1 100644 --- a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts +++ b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts @@ -1,6 +1,6 @@ import { getActivePinia } from 'pinia' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' -import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { ref } from 'vue' import { useTelemetry } from '@/platform/telemetry' @@ -107,9 +107,6 @@ vi.mock(import('@/config/comfyApi'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - function createMember( overrides: Partial = {} ): WorkspaceMember { @@ -503,15 +500,17 @@ describe('useDowngradeToPersonal', () => { calls.push('remove') return Promise.resolve() }) - dispatcher.trackBillingEvent.mockImplementation((event) => { - if ( - event.stage === 'started' && - (event.operation === 'subscription_checkout' || - event.operation === 'operation') - ) { - calls.push(`${event.operation}-start`) + vi.mocked(useTelemetry()?.trackBillingEvent)?.mockImplementation( + (event) => { + if ( + event.stage === 'started' && + (event.operation === 'subscription_checkout' || + event.operation === 'operation') + ) { + calls.push(`${event.operation}-start`) + } } - }) + ) mockSubscribe.mockImplementation(() => { calls.push('subscribe') return Promise.resolve({ billing_op_id: 'op-1', status: 'subscribed' }) @@ -563,7 +562,7 @@ describe('useDowngradeToPersonal', () => { const result = await downgradeToPersonal('creator-annual') expect(result).toStrictEqual({ preview, response }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'succeeded', outcome: 'success', @@ -689,7 +688,7 @@ describe('useDowngradeToPersonal', () => { attemptStartedAt: expect.any(Number) } ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -737,7 +736,7 @@ describe('useDowngradeToPersonal', () => { await downgradeToPersonal('founder-monthly') - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'started', outcome: 'pending', @@ -757,7 +756,7 @@ describe('useDowngradeToPersonal', () => { 'm2@example.com' ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -768,7 +767,7 @@ describe('useDowngradeToPersonal', () => { error_code: 'member_removal_failed', duration_ms: expect.any(Number) }) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -780,7 +779,7 @@ describe('useDowngradeToPersonal', () => { await expect(downgradeToPersonal('founder-monthly')).rejects.toBe('boom') - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -803,7 +802,7 @@ describe('useDowngradeToPersonal', () => { 'offline' ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -824,7 +823,7 @@ describe('useDowngradeToPersonal', () => { 'offline' ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -845,7 +844,7 @@ describe('useDowngradeToPersonal', () => { 'm1@example.com' ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', diff --git a/src/platform/workspace/composables/useResubscribe.test.ts b/src/platform/workspace/composables/useResubscribe.test.ts index d505e6c2c91..e092a26e264 100644 --- a/src/platform/workspace/composables/useResubscribe.test.ts +++ b/src/platform/workspace/composables/useResubscribe.test.ts @@ -1,4 +1,4 @@ -import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { createApp, defineComponent } from 'vue' import type { App } from 'vue' import { createI18n } from 'vue-i18n' @@ -69,9 +69,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports () => ({ @@ -120,7 +117,7 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).not.toHaveBeenCalled() - expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() expect(state.toastAdd).not.toHaveBeenCalled() expect(isResubscribing.value).toBe(false) }) @@ -134,7 +131,7 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).not.toHaveBeenCalled() - expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() expect(state.toastAdd).not.toHaveBeenCalled() expect(isResubscribing.value).toBe(false) }) @@ -169,7 +166,7 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -188,11 +185,11 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).toHaveBeenCalledOnce() - expect(dispatcher.trackResubscribeClicked).toHaveBeenCalledOnce() - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackResubscribeClicked).toHaveBeenCalledOnce() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -200,7 +197,7 @@ describe('useResubscribe', () => { }) // Exactly one started event on the legacy success rail: the pre-call start, // with no duplicate post-await started/pending emitted after resubscribe() resolves. - expect(dispatcher.trackBillingEvent).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledTimes(1) expect(state.toastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'success' }) ) @@ -221,7 +218,7 @@ describe('useResubscribe', () => { detail: 'Resubscribe failed for person@example.com' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -242,10 +239,10 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -262,7 +259,7 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -276,7 +273,7 @@ describe('useResubscribe', () => { state.resubscribe.mockImplementation(async () => { callOrder.push('resubscribe') }) - dispatcher.trackBillingEvent.mockImplementation( + vi.mocked(useTelemetry()?.trackBillingEvent)?.mockImplementation( (event: { stage: string }) => { callOrder.push(`trackBillingEvent:${event.stage}`) } diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 8d92b5dc296..7ec78c42d88 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -1,5 +1,5 @@ import { render } from '@testing-library/vue' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { computed } from 'vue' import { billingOperation } from './billingOperationTestUtils' import type { BillingOperation } from './billingOperationTestUtils' @@ -381,9 +381,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: mockReportError })) @@ -532,14 +529,14 @@ describe('useSubscriptionCheckout', () => { } mockCanReactivatePlan.value = true mockSubscription.value = null - dispatcher.trackCheckoutJourneyEvent.mockClear() + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mockClear() sessionStorage.clear() clearCheckoutJourney() }) describe('checkout journey instrumentation', () => { function journeyPhases() { - return dispatcher.trackCheckoutJourneyEvent.mock.calls.map( + return (useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? []).map( ([event]) => event.phase ) } @@ -568,9 +565,9 @@ describe('useSubscriptionCheckout', () => { phases.indexOf('operation_linked') ) - const events = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event - ) + const events = ( + useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + ).map(([event]) => event) const opLinked = events.find( (event) => event.phase === 'operation_linked' ) @@ -653,9 +650,9 @@ describe('useSubscriptionCheckout', () => { }) await checkout.handleConfirmTransition() - const events = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event - ) + const events = ( + useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + ).map(([event]) => event) expect(events.some((event) => event.phase === 'operation_linked')).toBe( false ) @@ -664,9 +661,9 @@ describe('useSubscriptionCheckout', () => { it('records a correlated preview failure with no operation id', async () => { await submitRejectedPreview('PREVIEW_FAILED') - const events = dispatcher.trackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event - ) + const events = ( + useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + ).map(([event]) => event) const entered = events.find((event) => event.phase === 'entered') const failed = events.find((event) => event.phase === 'preview_failed') expect(entered).toBeDefined() @@ -1433,9 +1430,9 @@ describe('useSubscriptionCheckout', () => { expect(checkout.previewData.value).toStrictEqual(preview) expect(checkout.checkoutStep.value).toBe('success') - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() - expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith( expect.objectContaining({ tier: 'creator', cycle: 'monthly', @@ -1462,7 +1459,7 @@ describe('useSubscriptionCheckout', () => { }) expect(checkout.checkoutStep.value).toBe('success') - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) }) @@ -2139,7 +2136,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleTeamSubscribe() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'started', outcome: 'pending', @@ -2148,7 +2145,7 @@ describe('useSubscriptionCheckout', () => { checkout_type: 'new', payment_intent_source: undefined }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -2188,7 +2185,7 @@ describe('useSubscriptionCheckout', () => { confirmReactivation: false }) expect(checkout.checkoutStep.value).toBe('success') - expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith( expect.objectContaining({ tier: 'team', checkout_type: 'new', @@ -2376,7 +2373,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'subscription_checkout', stage: 'failed', @@ -2435,7 +2432,7 @@ describe('useSubscriptionCheckout', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('refuses to bill a team reactivation when a fresh preview no longer matches the confirmed charge', async () => { @@ -2523,7 +2520,7 @@ describe('useSubscriptionCheckout', () => { detail: 'status unavailable' }) ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('bounces to pricing when a required reactivation refresh cannot collect consent', async () => { @@ -2622,7 +2619,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) @@ -2643,17 +2640,21 @@ describe('useSubscriptionCheckout', () => { ) expect(checkout.checkoutStep.value).toBe('success') expect( - dispatcher.trackBillingEvent.mock.calls.filter( - ([event]) => - event.operation === 'subscription_checkout' && - event.stage === 'started' - ) + vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.filter( + ([event]) => + event.operation === 'subscription_checkout' && + event.stage === 'started' + ) ).toHaveLength(1) expect( - dispatcher.trackBillingEvent.mock.calls.filter( - ([event]) => - event.operation === 'operation' && event.stage === 'started' - ) + vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.filter( + ([event]) => + event.operation === 'operation' && event.stage === 'started' + ) ).toHaveLength(1) }) @@ -2749,8 +2750,8 @@ describe('useSubscriptionCheckout', () => { detail: 'Team payment failed' }) ) - expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3111,7 +3112,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'started', outcome: 'pending', @@ -3120,7 +3121,7 @@ describe('useSubscriptionCheckout', () => { checkout_type: 'new', payment_intent_source: undefined }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -3151,7 +3152,7 @@ describe('useSubscriptionCheckout', () => { confirmReactivation: false }) expect(checkout.checkoutStep.value).toBe('success') - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'succeeded', outcome: 'success', @@ -3163,7 +3164,7 @@ describe('useSubscriptionCheckout', () => { duration_ms: expect.any(Number) }) expect( - dispatcher.trackMonthlySubscriptionSucceeded + useTelemetry()?.trackMonthlySubscriptionSucceeded ).not.toHaveBeenCalled() expect(mockFetchStatus).toHaveBeenCalledTimes(1) expect(mockFetchBalance).not.toHaveBeenCalled() @@ -3183,7 +3184,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() Object.assign(useAuthStore(), { userId: 'user-1' }) }) @@ -3200,7 +3201,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(dispatcher.trackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-1', tier: 'standard', cycle: 'yearly', @@ -3675,8 +3676,8 @@ describe('useSubscriptionCheckout', () => { detail: 'Payment failed' }) ) - expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3697,7 +3698,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3720,7 +3721,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('does not submit when workspace ownership is revoked', async () => { @@ -3753,7 +3754,7 @@ describe('useSubscriptionCheckout', () => { expect(checkout.checkoutStep.value).toBe('success') expect( - dispatcher.trackMonthlySubscriptionSucceeded + useTelemetry()?.trackMonthlySubscriptionSucceeded ).not.toHaveBeenCalled() }) @@ -3882,7 +3883,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) }) @@ -3999,7 +4000,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation amount changed' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'subscription_checkout', stage: 'failed', @@ -4084,7 +4085,7 @@ describe('useSubscriptionCheckout', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('refuses to bill when a fresh preview no longer matches the confirmed charge', async () => { @@ -4187,7 +4188,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleConfirmTransition() expect(mockSubscribe).not.toHaveBeenCalled() - expect(dispatcher.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() expect(emit).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() }) @@ -4260,7 +4261,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -4282,11 +4283,11 @@ describe('useSubscriptionCheckout', () => { expect(mockResubscribe).toHaveBeenCalled() expect(emit).toHaveBeenCalledWith('close', true) - expect(dispatcher.trackResubscribeClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackResubscribeClicked).toHaveBeenCalledWith({ source: 'pricing_dialog', payment_intent_source: 'subscribe_to_run' }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'succeeded', outcome: 'success', @@ -4309,7 +4310,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Resubscribe failed for person@example.com' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -4327,18 +4328,18 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).toHaveBeenCalledOnce() - expect(dispatcher.trackResubscribeClicked).toHaveBeenCalledOnce() - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackResubscribeClicked).toHaveBeenCalledOnce() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', source: 'pricing_dialog', payment_intent_source: 'subscribe_to_run' }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledTimes(1) }) it('fires resubscribe failure telemetry on the legacy rail too', async () => { @@ -4349,7 +4350,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -4385,7 +4386,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).not.toHaveBeenCalled() - expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() }) it('does not resubscribe when the server denies reactivation to a client-side owner', async () => { @@ -4396,7 +4397,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).not.toHaveBeenCalled() - expect(dispatcher.trackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() }) it('emits started before the awaited resubscribe call resolves', async () => { @@ -4405,7 +4406,7 @@ describe('useSubscriptionCheckout', () => { callOrder.push('resubscribe') return { billing_op_id: 'op-4', status: 'active' } }) - dispatcher.trackBillingEvent.mockImplementationOnce( + vi.mocked(useTelemetry()?.trackBillingEvent)?.mockImplementationOnce( (event: { stage: string }) => { callOrder.push(`trackBillingEvent:${event.stage}`) } diff --git a/src/platform/workspace/composables/useWorkspaceBilling.test.ts b/src/platform/workspace/composables/useWorkspaceBilling.test.ts index eafb94ee741..64abb06bb4e 100644 --- a/src/platform/workspace/composables/useWorkspaceBilling.test.ts +++ b/src/platform/workspace/composables/useWorkspaceBilling.test.ts @@ -1,7 +1,7 @@ import { billingOperation } from './billingOperationTestUtils' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' -import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { effectScope } from 'vue' import { useTelemetry } from '@/platform/telemetry' @@ -87,9 +87,6 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - let scope: ReturnType | undefined function setupBilling() { @@ -1175,7 +1172,7 @@ describe('useWorkspaceBilling', () => { const billing = setupBilling() await billing.cancelSubscription() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -1193,7 +1190,7 @@ describe('useWorkspaceBilling', () => { await expect(billing.cancelSubscription()).rejects.toThrow( 'Upstream failure' ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -1211,7 +1208,7 @@ describe('useWorkspaceBilling', () => { const billing = setupBilling() await expect(billing.cancelSubscription()).rejects.toThrow() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'network' }) ) }) @@ -1233,7 +1230,7 @@ describe('useWorkspaceBilling', () => { await expect(billing.cancelSubscription()).rejects.toThrow( 'processor rejected' ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) }) @@ -1271,16 +1268,16 @@ describe('useWorkspaceBilling', () => { expect(billing.subscription.value?.tier).toBe('CREATOR') expect(useBillingOperationStore().startOperation).not.toHaveBeenCalled() expect(billing.isLoading.value).toBe(false) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', operation_type: 'cancel' }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', diff --git a/src/platform/workspace/stores/billingOperationStore.test.ts b/src/platform/workspace/stores/billingOperationStore.test.ts index 303d3172b63..156378e70c2 100644 --- a/src/platform/workspace/stores/billingOperationStore.test.ts +++ b/src/platform/workspace/stores/billingOperationStore.test.ts @@ -7,7 +7,7 @@ import { } from '@/platform/workspace/utils/checkoutJourney' import { useToastStore } from '@/platform/updates/common/toastStore' import { useDialogStore } from '@/stores/dialogStore' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -84,9 +84,6 @@ vi.mock(import('@/platform/settings/composables/useSettingsDialog'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - import { workspaceApi } from '@/platform/workspace/api/workspaceApi' import { useBillingOperationStore } from './billingOperationStore' @@ -387,7 +384,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent.mock.calls).toEqual([ + expect(vi.mocked(useTelemetry()?.trackBillingEvent)?.mock.calls).toEqual([ [ { operation: 'operation', @@ -430,7 +427,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent.mock.calls).toEqual([ + expect(vi.mocked(useTelemetry()?.trackBillingEvent)?.mock.calls).toEqual([ [ { operation: 'operation', @@ -557,7 +554,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'succeeded', outcome: 'success', @@ -588,15 +585,15 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackMonthlySubscriptionSucceeded).toHaveBeenCalledWith( - { - tier: 'creator', - cycle: 'yearly', - checkout_type: 'new', - payment_intent_source: undefined, - billing_op_id: 'op-1' - } - ) + expect( + useTelemetry()?.trackMonthlySubscriptionSucceeded + ).toHaveBeenCalledWith({ + tier: 'creator', + cycle: 'yearly', + checkout_type: 'new', + payment_intent_source: undefined, + billing_op_id: 'op-1' + }) }) it('does not fire the generic subscription-success event for topup or cancel', async () => { @@ -612,7 +609,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) expect( - dispatcher.trackMonthlySubscriptionSucceeded + useTelemetry()?.trackMonthlySubscriptionSucceeded ).not.toHaveBeenCalled() }) @@ -642,9 +639,9 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) expect( - dispatcher.trackMonthlySubscriptionSucceeded + useTelemetry()?.trackMonthlySubscriptionSucceeded ).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal' }) ) }) @@ -670,10 +667,10 @@ describe('billingOperationStore', () => { } }) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'succeeded', outcome: 'success', @@ -698,7 +695,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', @@ -729,7 +726,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -782,8 +779,9 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - const successEvent = dispatcher.trackBillingEvent.mock.calls - .map(([event]) => event) + const successEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) .find( (event) => event.operation === 'operation' && event.stage === 'succeeded' @@ -813,8 +811,9 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - const successEvent = dispatcher.trackBillingEvent.mock.calls - .map(([event]) => event) + const successEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) .find( (event) => event.operation === 'topup' && event.stage === 'succeeded' ) @@ -932,7 +931,7 @@ describe('billingOperationStore', () => { detail: 'billingOperation.subscriptionFailedDetail', life: 7000 }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -959,7 +958,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'topup', failure_category: 'provider_decline' @@ -984,7 +983,7 @@ describe('billingOperationStore', () => { expect(useToastStore().add).not.toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed', billing_op_id: 'op-1', @@ -1005,7 +1004,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'cancel', failure_category: 'api_rejected' @@ -1035,21 +1034,21 @@ describe('billingOperationStore', () => { // Both emissions must agree: a downgrade that was merely replaced is not // an unexplained billing failure in either event stream. - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', failure_category: 'stale_operation' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal', stage: 'failed', failure_category: 'stale_operation' }) ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'unknown' }) ) }) @@ -1073,15 +1072,16 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', duration_ms: expect.any(Number) }) ) - const failureEvent = dispatcher.trackBillingEvent.mock.calls - .map(([event]) => event) + const failureEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) .find( (event) => event.operation === 'operation' && event.stage === 'failed' ) @@ -1129,20 +1129,20 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', operation_type: 'subscription', failure_category: 'api_rejected' }) ) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal', failure_category: 'api_rejected' }) ) - expect(dispatcher.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'provider_decline' }) ) }) @@ -1160,7 +1160,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'subscription', failure_category: 'network' @@ -1908,7 +1908,7 @@ describe('billingOperationStore', () => { }) await vi.advanceTimersByTimeAsync(60_000) expect(workspaceApi.getBillingOpStatus).toHaveBeenCalledOnce() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -1921,7 +1921,7 @@ describe('billingOperationStore', () => { failure_category: 'reconciliation_needed', duration_ms: 0 }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -2065,15 +2065,16 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(121_000) await vi.runAllTimersAsync() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'timeout', duration_ms: expect.any(Number) }) ) - const timeoutEvent = dispatcher.trackBillingEvent.mock.calls - .map(([event]) => event) + const timeoutEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) .find( (event) => event.operation === 'operation' && event.stage === 'timeout' @@ -2123,7 +2124,7 @@ describe('billingOperationStore', () => { JSON.stringify(vi.mocked(useToastStore().add).mock.calls) ).not.toContain(actionUrl) expect( - JSON.stringify(dispatcher.trackBillingEvent.mock.calls) + JSON.stringify(vi.mocked(useTelemetry()?.trackBillingEvent)?.mock.calls) ).not.toContain(actionUrl) }) @@ -2478,7 +2479,7 @@ describe('billingOperationStore', () => { ).toHaveBeenCalledWith({ isSubscribed: false }) - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -2541,7 +2542,7 @@ describe('billingOperationStore', () => { useTeamWorkspaceStore().updateActiveWorkspace ).not.toHaveBeenCalled() expect(useToastStore().add).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', @@ -2577,7 +2578,7 @@ describe('billingOperationStore', () => { useTeamWorkspaceStore().updateActiveWorkspace ).not.toHaveBeenCalled() expect(useToastStore().add).not.toHaveBeenCalled() - expect(dispatcher.trackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'timeout', diff --git a/src/platform/workspace/stores/useWorkspaceAuth.test.ts b/src/platform/workspace/stores/useWorkspaceAuth.test.ts index 3594819db30..07c51baac66 100644 --- a/src/platform/workspace/stores/useWorkspaceAuth.test.ts +++ b/src/platform/workspace/stores/useWorkspaceAuth.test.ts @@ -9,7 +9,7 @@ import { } from 'firebase/auth' import { storeToRefs } from 'pinia' import { nextTick } from 'vue' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTelemetry } from '@/platform/telemetry' @@ -72,9 +72,6 @@ vi.mock(import('@/platform/auth/session/useSessionCookie'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - vi.mock(import('@/platform/workspace/api/workspaceApiUrl'), () => ({ workspaceApiUrl: (route: string) => `https://api.example.com/api${route}` })) @@ -3060,7 +3057,9 @@ describe('useWorkspaceAuthStore', () => { expect(useToastStore().add).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error', detail: detailKey }) ) - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect( + useTelemetry()?.trackUnifiedAuthRefresh + ).toHaveBeenLastCalledWith({ outcome: 'permanent_failure', retry_count: 0 }) @@ -3197,7 +3196,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(refreshDelay) expect(mockFetch).toHaveBeenCalledTimes(2) expect(useAuthStore().notifyTokenRefreshed).not.toHaveBeenCalled() - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', retry_count: 1 }) @@ -3206,7 +3205,7 @@ describe('useWorkspaceAuthStore', () => { expect(mockFetch).toHaveBeenCalledTimes(3) expect(useAuthStore().notifyTokenRefreshed).toHaveBeenCalledTimes(1) - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'succeeded' }) expect(unifiedToken.value).toBe('unified-token-1') @@ -3250,7 +3249,7 @@ describe('useWorkspaceAuthStore', () => { const store = useWorkspaceAuthStore() await store.mintAtLogin() await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', retry_count: 1 }) @@ -3261,7 +3260,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) expect( - dispatcher.trackUnifiedAuthRefresh, + useTelemetry()?.trackUnifiedAuthRefresh, 'a successful mint starts a fresh retry chain; a stale count here poisons the exhaustion signal' ).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', @@ -3304,7 +3303,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(20000) expect(mockFetch).toHaveBeenCalledTimes(5) - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retries_exhausted', retry_count: 3 }) @@ -3317,7 +3316,7 @@ describe('useWorkspaceAuthStore', () => { expect(mockFetch).toHaveBeenCalledTimes(5) expect(useToastStore().add).not.toHaveBeenCalled() - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'expired', retry_count: 3 }) @@ -3377,7 +3376,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) await vi.advanceTimersByTimeAsync(5000 + 10_000 + 20_000) - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retries_exhausted', retry_count: 3 }) @@ -3390,7 +3389,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(5 * 60 * 1000) - expect(dispatcher.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'expired', retry_count: 3 }) diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts index bf737447d30..d138d5f3df3 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts @@ -2,7 +2,7 @@ import { useDialogStore } from '@/stores/dialogStore' import { fromPartial } from '@total-typescript/shoehorn' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { useTelemetry } from '@/platform/telemetry' @@ -42,9 +42,6 @@ vi.mock( vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const i18n = createI18n({ legacy: false, locale: 'en', @@ -84,10 +81,13 @@ describe('FirstRunTourNudge', () => { nudge(), 'a nudge armed before this mounted still has to appear' ).not.toBeNull() - expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { - tour: 'firstRun', - tour_completed: true - }) + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( + 'nudge_shown', + { + tour: 'firstRun', + tour_completed: true + } + ) }) it('waits out a dialog that is already open', async () => { @@ -123,7 +123,7 @@ describe('FirstRunTourNudge', () => { 'a nudge that came due behind a dialog would land on top of the modal' ).toBeNull() expect( - dispatcher.trackOnboardingTour, + useTelemetry()?.trackOnboardingTour, 'a nudge nobody can see has not been shown' ).not.toHaveBeenCalledWith('nudge_shown', expect.anything()) }) @@ -138,9 +138,9 @@ describe('FirstRunTourNudge', () => { useDialogStore().dialogStack = [] await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - const shown = dispatcher.trackOnboardingTour.mock.calls.filter( - ([stage]) => stage === 'nudge_shown' - ) + const shown = vi + .mocked(useTelemetry()?.trackOnboardingTour) + ?.mock.calls.filter(([stage]) => stage === 'nudge_shown') expect( shown, 'the funnel counts nudges, so a reappearance is not a second one' @@ -220,7 +220,7 @@ describe('FirstRunTourNudge', () => { 'the source is what separates a nudge conversion from a command-palette one, and it defaults to command' ).toHaveBeenCalledWith('first_run_nudge') expect(mocks.dismissNudge).toHaveBeenCalled() - expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith( + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', { tour: 'firstRun', tour_completed: true } ) @@ -238,11 +238,14 @@ describe('FirstRunTourNudge', () => { // Both events carry it, so the funnel can be read end to end: without it // a conversion from a finished tour and one from a tour that never // started are indistinguishable. - expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { - tour: 'firstRun', - tour_completed: false - }) - expect(dispatcher.trackOnboardingTour).toHaveBeenCalledWith( + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( + 'nudge_shown', + { + tour: 'firstRun', + tour_completed: false + } + ) + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', { tour: 'firstRun', tour_completed: false } ) diff --git a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts index d93ed732878..6e40c8c63fb 100644 --- a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts +++ b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts @@ -3,7 +3,7 @@ import { render, screen, fireEvent } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import { getActivePinia } from 'pinia' -import { assert, describe, expect, it, vi } from 'vitest' +import { describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' @@ -23,9 +23,6 @@ vi.mock(import('@/services/hdrViewerService'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - const i18n = createI18n({ legacy: false, locale: 'en', @@ -170,7 +167,9 @@ describe('ImagePreview', () => { expect( screen.queryByRole('button', { name: 'Download image' }) ).not.toBeInTheDocument() - expect(dispatcher.trackImageLoadFailed).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackImageLoadFailed + ).toHaveBeenCalledExactlyOnceWith({ source: 'node_image_preview' }) }) diff --git a/src/stores/authStore.test.ts b/src/stores/authStore.test.ts index 85df3b54be9..d372b8d94bb 100644 --- a/src/stores/authStore.test.ts +++ b/src/stores/authStore.test.ts @@ -4,7 +4,7 @@ import { FirebaseError } from 'firebase/app' import type { User, UserCredential } from 'firebase/auth' import * as firebaseAuth from 'firebase/auth' import type { Mock } from 'vitest' -import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import * as vuefire from 'vuefire' import { useTelemetry } from '@/platform/telemetry' @@ -98,9 +98,6 @@ vi.mock(import('firebase/auth')) vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - let mockResetSocket: Mock // Mock useDialogService @@ -1535,7 +1532,7 @@ describe('useAuthStore', () => { await store[method]() - expect(dispatcher.trackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: true }) ) } @@ -1552,7 +1549,7 @@ describe('useAuthStore', () => { await store[method]({ isNewUser: true }) - expect(dispatcher.trackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: true }) ) } @@ -1569,7 +1566,7 @@ describe('useAuthStore', () => { await store[method]() - expect(dispatcher.trackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: false }) ) } @@ -1582,7 +1579,7 @@ describe('useAuthStore', () => { await store[method]() - expect(dispatcher.trackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: false }) ) } @@ -1633,7 +1630,7 @@ describe('useAuthStore', () => { await store.register('new@example.com', 'password') - expect(dispatcher.trackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'email', is_new_user: true, user_id: 'test-user-id', @@ -1648,7 +1645,7 @@ describe('useAuthStore', () => { await store.login('test@example.com', 'password') - expect(dispatcher.trackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'email', is_new_user: false, user_id: 'test-user-id', @@ -1663,7 +1660,7 @@ describe('useAuthStore', () => { await store.loginWithGoogle() - expect(dispatcher.trackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'google', is_new_user: true, user_id: 'test-user-id', @@ -1678,7 +1675,7 @@ describe('useAuthStore', () => { await store.loginWithGithub() - expect(dispatcher.trackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'github', is_new_user: true, user_id: 'test-user-id', diff --git a/src/stores/executionStore.test.ts b/src/stores/executionStore.test.ts index ff61ad1cb2c..a4935fdf5c2 100644 --- a/src/stores/executionStore.test.ts +++ b/src/stores/executionStore.test.ts @@ -1,7 +1,7 @@ import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import type { LoadedComfyWorkflow } from '@/platform/workflow/management/stores/comfyWorkflow' import { fromPartial } from '@total-typescript/shoehorn' -import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { useTelemetry } from '@/platform/telemetry' @@ -51,9 +51,6 @@ vi.mock(import('@/platform/distribution/types'), () => ({ vi.mock(import('@/platform/telemetry')) -const dispatcher = vi.mocked(useTelemetry(), { deep: true }) -assert.exists(dispatcher) - // Remove any previous global types declare global { interface Window {} @@ -595,7 +592,7 @@ describe('useExecutionStore - workflowStatus', () => { callStoreJob('job-1', workflowA) fireExecutionStart('job-1') - expect(dispatcher.trackExecutionOutcome).not.toHaveBeenCalled() + expect(useTelemetry()?.trackExecutionOutcome).not.toHaveBeenCalled() expect(store.getWorkflowStatus(workflowA)).toBe('running') }) @@ -616,7 +613,9 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionSuccess('job-1') callStoreJob('job-1', workflowA) - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -639,7 +638,9 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionError('job-1') callStoreJob('job-1', workflowA) - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -670,7 +671,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionSuccess('job-1') - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -695,7 +698,7 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionSuccess('job-1') fireExecutionSuccess('job-1') - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledOnce() + expect(useTelemetry()?.trackExecutionOutcome).toHaveBeenCalledOnce() } finally { now.mockRestore() } @@ -713,7 +716,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionSuccess('job-1') - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -753,7 +758,7 @@ describe('useExecutionStore - workflowStatus', () => { }) fireExecutionSuccess('job-1') - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledWith( + expect(useTelemetry()?.trackExecutionOutcome).toHaveBeenCalledWith( expect.objectContaining({ startTime: 42, success: true, @@ -773,7 +778,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionError('job-1') - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -797,7 +804,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionInterrupted('job-1') - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -893,7 +902,9 @@ describe('useExecutionStore - workflowStatus', () => { }) ) - expect(dispatcher.trackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -2472,8 +2483,8 @@ describe('useExecutionStore - WebSocket event handlers', () => { it('does not track success for jobs this client did not queue', () => { fire('execution_success', { prompt_id: 'foreign-job', timestamp: 0 }) - expect(dispatcher.trackExecutionSuccess).not.toHaveBeenCalled() - expect(dispatcher.trackSharedWorkflowRun).not.toHaveBeenCalled() + expect(useTelemetry()?.trackExecutionSuccess).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSharedWorkflowRun).not.toHaveBeenCalled() }) it('tracks shared workflow run when the queued workflow has share attribution', () => { @@ -2492,10 +2503,10 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(dispatcher.trackExecutionSuccess).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackExecutionSuccess).toHaveBeenCalledWith({ jobId: 'job-1' }) - expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2518,7 +2529,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2543,7 +2554,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { mockAppModeState.isAppMode.value = true fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2567,7 +2578,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(dispatcher.trackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'app', From 3c734b19b6a1940c0f5aef99897f6cf618c83b84 Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 15 Sep 2026 05:45:43 +0000 Subject: [PATCH 6/6] test: remove redundant telemetry resets Amp-Thread-ID: https://ampcode.com/threads/T-01a0a2f9-a153-7099-9a4a-1dc942db28ca --- .../rightSidePanel/RightSidePanel.test.ts | 5 ----- .../canvas/visibleCanvasViewport.test.ts | 5 ----- .../cloud/onboarding/CloudSignupView.test.ts | 5 ----- .../composables/useSettingsDialog.test.ts | 5 ----- .../CurrentUserPopoverWorkspace.test.ts | 5 ----- .../TopUpCreditsDialogContentWorkspace.test.ts | 10 +++++----- .../useSubscriptionCheckout.test.ts | 18 +++++++++--------- src/services/dialogService.downgrade.test.ts | 5 ----- src/services/dialogService.renderer.test.ts | 7 +------ .../dialogService.topUpCredits.test.ts | 5 ----- src/views/GraphView.test.ts | 5 ----- .../components/agent/DockedAgentPanel.test.ts | 5 ----- .../agent/dockedAgentPanelLoadFailure.test.ts | 5 ----- .../composables/useAgentDockMount.test.ts | 5 ----- .../stores/agent/agentPanelStoreId.test.ts | 5 ----- 15 files changed, 15 insertions(+), 80 deletions(-) diff --git a/src/components/rightSidePanel/RightSidePanel.test.ts b/src/components/rightSidePanel/RightSidePanel.test.ts index 3d506396ad9..205ce60dc5e 100644 --- a/src/components/rightSidePanel/RightSidePanel.test.ts +++ b/src/components/rightSidePanel/RightSidePanel.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { getActivePinia } from 'pinia' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -35,10 +34,6 @@ vi.mock(import('@/composables/graph/useGraphHierarchy'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - function createPanelI18n() { return createI18n({ legacy: false, diff --git a/src/composables/canvas/visibleCanvasViewport.test.ts b/src/composables/canvas/visibleCanvasViewport.test.ts index ed3882cd94c..a1052359479 100644 --- a/src/composables/canvas/visibleCanvasViewport.test.ts +++ b/src/composables/canvas/visibleCanvasViewport.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { LGraphCanvas } from '@/lib/litegraph/src/litegraph' @@ -8,10 +7,6 @@ import { visibleCanvasViewport } from './visibleCanvasViewport' vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - describe('visibleCanvasViewport', () => { beforeEach(() => { localStorage.clear() diff --git a/src/platform/cloud/onboarding/CloudSignupView.test.ts b/src/platform/cloud/onboarding/CloudSignupView.test.ts index 4c0a87eb148..76133ffbf20 100644 --- a/src/platform/cloud/onboarding/CloudSignupView.test.ts +++ b/src/platform/cloud/onboarding/CloudSignupView.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { render, screen, waitFor } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' @@ -26,10 +25,6 @@ vi.mock(import('@comfyorg/account/webviewDetection'), () => ({ })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - const inChina = vi.hoisted(() => ({ value: false, pending: null as Promise | null, diff --git a/src/platform/settings/composables/useSettingsDialog.test.ts b/src/platform/settings/composables/useSettingsDialog.test.ts index 93ecf2ab963..8448a1464b0 100644 --- a/src/platform/settings/composables/useSettingsDialog.test.ts +++ b/src/platform/settings/composables/useSettingsDialog.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { useDialogStore } from '@/stores/dialogStore' /** * Settings dialog migration regression net: `useSettingsDialog().show()` must @@ -23,10 +22,6 @@ vi.mock(import('@/i18n'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: () => ({ canAccessSubscriptionFeatures: { value: true }, diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts index 839eecdf62f..325b51d6157 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { getActivePinia } from 'pinia' import { render, screen, waitFor } from '@testing-library/vue' @@ -130,10 +129,6 @@ vi.mock(import('@/services/dialogService'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ buildDocsUrl: vi.fn(() => 'https://docs.comfy.org'), diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index d67976ce102..5b9ac064cfe 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -280,7 +280,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { ) ) const phases = ( - useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] ).map(([event]) => event.phase) expect(phases.indexOf('submitted')).toBeLessThan( phases.indexOf('operation_linked') @@ -289,9 +289,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { // One denominator: every phase of a top-up must carry the same journey. const journeyIds = new Set( - (useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? []).map( - ([event]) => event.checkout_journey_id - ) + ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event.checkout_journey_id) ) expect(journeyIds.size).toBe(1) }) @@ -327,7 +327,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await waitFor(() => expect(mockFetchBalance).toHaveBeenCalled()) const phases = ( - useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] ).map(([event]) => event.phase) expect(phases).toContain('submitted') expect(phases).not.toContain('operation_linked') diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 7ec78c42d88..f59e8f067b0 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -1,5 +1,5 @@ import { render } from '@testing-library/vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { computed } from 'vue' import { billingOperation } from './billingOperationTestUtils' import type { BillingOperation } from './billingOperationTestUtils' @@ -536,9 +536,9 @@ describe('useSubscriptionCheckout', () => { describe('checkout journey instrumentation', () => { function journeyPhases() { - return (useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? []).map( - ([event]) => event.phase - ) + return ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event.phase) } it('emits entered, submitted, and operation_linked across a subscribe', async () => { @@ -566,7 +566,7 @@ describe('useSubscriptionCheckout', () => { ) const events = ( - useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] ).map(([event]) => event) const opLinked = events.find( (event) => event.phase === 'operation_linked' @@ -651,7 +651,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleConfirmTransition() const events = ( - useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] ).map(([event]) => event) expect(events.some((event) => event.phase === 'operation_linked')).toBe( false @@ -662,12 +662,12 @@ describe('useSubscriptionCheckout', () => { await submitRejectedPreview('PREVIEW_FAILED') const events = ( - useTelemetry()?.trackCheckoutJourneyEvent.mock.calls ?? [] + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] ).map(([event]) => event) const entered = events.find((event) => event.phase === 'entered') const failed = events.find((event) => event.phase === 'preview_failed') - expect(entered).toBeDefined() - expect(failed).toBeDefined() + assert.exists(entered) + assert.exists(failed) expect(events.some((event) => event.phase === 'operation_linked')).toBe( false ) diff --git a/src/services/dialogService.downgrade.test.ts b/src/services/dialogService.downgrade.test.ts index aff7993550c..512c33fa441 100644 --- a/src/services/dialogService.downgrade.test.ts +++ b/src/services/dialogService.downgrade.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import type { Component } from 'vue' import type DowngradeContent from '@/platform/workspace/components/dialogs/DowngradeRemoveMembersDialogContent.vue' @@ -41,10 +40,6 @@ vi.mock(import('@/i18n'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false })) diff --git a/src/services/dialogService.renderer.test.ts b/src/services/dialogService.renderer.test.ts index bafa31633d9..d0b7d7f9f55 100644 --- a/src/services/dialogService.renderer.test.ts +++ b/src/services/dialogService.renderer.test.ts @@ -1,10 +1,9 @@ -import { useTelemetry } from '@/platform/telemetry' /** * Dialog migration regression net: when callers in `dialogService` open a * Reka-migrated dialog, the dialog stack item must carry `renderer: 'reka'`. * Catches accidental reverts of the Reka renderer flip. */ -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { describe, expect, it, vi } from 'vitest' vi.mock(import('@/i18n'), () => ({ t: (key: string) => key @@ -12,10 +11,6 @@ vi.mock(import('@/i18n'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false })) diff --git a/src/services/dialogService.topUpCredits.test.ts b/src/services/dialogService.topUpCredits.test.ts index c982a1c5acf..b796c09665a 100644 --- a/src/services/dialogService.topUpCredits.test.ts +++ b/src/services/dialogService.topUpCredits.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { useDialogStore } from '@/stores/dialogStore' /** * showTopUpCreditsDialog routes the paired server capabilities to purchase, @@ -20,10 +19,6 @@ vi.mock(import('@/i18n'), () => ({ vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - const mockIsCloud = vi.hoisted(() => ({ value: true })) vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { diff --git a/src/views/GraphView.test.ts b/src/views/GraphView.test.ts index 62c8a2c2bcb..ccfc459c1e5 100644 --- a/src/views/GraphView.test.ts +++ b/src/views/GraphView.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { render, screen } from '@testing-library/vue' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' @@ -117,10 +116,6 @@ vi.mock(import('@/composables/useProgressFavicon'), () => ({ vi.mock(import('@/platform/distribution/types'), () => distribution) vi.mock(import('@/platform/telemetry')) - -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) vi.mock( import('@/platform/updates/common/useFrontendVersionMismatchWarning'), () => ({ diff --git a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts index a2f6d6732f7..05386196729 100644 --- a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts +++ b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import userEvent from '@testing-library/user-event' import { fireEvent, render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -15,10 +14,6 @@ import { useAgentRunModeStore } from '@/workbench/extensions/agent/stores/agent/ import DockedAgentPanel from './DockedAgentPanel.vue' vi.mock(import('@/platform/telemetry')) - -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: vi.fn() })) diff --git a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts index 15f78f629a8..bd0d9485dea 100644 --- a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts +++ b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { render, screen } from '@testing-library/vue' import { createI18n } from 'vue-i18n' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -14,10 +13,6 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ })) vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - // The mocked module factory throws, so the dynamic import itself rejects - // the chunk-load failure path, distinct from a runtime error inside a // resolved panel (covered in DockedAgentPanel.test.ts). diff --git a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts index 89599d7a969..bfd477ac796 100644 --- a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts +++ b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { beforeEach, describe, expect, it, vi } from 'vitest' import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore' @@ -6,10 +5,6 @@ import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/ag import { useAgentDockMount } from './useAgentDockMount' vi.mock(import('@/platform/telemetry')) - -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) const { loadDockedAgentPanel } = vi.hoisted(() => ({ loadDockedAgentPanel: vi.fn(() => ({ name: 'DockedAgentPanel' })) })) diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts index 1fd5ea75b5a..d5470574987 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts @@ -1,4 +1,3 @@ -import { useTelemetry } from '@/platform/telemetry' import { getActivePinia } from 'pinia' import type { Pinia } from 'pinia' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -11,10 +10,6 @@ import { useAgentPanelStore } from './agentPanelStore' vi.mock(import('@/platform/telemetry')) -beforeEach(() => { - vi.mocked(useTelemetry).mockReturnValue(null) -}) - /** * Regression pin for the duplicate Pinia id `agentPanel`. *