Skip to content

Commit 3269de1

Browse files
add telemetry events
1 parent e5cbf19 commit 3269de1

File tree

7 files changed

+91
-27
lines changed

7 files changed

+91
-27
lines changed

redisinsight/ui/src/components/oauth/oauth-sso/oauth-autodiscovery/OAuthAutodiscovery.spec.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ describe('OAuthAutodiscovery', () => {
7171
invokeMock.mockRestore()
7272

7373
const expectedActions = [
74-
signIn(),
7574
setSSOFlow(OAuthSocialAction.Import),
76-
setOAuthCloudSource(OAuthSocialSource.Autodiscovery)
75+
setOAuthCloudSource(OAuthSocialSource.Autodiscovery),
76+
signIn(),
7777
]
7878
expect(store.getActions()).toEqual(expectedActions)
7979

@@ -88,6 +88,15 @@ describe('OAuthAutodiscovery', () => {
8888

8989
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
9090

91+
expect(sendEventTelemetry).toBeCalledWith({
92+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
93+
eventData: {
94+
accountOption: OAuthStrategy.SSO,
95+
action: OAuthSocialAction.Import,
96+
source: OAuthSocialSource.Autodiscovery
97+
}
98+
})
99+
91100
await act(async () => {
92101
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
93102
})
@@ -99,11 +108,9 @@ describe('OAuthAutodiscovery', () => {
99108
})
100109

101110
expect(sendEventTelemetry).toBeCalledWith({
102-
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
111+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
103112
eventData: {
104-
accountOption: OAuthStrategy.SSO,
105113
action: OAuthSocialAction.Import,
106-
source: OAuthSocialSource.Autodiscovery
107114
}
108115
})
109116

@@ -121,9 +128,9 @@ describe('OAuthAutodiscovery', () => {
121128
invokeMock.mockRestore()
122129

123130
const expectedActions = [
124-
signIn(),
125131
setSSOFlow(OAuthSocialAction.Import),
126-
setOAuthCloudSource(OAuthSocialSource.Autodiscovery)
132+
setOAuthCloudSource(OAuthSocialSource.Autodiscovery),
133+
signIn(),
127134
]
128135
expect(store.getActions()).toEqual(expectedActions)
129136

redisinsight/ui/src/components/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.spec.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ describe('OAuthCreateDb', () => {
7272

7373
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
7474

75+
expect(sendEventTelemetry).toBeCalledWith({
76+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
77+
eventData: {
78+
accountOption: OAuthStrategy.SSO,
79+
action: OAuthSocialAction.Create,
80+
cloudRecommendedSettings: 'enabled'
81+
}
82+
})
83+
7584
await act(async () => {
7685
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
7786
})
@@ -83,15 +92,13 @@ describe('OAuthCreateDb', () => {
8392
})
8493

8594
expect(sendEventTelemetry).toBeCalledWith({
86-
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
95+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
8796
eventData: {
88-
accountOption: OAuthStrategy.SSO,
8997
action: OAuthSocialAction.Create,
90-
cloudRecommendedSettings: 'enabled'
9198
}
9299
})
93100

94-
const expectedActions = [signIn(), setIsRecommendedSettingsSSO(true)]
101+
const expectedActions = [setIsRecommendedSettingsSSO(true), signIn()]
95102
expect(store.getActions()).toEqual(expectedActions);
96103
(sendEventTelemetry as jest.Mock).mockRestore()
97104
})
@@ -110,7 +117,7 @@ describe('OAuthCreateDb', () => {
110117
}
111118
})
112119

113-
const expectedActions = [signIn(), setIsRecommendedSettingsSSO(true)]
120+
const expectedActions = [setIsRecommendedSettingsSSO(true), signIn()]
114121
expect(store.getActions()).toEqual(expectedActions);
115122
(sendEventTelemetry as jest.Mock).mockRestore()
116123
})

redisinsight/ui/src/components/oauth/oauth-sso/oauth-sign-in/OAuthSignIn.spec.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ describe('OAuthSignIn', () => {
5353
fireEvent.click(screen.queryByTestId('sso-oauth') as HTMLButtonElement)
5454

5555
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
56+
expect(sendEventTelemetry).toBeCalledWith({
57+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
58+
eventData: {
59+
accountOption: OAuthStrategy.SSO,
60+
action: OAuthSocialAction.SignIn,
61+
}
62+
})
5663

5764
await act(async () => {
5865
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
@@ -65,9 +72,8 @@ describe('OAuthSignIn', () => {
6572
})
6673

6774
expect(sendEventTelemetry).toBeCalledWith({
68-
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
75+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
6976
eventData: {
70-
accountOption: OAuthStrategy.SSO,
7177
action: OAuthSocialAction.SignIn,
7278
}
7379
})
@@ -86,8 +92,8 @@ describe('OAuthSignIn', () => {
8692
invokeMock.mockRestore()
8793

8894
const expectedActions = [
89-
signIn(),
9095
setSSOFlow(OAuthSocialAction.SignIn),
96+
signIn(),
9197
]
9298
expect(store.getActions()).toEqual(expectedActions)
9399

redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.spec.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
3+
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
34
import { render, cleanup, mockedStore, fireEvent, screen, act, waitFor } from 'uiSrc/utils/test-utils'
45
import { OAuthStrategy } from 'uiSrc/slices/interfaces'
56
import { MOCK_OAUTH_SSO_EMAIL } from 'uiSrc/mocks/data/oauth'
67
import OAuthForm from './OAuthForm'
78

9+
jest.mock('uiSrc/telemetry', () => ({
10+
...jest.requireActual('uiSrc/telemetry'),
11+
sendEventTelemetry: jest.fn(),
12+
}))
13+
814
jest.mock('uiSrc/slices/oauth/cloud', () => ({
915
...jest.requireActual('uiSrc/slices/oauth/cloud'),
1016
oauthCloudSelector: jest.fn().mockReturnValue({
@@ -60,6 +66,11 @@ describe('OAuthForm', () => {
6066
fireEvent.click(screen.getByTestId('btn-submit'))
6167
})
6268

69+
expect(sendEventTelemetry).toBeCalledWith({
70+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
71+
eventData: {}
72+
})
73+
6374
expect(onClick).toBeCalledWith(OAuthStrategy.SSO)
6475
})
6576

@@ -73,6 +84,11 @@ describe('OAuthForm', () => {
7384

7485
fireEvent.click(screen.getByTestId('btn-back'))
7586

87+
expect(sendEventTelemetry).toBeCalledWith({
88+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_CANCELED,
89+
eventData: {}
90+
})
91+
7692
expect(screen.getByTestId('sso-oauth')).toBeInTheDocument()
7793
})
7894

@@ -100,7 +116,5 @@ describe('OAuthForm', () => {
100116
await act(async () => {
101117
fireEvent.click(screen.getByTestId('btn-submit'))
102118
})
103-
104-
expect(onClick).not.toHaveBeenCalled()
105119
})
106120
})

redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useDispatch } from 'react-redux'
33
import { signIn } from 'uiSrc/slices/oauth/cloud'
44
import { OAuthSocialAction, OAuthStrategy } from 'uiSrc/slices/interfaces'
55
import { ipcAuth } from 'uiSrc/electron/utils'
6+
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
67
import OAuthSsoForm from './components/oauth-sso-form'
78
import OAuthSocialButtons from '../oauth-social-buttons'
89
import { Props as OAuthSocialButtonsProps } from '../oauth-social-buttons/OAuthSocialButtons'
@@ -30,12 +31,12 @@ const OAuthForm = ({
3031

3132
const initOAuthProcess = (strategy: OAuthStrategy, action: string, data?: {}) => {
3233
dispatch(signIn())
33-
onClick?.(strategy)
3434
ipcAuth(strategy, action, data)
3535
}
3636

3737
const onSocialButtonClick = (authStrategy: OAuthStrategy) => {
3838
setAuthStrategy(authStrategy)
39+
onClick?.(authStrategy)
3940

4041
switch (authStrategy) {
4142
case OAuthStrategy.Google:
@@ -50,11 +51,31 @@ const OAuthForm = ({
5051
}
5152
}
5253

54+
const onSsoBackButtonClick = () => {
55+
setAuthStrategy('')
56+
sendEventTelemetry({
57+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_CANCELED,
58+
eventData: {
59+
action,
60+
}
61+
})
62+
}
63+
64+
const onSsoLoginButtonClick = (data: {}) => {
65+
sendEventTelemetry({
66+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
67+
eventData: {
68+
action,
69+
}
70+
})
71+
initOAuthProcess(OAuthStrategy.SSO, action, data)
72+
}
73+
5374
if (authStrategy === OAuthStrategy.SSO) {
5475
return (
5576
<OAuthSsoForm
56-
onBack={() => setAuthStrategy('')}
57-
onSubmit={(data: {}) => initOAuthProcess(OAuthStrategy.SSO, action, data)}
77+
onBack={onSsoBackButtonClick}
78+
onSubmit={onSsoLoginButtonClick}
5879
/>
5980
)
6081
}

redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/welcome-ai-assistant/WelcomeAiAssistant.spec.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ describe('WelcomeAiAssistant', () => {
4646
fireEvent.click(screen.getByTestId('google-oauth'))
4747

4848
expect(store.getActions()).toEqual([
49-
signIn(),
5049
setSSOFlow(OAuthSocialAction.SignIn),
51-
setOAuthCloudSource(OAuthSocialSource.AiChat)
50+
setOAuthCloudSource(OAuthSocialSource.AiChat),
51+
signIn(),
5252
])
5353

5454
expect(sendEventTelemetry).toBeCalledWith({
@@ -69,6 +69,15 @@ describe('WelcomeAiAssistant', () => {
6969

7070
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
7171

72+
expect(sendEventTelemetry).toBeCalledWith({
73+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
74+
eventData: {
75+
accountOption: OAuthStrategy.SSO,
76+
action: OAuthSocialAction.SignIn,
77+
source: OAuthSocialSource.AiChat
78+
}
79+
})
80+
7281
await act(async () => {
7382
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
7483
})
@@ -80,17 +89,15 @@ describe('WelcomeAiAssistant', () => {
8089
})
8190

8291
expect(store.getActions()).toEqual([
83-
signIn(),
8492
setSSOFlow(OAuthSocialAction.SignIn),
85-
setOAuthCloudSource(OAuthSocialSource.AiChat)
93+
setOAuthCloudSource(OAuthSocialSource.AiChat),
94+
signIn(),
8695
])
8796

8897
expect(sendEventTelemetry).toBeCalledWith({
89-
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
98+
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
9099
eventData: {
91-
accountOption: OAuthStrategy.SSO,
92100
action: OAuthSocialAction.SignIn,
93-
source: OAuthSocialSource.AiChat
94101
}
95102
});
96103
(sendEventTelemetry as jest.Mock).mockRestore()

redisinsight/ui/src/telemetry/events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ export enum TelemetryEvent {
270270

271271
CLOUD_FREE_DATABASE_CLICKED = 'CLOUD_FREE_DATABASE_CLICKED',
272272
CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED = 'CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED',
273+
CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED = 'CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED',
274+
CLOUD_SIGN_IN_SSO_OPTION_CANCELED = 'CLOUD_SIGN_IN_SSO_OPTION_CANCELED',
273275
CLOUD_SIGN_IN_FORM_CLOSED = 'CLOUD_SIGN_IN_FORM_CLOSED',
274276
CLOUD_SIGN_IN_CLICKED = 'CLOUD_SIGN_IN_CLICKED',
275277
CLOUD_SIGN_IN_SUCCEEDED = 'CLOUD_SIGN_IN_SUCCEEDED',

0 commit comments

Comments
 (0)