6
6
waitFor ,
7
7
} from '@clerk/shared/testUtils' ;
8
8
import { titleize } from '@clerk/shared/utils/string' ;
9
- import { Session } from 'core/resources ' ;
10
- import { AuthConfig } from 'core/resources/AuthConfig ' ;
9
+ import { UserSettingsJSON } from '@clerk/types ' ;
10
+ import { Session , UserSettings } from 'core/resources/internal ' ;
11
11
import React from 'react' ;
12
12
import { useCore# } from 'ui/contexts' ;
13
13
@@ -17,8 +17,7 @@ const navigateMock = jest.fn();
17
17
const mockCreateRequest = jest . fn ( ) ;
18
18
const mockSetSession = jest . fn ( ) ;
19
19
const mockAuthenticateWithRedirect = jest . fn ( ) ;
20
- const mockIdentificationRequirements = jest . fn ( ) ;
21
- let mockAuthConfig : Partial < AuthConfig > ;
20
+ let mockUserSettings : UserSettings ;
22
21
23
22
const oldWindowLocation = window . location ;
24
23
const setWindowQueryParams = ( params : Array < [ string , string ] > ) => {
@@ -62,7 +61,8 @@ jest.mock('ui/contexts', () => {
62
61
applicationName : 'My test app' ,
63
62
after#Url : 'http://test.host' ,
64
63
} ,
65
- authConfig : mockAuthConfig ,
64
+ userSettings : mockUserSettings ,
65
+ authConfig : { singleSessionMode : false } ,
66
66
} ) ) ,
67
67
} ;
68
68
} ) ;
@@ -79,9 +79,9 @@ describe('<#Start/>', () => {
79
79
const { location } = window ;
80
80
81
81
beforeEach ( ( ) => {
82
- mockIdentificationRequirements . mockImplementation ( ( ) => [
83
- [ 'email_address' , 'oauth_google' , 'oauth_facebook' ] ,
84
- ] ) ;
82
+ // mockIdentificationRequirements.mockImplementation(() => [
83
+ // ['email_address', 'oauth_google', 'oauth_facebook'],
84
+ // ]);
85
85
86
86
mockCreateRequest . mockImplementation ( ( ) =>
87
87
Promise . resolve ( {
@@ -94,13 +94,38 @@ describe('<#Start/>', () => {
94
94
} ) ,
95
95
) ;
96
96
97
- mockAuthConfig = {
98
- username : 'on' ,
99
- firstName : 'required' ,
100
- lastName : 'required' ,
101
- password : 'required' ,
102
- identificationRequirements : mockIdentificationRequirements ( ) ,
103
- } ;
97
+ mockUserSettings = new UserSettings ( {
98
+ attributes : {
99
+ username : {
100
+ enabled : true ,
101
+ } ,
102
+ first_name : {
103
+ enabled : true ,
104
+ required : true ,
105
+ } ,
106
+ last_name : {
107
+ enabled : true ,
108
+ required : true ,
109
+ } ,
110
+ password : {
111
+ enabled : true ,
112
+ required : true ,
113
+ } ,
114
+ email_address : {
115
+ enabled : true ,
116
+ } ,
117
+ } ,
118
+ social : {
119
+ oauth_google : {
120
+ enabled : true ,
121
+ strategy : 'oauth_google' ,
122
+ } ,
123
+ oauth_facebook : {
124
+ enabled : true ,
125
+ strategy : 'oauth_facebook' ,
126
+ } ,
127
+ } ,
128
+ } as UserSettingsJSON ) ;
104
129
} ) ;
105
130
106
131
afterEach ( ( ) => {
@@ -111,22 +136,19 @@ describe('<#Start/>', () => {
111
136
global . window . location = location ;
112
137
} ) ;
113
138
114
- it ( 'renders the # start screen' , async ( ) => {
139
+ it ( 'renders the # start screen' , ( ) => {
115
140
const tree = renderJSON ( < #Start /> ) ;
116
141
expect ( tree ) . toMatchSnapshot ( ) ;
117
142
} ) ;
118
143
119
144
it ( 'renders the start screen, types the name, email, and password and creates a # attempt' , async ( ) => {
120
145
render ( < #Start /> ) ;
121
146
122
- await userEvent . type ( screen . getByLabelText ( 'First name' ) , 'John' ) ;
123
- await userEvent . type ( screen . getByLabelText ( 'Last name' ) , 'Doe' ) ;
124
- await userEvent . type ( screen . getByLabelText ( 'Username' ) , 'jdoe' ) ;
125
- await userEvent . type (
126
- screen . getByLabelText ( 'Email address' ) ,
127
- 'jdoe@example.com' ,
128
- ) ;
129
- await userEvent . type ( screen . getByLabelText ( 'Password' ) , 'p@ssW0rd' ) ;
147
+ userEvent . type ( screen . getByLabelText ( 'First name' ) , 'John' ) ;
148
+ userEvent . type ( screen . getByLabelText ( 'Last name' ) , 'Doe' ) ;
149
+ userEvent . type ( screen . getByLabelText ( 'Username' ) , 'jdoe' ) ;
150
+ userEvent . type ( screen . getByLabelText ( 'Email address' ) , 'jdoe@example.com' ) ;
151
+ userEvent . type ( screen . getByLabelText ( 'Password' ) , 'p@ssW0rd' ) ;
130
152
131
153
userEvent . click ( screen . getByRole ( 'button' , { name : '#' } ) ) ;
132
154
@@ -170,7 +192,7 @@ describe('<#Start/>', () => {
170
192
} ,
171
193
) ;
172
194
173
- it ( 'renders the external account verification error if available' , async ( ) => {
195
+ it ( 'renders the external account verification error if available' , ( ) => {
174
196
const errorMsg =
175
197
'You cannot # with sokratis.vidros@gmail.com since this is an invitation-only application' ;
176
198
@@ -194,14 +216,24 @@ describe('<#Start/>', () => {
194
216
expect ( mockCreateRequest ) . toHaveBeenNthCalledWith ( 1 , { } ) ;
195
217
} ) ;
196
218
197
- it ( 'only renders the SSO buttons if no other method is supported' , async ( ) => {
198
- mockIdentificationRequirements . mockImplementation ( ( ) => [
199
- [ 'oauth_google' , 'oauth_facebook' ] ,
200
- ] ) ;
201
- mockAuthConfig = {
202
- username : 'off' ,
203
- identificationRequirements : mockIdentificationRequirements ( ) ,
204
- } ;
219
+ it ( 'only renders the SSO buttons if no other method is supported' , ( ) => {
220
+ mockUserSettings = new UserSettings ( {
221
+ attributes : {
222
+ username : {
223
+ enabled : false ,
224
+ } ,
225
+ } ,
226
+ social : {
227
+ oauth_google : {
228
+ enabled : true ,
229
+ strategy : 'oauth_google' ,
230
+ } ,
231
+ oauth_facebook : {
232
+ enabled : true ,
233
+ strategy : 'oauth_facebook' ,
234
+ } ,
235
+ } ,
236
+ } as UserSettingsJSON ) ;
205
237
206
238
render ( < #Start /> ) ;
207
239
screen . getByRole ( 'button' , { name : / G o o g l e / } ) ;
@@ -212,7 +244,7 @@ describe('<#Start/>', () => {
212
244
} ) ;
213
245
214
246
describe ( 'when the user does not grant access to their Facebook account' , ( ) => {
215
- it ( 'renders the external account verification error if available' , async ( ) => {
247
+ it ( 'renders the external account verification error if available' , ( ) => {
216
248
const errorMsg = 'You did not grant access to your Facebook account' ;
217
249
218
250
( useCore# as jest . Mock ) . mockImplementation ( ( ) => {
@@ -296,9 +328,14 @@ describe('<#Start/>', () => {
296
328
} ) ;
297
329
298
330
it ( 'does not render the phone number field' , async ( ) => {
299
- mockIdentificationRequirements . mockImplementation ( ( ) => [
300
- [ 'phone_number' ] ,
301
- ] ) ;
331
+ mockUserSettings = new UserSettings ( {
332
+ attributes : {
333
+ phone_number : {
334
+ enabled : true ,
335
+ required : true ,
336
+ } ,
337
+ } ,
338
+ } as UserSettingsJSON ) ;
302
339
303
340
const { container } = render ( < #Start /> ) ;
304
341
const labels = container . querySelectorAll ( 'label' ) ;
0 commit comments