@@ -4,8 +4,9 @@ import * as utils from 'uiSrc/utils'
4
4
import { OAuthSocialAction , OAuthSocialSource , VscodeMessageAction } from 'uiSrc/constants'
5
5
import { initialOAuthState , useOAuthStore } from 'uiSrc/store'
6
6
import { vscodeApi } from 'uiSrc/services'
7
- import { cleanup , fireEvent , render , waitFor } from 'testSrc/helpers'
7
+ import { cleanup , fireEvent , render , screen } from 'testSrc/helpers'
8
8
import OAuthCreateFreeDb from './OAuthCreateFreeDb'
9
+ import OAuthSsoDialog from '../oauth-sso-dialog'
9
10
10
11
vi . spyOn ( utils , 'sendEventTelemetry' )
11
12
vi . spyOn ( vscodeApi , 'postMessage' )
@@ -20,7 +21,7 @@ beforeEach(() => {
20
21
vi . resetAllMocks ( )
21
22
} )
22
23
23
- describe ( 'OAuthConnectFreeDb ' , ( ) => {
24
+ describe ( 'OAuthCreateFreeDb ' , ( ) => {
24
25
it ( 'should render if there is a free cloud db' , ( ) => {
25
26
const { queryByTestId } = render ( < OAuthCreateFreeDb source = { OAuthSocialSource . AddDbForm } /> )
26
27
expect ( queryByTestId ( 'create-free-db-btn' ) ) . toBeInTheDocument ( )
@@ -39,8 +40,9 @@ describe('OAuthConnectFreeDb', () => {
39
40
} )
40
41
} )
41
42
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 ' , ( ) => {
43
44
const { queryByTestId } = render ( < OAuthCreateFreeDb source = { OAuthSocialSource . DatabasesList } compressed = { true } /> )
45
+ render ( < OAuthSsoDialog /> )
44
46
45
47
const compressedCreateBtn = queryByTestId ( 'create-free-db-btn' )
46
48
expect ( compressedCreateBtn ) . toBeInTheDocument ( )
@@ -54,29 +56,38 @@ describe('OAuthConnectFreeDb', () => {
54
56
source : OAuthSocialSource . DatabasesList ,
55
57
} ,
56
58
} )
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 )
57
69
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
+ } ,
64
76
} )
65
77
} )
66
78
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' , ( ) => {
68
80
const { queryByTestId } = render ( < OAuthCreateFreeDb source = { OAuthSocialSource . DatabasesList } compressed = { false } /> )
69
81
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
+
70
86
const regularCreateBtn = queryByTestId ( 'create-free-db-btn' )
71
87
expect ( regularCreateBtn ) . toBeInTheDocument ( )
72
88
73
89
fireEvent . click ( regularCreateBtn as HTMLButtonElement )
74
90
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 ( )
81
92
} )
82
93
} )
0 commit comments