@@ -190,6 +190,83 @@ describe('EmailSection', () => {
190190 } ) ;
191191 } ) ;
192192
193+ describe ( 'Immutable email addresses' , ( ) => {
194+ const withImmutableEmails = createFixtures . config ( f => {
195+ f . withEmailAddress ( { immutable : true } ) ;
196+ f . withUser ( {
197+ email_addresses : [ 'test@clerk.com' , 'test2@clerk.com' ] ,
198+ } ) ;
199+ } ) ;
200+
201+ it ( 'hides the "Add email address" button when email is immutable' , async ( ) => {
202+ const { wrapper } = await createFixtures ( withImmutableEmails ) ;
203+
204+ const { queryByRole } = render (
205+ < CardStateProvider >
206+ < EmailsSection shouldAllowCreation = { false } />
207+ </ CardStateProvider > ,
208+ { wrapper } ,
209+ ) ;
210+
211+ expect ( queryByRole ( 'button' , { name : / a d d e m a i l a d d r e s s / i } ) ) . not . toBeInTheDocument ( ) ;
212+ } ) ;
213+
214+ it ( 'hides the "Remove" menu action when email is immutable' , async ( ) => {
215+ const { wrapper } = await createFixtures ( withImmutableEmails ) ;
216+
217+ const { getByText, userEvent, queryByRole } = render (
218+ < CardStateProvider >
219+ < EmailsSection
220+ shouldAllowCreation = { false }
221+ shouldAllowDeletion = { false }
222+ />
223+ </ CardStateProvider > ,
224+ { wrapper } ,
225+ ) ;
226+
227+ const item = getByText ( 'test@clerk.com' ) ;
228+ const menuButton = getMenuItemFromText ( item ) ;
229+ await act ( async ( ) => {
230+ await userEvent . click ( menuButton ! ) ;
231+ } ) ;
232+
233+ expect ( queryByRole ( 'menuitem' , { name : / r e m o v e e m a i l / i } ) ) . not . toBeInTheDocument ( ) ;
234+ } ) ;
235+
236+ it ( 'still shows verify and set-as-primary actions when email is immutable' , async ( ) => {
237+ const { wrapper } = await createFixtures (
238+ createFixtures . config ( f => {
239+ f . withEmailAddress ( { immutable : true } ) ;
240+ f . withUser ( {
241+ email_addresses : [
242+ { email_address : 'primary@clerk.com' , id : 'email_primary' , verification : { status : 'verified' } } ,
243+ { email_address : 'secondary@clerk.com' , id : 'email_secondary' , verification : { status : 'verified' } } ,
244+ ] ,
245+ primary_email_address_id : 'email_primary' ,
246+ } ) ;
247+ } ) ,
248+ ) ;
249+
250+ const { getByText, userEvent, getByRole } = render (
251+ < CardStateProvider >
252+ < EmailsSection
253+ shouldAllowCreation = { false }
254+ shouldAllowDeletion = { false }
255+ />
256+ </ CardStateProvider > ,
257+ { wrapper } ,
258+ ) ;
259+
260+ const item = getByText ( 'secondary@clerk.com' ) ;
261+ const menuButton = getMenuItemFromText ( item ) ;
262+ await act ( async ( ) => {
263+ await userEvent . click ( menuButton ! ) ;
264+ } ) ;
265+
266+ getByRole ( 'menuitem' , { name : / s e t a s p r i m a r y / i } ) ;
267+ } ) ;
268+ } ) ;
269+
193270 describe ( 'Handles opening/closing actions' , ( ) => {
194271 it ( 'closes add email form when remove an email address action is clicked' , async ( ) => {
195272 const { wrapper, fixtures } = await createFixtures ( withEmails ) ;
0 commit comments