Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe('OAuthAutodiscovery', () => {
invokeMock.mockRestore()

const expectedActions = [
signIn(),
setSSOFlow(OAuthSocialAction.Import),
setOAuthCloudSource(OAuthSocialSource.Autodiscovery)
setOAuthCloudSource(OAuthSocialSource.Autodiscovery),
signIn(),
]
expect(store.getActions()).toEqual(expectedActions)

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

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

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.Import,
source: OAuthSocialSource.Autodiscovery
}
})

await act(async () => {
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
})
Expand All @@ -99,11 +108,9 @@ describe('OAuthAutodiscovery', () => {
})

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.Import,
source: OAuthSocialSource.Autodiscovery
}
})

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

const expectedActions = [
signIn(),
setSSOFlow(OAuthSocialAction.Import),
setOAuthCloudSource(OAuthSocialSource.Autodiscovery)
setOAuthCloudSource(OAuthSocialSource.Autodiscovery),
signIn(),
]
expect(store.getActions()).toEqual(expectedActions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ describe('OAuthCreateDb', () => {

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

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.Create,
cloudRecommendedSettings: 'enabled'
}
})

await act(async () => {
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
})
Expand All @@ -83,15 +92,13 @@ describe('OAuthCreateDb', () => {
})

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.Create,
cloudRecommendedSettings: 'enabled'
}
})

const expectedActions = [signIn(), setIsRecommendedSettingsSSO(true)]
const expectedActions = [setIsRecommendedSettingsSSO(true), signIn()]
expect(store.getActions()).toEqual(expectedActions);
(sendEventTelemetry as jest.Mock).mockRestore()
})
Expand All @@ -110,7 +117,7 @@ describe('OAuthCreateDb', () => {
}
})

const expectedActions = [signIn(), setIsRecommendedSettingsSSO(true)]
const expectedActions = [setIsRecommendedSettingsSSO(true), signIn()]
expect(store.getActions()).toEqual(expectedActions);
(sendEventTelemetry as jest.Mock).mockRestore()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ describe('OAuthSignIn', () => {
fireEvent.click(screen.queryByTestId('sso-oauth') as HTMLButtonElement)

expect(screen.getByTestId('sso-email')).toBeInTheDocument()
expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.SignIn,
}
})

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

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.SignIn,
}
})
Expand All @@ -86,8 +92,8 @@ describe('OAuthSignIn', () => {
invokeMock.mockRestore()

const expectedActions = [
signIn(),
setSSOFlow(OAuthSocialAction.SignIn),
signIn(),
]
expect(store.getActions()).toEqual(expectedActions)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React from 'react'
import { cloneDeep } from 'lodash'
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import { render, cleanup, mockedStore, fireEvent, screen, act, waitFor } from 'uiSrc/utils/test-utils'
import { OAuthStrategy } from 'uiSrc/slices/interfaces'
import { MOCK_OAUTH_SSO_EMAIL } from 'uiSrc/mocks/data/oauth'
import OAuthForm from './OAuthForm'

jest.mock('uiSrc/telemetry', () => ({
...jest.requireActual('uiSrc/telemetry'),
sendEventTelemetry: jest.fn(),
}))

jest.mock('uiSrc/slices/oauth/cloud', () => ({
...jest.requireActual('uiSrc/slices/oauth/cloud'),
oauthCloudSelector: jest.fn().mockReturnValue({
Expand Down Expand Up @@ -60,6 +66,11 @@ describe('OAuthForm', () => {
fireEvent.click(screen.getByTestId('btn-submit'))
})

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
eventData: {}
})

expect(onClick).toBeCalledWith(OAuthStrategy.SSO)
})

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

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

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_CANCELED,
eventData: {}
})

expect(screen.getByTestId('sso-oauth')).toBeInTheDocument()
})

Expand Down Expand Up @@ -100,7 +116,5 @@ describe('OAuthForm', () => {
await act(async () => {
fireEvent.click(screen.getByTestId('btn-submit'))
})

expect(onClick).not.toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useDispatch } from 'react-redux'
import { signIn } from 'uiSrc/slices/oauth/cloud'
import { OAuthSocialAction, OAuthStrategy } from 'uiSrc/slices/interfaces'
import { ipcAuth } from 'uiSrc/electron/utils'
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import OAuthSsoForm from './components/oauth-sso-form'
import OAuthSocialButtons from '../oauth-social-buttons'
import { Props as OAuthSocialButtonsProps } from '../oauth-social-buttons/OAuthSocialButtons'
Expand Down Expand Up @@ -30,12 +31,12 @@ const OAuthForm = ({

const initOAuthProcess = (strategy: OAuthStrategy, action: string, data?: {}) => {
dispatch(signIn())
onClick?.(strategy)
ipcAuth(strategy, action, data)
}

const onSocialButtonClick = (authStrategy: OAuthStrategy) => {
setAuthStrategy(authStrategy)
onClick?.(authStrategy)

switch (authStrategy) {
case OAuthStrategy.Google:
Expand All @@ -50,11 +51,31 @@ const OAuthForm = ({
}
}

const onSsoBackButtonClick = () => {
setAuthStrategy('')
sendEventTelemetry({
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_CANCELED,
eventData: {
action,
}
})
}

const onSsoLoginButtonClick = (data: {}) => {
sendEventTelemetry({
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
eventData: {
action,
}
})
initOAuthProcess(OAuthStrategy.SSO, action, data)
}

if (authStrategy === OAuthStrategy.SSO) {
return (
<OAuthSsoForm
onBack={() => setAuthStrategy('')}
onSubmit={(data: {}) => initOAuthProcess(OAuthStrategy.SSO, action, data)}
onBack={onSsoBackButtonClick}
onSubmit={onSsoLoginButtonClick}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('WelcomeAiAssistant', () => {
fireEvent.click(screen.getByTestId('google-oauth'))

expect(store.getActions()).toEqual([
signIn(),
setSSOFlow(OAuthSocialAction.SignIn),
setOAuthCloudSource(OAuthSocialSource.AiChat)
setOAuthCloudSource(OAuthSocialSource.AiChat),
signIn(),
])

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

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

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.SignIn,
source: OAuthSocialSource.AiChat
}
})

await act(async () => {
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
})
Expand All @@ -80,17 +89,15 @@ describe('WelcomeAiAssistant', () => {
})

expect(store.getActions()).toEqual([
signIn(),
setSSOFlow(OAuthSocialAction.SignIn),
setOAuthCloudSource(OAuthSocialSource.AiChat)
setOAuthCloudSource(OAuthSocialSource.AiChat),
signIn(),
])

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED,
eventData: {
accountOption: OAuthStrategy.SSO,
action: OAuthSocialAction.SignIn,
source: OAuthSocialSource.AiChat
}
});
(sendEventTelemetry as jest.Mock).mockRestore()
Expand Down
2 changes: 2 additions & 0 deletions redisinsight/ui/src/telemetry/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export enum TelemetryEvent {

CLOUD_FREE_DATABASE_CLICKED = 'CLOUD_FREE_DATABASE_CLICKED',
CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED = 'CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED',
CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED = 'CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED',
CLOUD_SIGN_IN_SSO_OPTION_CANCELED = 'CLOUD_SIGN_IN_SSO_OPTION_CANCELED',
CLOUD_SIGN_IN_FORM_CLOSED = 'CLOUD_SIGN_IN_FORM_CLOSED',
CLOUD_SIGN_IN_CLICKED = 'CLOUD_SIGN_IN_CLICKED',
CLOUD_SIGN_IN_SUCCEEDED = 'CLOUD_SIGN_IN_SUCCEEDED',
Expand Down