Skip to content

Commit a3f4c41

Browse files
UI UTests
1 parent e219dbd commit a3f4c41

File tree

10 files changed

+399
-70
lines changed

10 files changed

+399
-70
lines changed

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

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
3-
import { cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
3+
import { act, cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
44

55
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
6-
import { OAuthSocialAction, OAuthSocialSource } from 'uiSrc/slices/interfaces'
7-
import { CloudAuthSocial, IpcInvokeEvent } from 'uiSrc/electron/constants'
6+
import { OAuthSocialAction, OAuthSocialSource, OAuthStrategy } from 'uiSrc/slices/interfaces'
7+
import { IpcInvokeEvent } from 'uiSrc/electron/constants'
88
import { oauthCloudUserSelector, setOAuthCloudSource, signIn } from 'uiSrc/slices/oauth/cloud'
99
import { loadSubscriptionsRedisCloud, setSSOFlow } from 'uiSrc/slices/instances/cloud'
10-
import { MOCK_OAUTH_USER_PROFILE } from 'uiSrc/mocks/data/oauth'
10+
import { MOCK_OAUTH_SSO_EMAIL, MOCK_OAUTH_USER_PROFILE } from 'uiSrc/mocks/data/oauth'
1111
import OAuthAutodiscovery from './OAuthAutodiscovery'
1212

1313
jest.mock('uiSrc/telemetry', () => ({
@@ -47,18 +47,62 @@ describe('OAuthAutodiscovery', () => {
4747
})
4848

4949
it('should send telemetry after click on github btn', async () => {
50-
const sendEventTelemetryMock = jest.fn();
51-
(sendEventTelemetry as jest.Mock).mockImplementation(() => sendEventTelemetryMock)
52-
5350
render(<OAuthAutodiscovery />)
5451

5552
fireEvent.click(screen.queryByTestId('github-oauth') as HTMLButtonElement)
5653

5754
expect(sendEventTelemetry).toBeCalledWith({
5855
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
5956
eventData: {
60-
accountOption: 'GitHub',
61-
action: 'import',
57+
accountOption: OAuthStrategy.GitHub,
58+
action: OAuthSocialAction.Import,
59+
source: OAuthSocialSource.Autodiscovery
60+
}
61+
})
62+
63+
expect(invokeMock).toBeCalledTimes(1)
64+
expect(invokeMock).toBeCalledWith(
65+
IpcInvokeEvent.cloudOauth,
66+
{
67+
action: OAuthSocialAction.Import,
68+
strategy: OAuthStrategy.GitHub
69+
}
70+
)
71+
invokeMock.mockRestore()
72+
73+
const expectedActions = [
74+
signIn(),
75+
setSSOFlow(OAuthSocialAction.Import),
76+
setOAuthCloudSource(OAuthSocialSource.Autodiscovery)
77+
]
78+
expect(store.getActions()).toEqual(expectedActions)
79+
80+
invokeMock.mockRestore();
81+
(sendEventTelemetry as jest.Mock).mockRestore()
82+
})
83+
84+
it('should send telemetry after click on sso btn', async () => {
85+
render(<OAuthAutodiscovery />)
86+
87+
fireEvent.click(screen.queryByTestId('sso-oauth') as HTMLButtonElement)
88+
89+
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
90+
91+
await act(async () => {
92+
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
93+
})
94+
95+
expect(screen.getByTestId('btn-submit')).not.toBeDisabled()
96+
97+
await act(async () => {
98+
fireEvent.click(screen.getByTestId('btn-submit'))
99+
})
100+
101+
expect(sendEventTelemetry).toBeCalledWith({
102+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
103+
eventData: {
104+
accountOption: OAuthStrategy.SSO,
105+
action: OAuthSocialAction.Import,
62106
source: OAuthSocialSource.Autodiscovery
63107
}
64108
})
@@ -68,7 +112,10 @@ describe('OAuthAutodiscovery', () => {
68112
IpcInvokeEvent.cloudOauth,
69113
{
70114
action: OAuthSocialAction.Import,
71-
strategy: CloudAuthSocial.Github
115+
strategy: OAuthStrategy.SSO,
116+
data: {
117+
email: MOCK_OAUTH_SSO_EMAIL
118+
}
72119
}
73120
)
74121
invokeMock.mockRestore()

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import {
77
addFreeDb,
88
getPlans,
99
oauthCloudUserSelector,
10-
setJob,
1110
setSocialDialogState,
1211
showOAuthProgress,
1312
signIn
1413
} from 'uiSrc/slices/oauth/cloud'
1514
import { setIsRecommendedSettingsSSO, setSSOFlow } from 'uiSrc/slices/instances/cloud'
16-
import { CloudJobName, CloudJobStep } from 'uiSrc/electron/constants'
15+
import { CloudJobStep } from 'uiSrc/electron/constants'
1716
import { addInfiniteNotification } from 'uiSrc/slices/app/notifications'
1817
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
19-
import { OAuthSocialAction } from 'uiSrc/slices/interfaces'
18+
import { OAuthSocialAction, OAuthStrategy } from 'uiSrc/slices/interfaces'
19+
import { MOCK_OAUTH_SSO_EMAIL } from 'uiSrc/mocks/data/oauth'
2020
import OAuthCreateDb from './OAuthCreateDb'
2121

2222
jest.mock('uiSrc/telemetry', () => ({
@@ -65,19 +65,47 @@ describe('OAuthCreateDb', () => {
6565
expect(screen.getByTestId('oauth-recommended-settings-checkbox')).toBeInTheDocument()
6666
})
6767

68-
it('should call proper actions after click on sign button', () => {
69-
const sendEventTelemetryMock = jest.fn();
70-
(sendEventTelemetry as jest.Mock).mockImplementation(() => sendEventTelemetryMock)
68+
it('should call proper actions after click on sso sign button', async () => {
69+
render(<OAuthCreateDb />)
70+
71+
fireEvent.click(screen.getByTestId('sso-oauth'))
72+
73+
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
74+
75+
await act(async () => {
76+
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
77+
})
78+
79+
expect(screen.getByTestId('btn-submit')).not.toBeDisabled()
80+
81+
await act(async () => {
82+
fireEvent.click(screen.getByTestId('btn-submit'))
83+
})
84+
85+
expect(sendEventTelemetry).toBeCalledWith({
86+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
87+
eventData: {
88+
accountOption: OAuthStrategy.SSO,
89+
action: OAuthSocialAction.Create,
90+
cloudRecommendedSettings: 'enabled'
91+
}
92+
})
7193

94+
const expectedActions = [signIn(), setIsRecommendedSettingsSSO(true)]
95+
expect(store.getActions()).toEqual(expectedActions);
96+
(sendEventTelemetry as jest.Mock).mockRestore()
97+
})
98+
99+
it('should call proper actions after click on sign button', () => {
72100
render(<OAuthCreateDb />)
73101

74102
fireEvent.click(screen.getByTestId('google-oauth'))
75103

76104
expect(sendEventTelemetry).toBeCalledWith({
77105
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
78106
eventData: {
79-
accountOption: 'Google',
80-
action: 'create',
107+
accountOption: OAuthStrategy.Google,
108+
action: OAuthSocialAction.Create,
81109
cloudRecommendedSettings: 'enabled'
82110
}
83111
})

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

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
11
import React from 'react'
2-
import { render, screen } from 'uiSrc/utils/test-utils'
32

3+
import { cloneDeep } from 'lodash'
4+
import { act, cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
5+
import { MOCK_OAUTH_SSO_EMAIL } from 'uiSrc/mocks/data/oauth'
6+
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
7+
import { OAuthSocialAction, OAuthStrategy } from 'uiSrc/slices/interfaces'
8+
import { IpcInvokeEvent } from 'uiSrc/electron/constants'
9+
import { signIn } from 'uiSrc/slices/oauth/cloud'
10+
import { setSSOFlow } from 'uiSrc/slices/instances/cloud'
411
import OAuthSignIn from './OAuthSignIn'
512

13+
jest.mock('uiSrc/telemetry', () => ({
14+
...jest.requireActual('uiSrc/telemetry'),
15+
sendEventTelemetry: jest.fn(),
16+
}))
17+
18+
jest.mock('uiSrc/slices/oauth/cloud', () => ({
19+
...jest.requireActual('uiSrc/slices/oauth/cloud'),
20+
oauthCloudPAgreementSelector: jest.fn().mockReturnValue(true),
21+
oauthCloudUserSelector: jest.fn().mockReturnValue({
22+
data: null
23+
}),
24+
}))
25+
26+
const invokeMock = jest.fn()
27+
let store: typeof mockedStore
28+
beforeEach(() => {
29+
cleanup()
30+
store = cloneDeep(mockedStore)
31+
store.clearActions()
32+
window.app = {
33+
ipc: { invoke: invokeMock }
34+
} as any
35+
})
36+
637
describe('OAuthSignIn', () => {
738
it('should render', () => {
839
expect(render(<OAuthSignIn />)).toBeTruthy()
@@ -15,4 +46,52 @@ describe('OAuthSignIn', () => {
1546
expect(screen.getByTestId('oauth-container-social-buttons')).toBeInTheDocument()
1647
expect(screen.getByTestId('oauth-agreement-checkbox')).toBeInTheDocument()
1748
})
49+
50+
it('should send telemetry after click on sso btn', async () => {
51+
render(<OAuthSignIn />)
52+
53+
fireEvent.click(screen.queryByTestId('sso-oauth') as HTMLButtonElement)
54+
55+
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
56+
57+
await act(async () => {
58+
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
59+
})
60+
61+
expect(screen.getByTestId('btn-submit')).not.toBeDisabled()
62+
63+
await act(async () => {
64+
fireEvent.click(screen.getByTestId('btn-submit'))
65+
})
66+
67+
expect(sendEventTelemetry).toBeCalledWith({
68+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
69+
eventData: {
70+
accountOption: OAuthStrategy.SSO,
71+
action: OAuthSocialAction.SignIn,
72+
}
73+
})
74+
75+
expect(invokeMock).toBeCalledTimes(1)
76+
expect(invokeMock).toBeCalledWith(
77+
IpcInvokeEvent.cloudOauth,
78+
{
79+
action: OAuthSocialAction.SignIn,
80+
strategy: OAuthStrategy.SSO,
81+
data: {
82+
email: MOCK_OAUTH_SSO_EMAIL
83+
}
84+
}
85+
)
86+
invokeMock.mockRestore()
87+
88+
const expectedActions = [
89+
signIn(),
90+
setSSOFlow(OAuthSocialAction.SignIn),
91+
]
92+
expect(store.getActions()).toEqual(expectedActions)
93+
94+
invokeMock.mockRestore();
95+
(sendEventTelemetry as jest.Mock).mockRestore()
96+
})
1897
})
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import React from 'react'
2+
import { cloneDeep } from 'lodash'
3+
import { render, cleanup, mockedStore, fireEvent, screen, act, waitFor } from 'uiSrc/utils/test-utils'
4+
import { OAuthStrategy } from 'uiSrc/slices/interfaces'
5+
import { MOCK_OAUTH_SSO_EMAIL } from 'uiSrc/mocks/data/oauth'
6+
import OAuthForm from './OAuthForm'
7+
8+
jest.mock('uiSrc/slices/oauth/cloud', () => ({
9+
...jest.requireActual('uiSrc/slices/oauth/cloud'),
10+
oauthCloudSelector: jest.fn().mockReturnValue({
11+
source: 'source',
12+
}),
13+
oauthCloudPAgreementSelector: jest.fn().mockReturnValue(true),
14+
}))
15+
16+
const onClick = jest.fn()
17+
18+
let store: typeof mockedStore
19+
const invokeMock = jest.fn()
20+
beforeEach(() => {
21+
cleanup()
22+
store = cloneDeep(mockedStore)
23+
store.clearActions()
24+
window.app = {
25+
ipc: { invoke: invokeMock }
26+
} as any
27+
})
28+
29+
describe('OAuthForm', () => {
30+
afterEach(() => {
31+
onClick.mockRestore()
32+
})
33+
34+
it('should render', () => {
35+
expect(render(<OAuthForm>{(children) => (<>{children}</>)}</OAuthForm>)).toBeTruthy()
36+
})
37+
38+
it('should call proper actions after click on google', () => {
39+
render(<OAuthForm onClick={onClick}>{(children) => (<>{children}</>)}</OAuthForm>)
40+
41+
fireEvent.click(screen.getByTestId('google-oauth'))
42+
43+
expect(onClick).toBeCalledWith(OAuthStrategy.Google)
44+
})
45+
46+
it('should call proper actions after click on sso', async () => {
47+
render(<OAuthForm onClick={onClick}>{(children) => (<>{children}</>)}</OAuthForm>)
48+
49+
fireEvent.click(screen.getByTestId('sso-oauth'))
50+
51+
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
52+
53+
await act(async () => {
54+
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } })
55+
})
56+
57+
expect(screen.getByTestId('btn-submit')).not.toBeDisabled()
58+
59+
await act(async () => {
60+
fireEvent.click(screen.getByTestId('btn-submit'))
61+
})
62+
63+
expect(onClick).toBeCalledWith(OAuthStrategy.SSO)
64+
})
65+
66+
it('should go back to main oauth form by clicking to back button', async () => {
67+
render(<OAuthForm onClick={onClick}>{(children) => (<>{children}</>)}</OAuthForm>)
68+
69+
fireEvent.click(screen.getByTestId('sso-oauth'))
70+
71+
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
72+
expect(screen.getByTestId('btn-back')).toBeInTheDocument()
73+
74+
fireEvent.click(screen.getByTestId('btn-back'))
75+
76+
expect(screen.getByTestId('sso-oauth')).toBeInTheDocument()
77+
})
78+
79+
it('should disable submit button id incorrect email provided', async () => {
80+
render(<OAuthForm onClick={onClick}>{(children) => (<>{children}</>)}</OAuthForm>)
81+
82+
fireEvent.click(screen.getByTestId('sso-oauth'))
83+
84+
expect(screen.getByTestId('sso-email')).toBeInTheDocument()
85+
86+
await act(async () => {
87+
fireEvent.change(screen.getByTestId('sso-email'), { target: { value: 'bad-email' } })
88+
})
89+
90+
expect(screen.getByTestId('btn-submit')).toBeDisabled()
91+
92+
await act(async () => {
93+
fireEvent.mouseOver(screen.getByTestId('btn-submit'))
94+
})
95+
96+
await waitFor(() => screen.getByTestId('btn-submit-tooltip'))
97+
98+
expect(screen.getByTestId('btn-submit-tooltip')).toBeInTheDocument()
99+
100+
await act(async () => {
101+
fireEvent.click(screen.getByTestId('btn-submit'))
102+
})
103+
104+
expect(onClick).not.toHaveBeenCalled()
105+
})
106+
})

redisinsight/ui/src/components/oauth/shared/oauth-form/components/oauth-sso-form/OAuthSsoForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ const OAuthSsoForm = ({
5252
const submitIsDisabled = () => !isEmpty(validationErrors)
5353

5454
const SubmitButton = ({
55-
text = '',
55+
text,
5656
disabled,
57-
}: { disabled: boolean, text?: string }) => (
57+
}: { disabled: boolean, text: string }) => (
5858
<EuiToolTip
5959
position="top"
6060
anchorClassName="euiToolTip__btn-disabled"
61+
data-testid="btn-submit-tooltip"
6162
content={disabled ? (
6263
<>
6364
<p>Email must be in the format</p>

0 commit comments

Comments
 (0)