@@ -280,6 +280,19 @@ describe('default layout', () => {
280280 } ) ;
281281 }
282282
283+ const myOpenStaxUser = {
284+ contact : {
285+ firstName : 'Roy' ,
286+ lastName : 'Johnson'
287+ }
288+ } ;
289+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
290+ const loggedInUser = { userModel : { id : 16249 } , myOpenStaxUser} as any ;
291+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
292+ const loggedOutUser = { } as any ;
293+
294+ const spyUseUserContext = jest . spyOn ( UUC , 'default' ) . mockReturnValue ( loggedOutUser ) ;
295+
283296 beforeAll ( ( ) => {
284297 global . fetch = jest
285298 . fn ( )
@@ -328,6 +341,8 @@ describe('default layout', () => {
328341 await user . click ( overlay as Element ) ;
329342 expect ( toggle . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
330343
344+ spyUseUserContext . mockReturnValue ( loggedInUser ) ;
345+
331346 // close on Escape (but not on other keypress)
332347 await user . click ( toggle ) ;
333348 expect ( toggle . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
@@ -349,21 +364,16 @@ describe('default layout', () => {
349364
350365 fireEvent . focus ( techMenu ) ;
351366 fireEvent . keyDown ( techMenu , { key : 'ArrowDown' } ) ;
367+ expect ( document . activeElement ?. textContent ) . toBe ( 'OpenStax Assignable' ) ;
352368 fireEvent . keyDown ( techMenu , { key : 'ArrowUp' } ) ;
369+ expect ( document . activeElement ?. textContent ) . toBe ( 'Technology arrow' ) ;
353370 fireEvent . keyDown ( techMenu , { key : 'ArrowRight' } ) ;
371+ expect ( document . activeElement ?. textContent ) . toBe ( 'What we do arrow' ) ;
372+ fireEvent . keyDown ( techMenu , { key : 'ArrowLeft' } ) ;
373+ expect ( document . activeElement ?. textContent ) . toBe ( 'What we do arrow' ) ;
354374 expect ( techMenu . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
355375 } ) ;
356376 it ( 'renders login menu' , async ( ) => {
357- // Normally dynamically loaded, so needs its own test
358- const myOpenStaxUser = {
359- contact : {
360- firstName : 'Roy' ,
361- lastName : 'Johnson'
362- }
363- } ;
364-
365- // eslint-disable-next-line @typescript-eslint/no-explicit-any
366- jest . spyOn ( UUC , 'default' ) . mockReturnValue ( { userModel : { id : 16249 } , myOpenStaxUser} as any ) ;
367377 render ( < MemoryRouter initialEntries = { [ '/webinars' ] } >
368378 < LoginMenu />
369379 </ MemoryRouter > ) ;
@@ -381,4 +391,26 @@ describe('default layout', () => {
381391 fireEvent . click ( screen . getByText ( 'Change route' ) ) ;
382392 expect ( toggleActive ) . toHaveBeenCalledWith ( false ) ;
383393 } ) ;
394+ it ( 'renders login-menu options based on userModel' , async ( ) => {
395+ spyUseUserContext . mockReturnValue ( {
396+ myOpenStaxUser : {
397+ error : 'true'
398+ } ,
399+ // @ts -expect-error userModel missssing properties
400+ userModel : {
401+ instructorEligible : true ,
402+ incompleteSignup : true ,
403+ pendingInstructorAccess : true ,
404+ emailUnverified : true
405+ }
406+ } ) ;
407+ render ( < MemoryRouter initialEntries = { [ '/webinars' ] } >
408+ < LoginMenu />
409+ </ MemoryRouter > ) ;
410+ screen . getByRole ( 'link' , { name : 'Account Profile' } ) ;
411+ screen . getByRole ( 'link' , { name : 'Request instructor access' } ) ;
412+ screen . getByRole ( 'link' , { name : 'Complete your profile' } ) ;
413+ screen . getByRole ( 'link' , { name : 'Pending instructor access' } ) ;
414+ screen . getByRole ( 'link' , { name : 'Verify your email address' } ) ;
415+ } ) ;
384416} ) ;
0 commit comments