Skip to content

Commit 6acefbf

Browse files
committed
when compressed button - add check for the data in the vscodeApi action; for the normal button - check the dialog content inside the document when clicked
1 parent 1ec013f commit 6acefbf

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/webviews/src/modules/oauth/oauth-create-free-db/OAuthCreateFreeDb.spec.tsx

+27-16
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import * as utils from 'uiSrc/utils'
44
import { OAuthSocialAction, OAuthSocialSource, VscodeMessageAction } from 'uiSrc/constants'
55
import { initialOAuthState, useOAuthStore } from 'uiSrc/store'
66
import { vscodeApi } from 'uiSrc/services'
7-
import { cleanup, fireEvent, render, waitFor } from 'testSrc/helpers'
7+
import { cleanup, fireEvent, render, screen } from 'testSrc/helpers'
88
import OAuthCreateFreeDb from './OAuthCreateFreeDb'
9+
import OAuthSsoDialog from '../oauth-sso-dialog'
910

1011
vi.spyOn(utils, 'sendEventTelemetry')
1112
vi.spyOn(vscodeApi, 'postMessage')
@@ -20,7 +21,7 @@ beforeEach(() => {
2021
vi.resetAllMocks()
2122
})
2223

23-
describe('OAuthConnectFreeDb', () => {
24+
describe('OAuthCreateFreeDb', () => {
2425
it('should render if there is a free cloud db', () => {
2526
const { queryByTestId } = render(<OAuthCreateFreeDb source={OAuthSocialSource.AddDbForm}/>)
2627
expect(queryByTestId('create-free-db-btn')).toBeInTheDocument()
@@ -39,8 +40,9 @@ describe('OAuthConnectFreeDb', () => {
3940
})
4041
})
4142

42-
it('should open add database page and oauth sso modal when compressed button is clicked', () => {
43+
it('should set the propper state variables when action is triggered with with valid ssoFlow and source', () => {
4344
const { queryByTestId } = render(<OAuthCreateFreeDb source={OAuthSocialSource.DatabasesList} compressed={true}/>)
45+
render(<OAuthSsoDialog />)
4446

4547
const compressedCreateBtn = queryByTestId('create-free-db-btn')
4648
expect(compressedCreateBtn).toBeInTheDocument()
@@ -54,29 +56,38 @@ describe('OAuthConnectFreeDb', () => {
5456
source: OAuthSocialSource.DatabasesList,
5557
},
5658
})
59+
})
60+
61+
it('should set the propper state variables when action is triggered with source null', () => {
62+
const { queryByTestId } = render(<OAuthCreateFreeDb source={null} compressed={true}/>)
63+
render(<OAuthSsoDialog />)
64+
65+
const compressedCreateBtn = queryByTestId('create-free-db-btn')
66+
expect(compressedCreateBtn).toBeInTheDocument()
67+
68+
fireEvent.click(compressedCreateBtn as HTMLButtonElement)
5769

58-
const state = useOAuthStore.getState()
59-
const socialDialog = queryByTestId('social-oauth-dialog')
60-
waitFor(() => {
61-
expect(state.ssoFlow).toEqual(OAuthSocialAction.Create)
62-
expect(state.isOpenSocialDialog).toEqual(true)
63-
expect(socialDialog).toBeInTheDocument()
70+
expect(vscodeApi.postMessage).toBeCalledWith({
71+
action: VscodeMessageAction.OpenAddDatabase,
72+
data: {
73+
ssoFlow: OAuthSocialAction.Create,
74+
source: null,
75+
},
6476
})
6577
})
6678

67-
it('should open auth sso modal when non compressed button is clicked', () => {
79+
it('should open auth sso dialog when non compressed button is clicked', () => {
6880
const { queryByTestId } = render(<OAuthCreateFreeDb source={OAuthSocialSource.DatabasesList} compressed={false}/>)
6981

82+
// component is initialized in the document, but the state is not updated yet to show the dialog
83+
render(<OAuthSsoDialog />)
84+
expect(screen.queryByTestId('social-oauth-dialog')).not.toBeInTheDocument()
85+
7086
const regularCreateBtn = queryByTestId('create-free-db-btn')
7187
expect(regularCreateBtn).toBeInTheDocument()
7288

7389
fireEvent.click(regularCreateBtn as HTMLButtonElement)
7490

75-
const state = useOAuthStore.getState()
76-
expect(state.ssoFlow).toEqual(OAuthSocialAction.Create)
77-
expect(state.isOpenSocialDialog).toEqual(true)
78-
79-
const socialDialog = queryByTestId('social-oauth-dialog')
80-
waitFor(() => expect(socialDialog).toBeInTheDocument())
91+
expect(screen.queryByTestId('social-oauth-dialog')).toBeInTheDocument()
8192
})
8293
})

0 commit comments

Comments
 (0)