88 fireEvent ,
99 screen ,
1010} from '@src/testUtils' ;
11+ import userEvent from '@testing-library/user-event' ;
1112
1213import { useUserPermissions } from '@src/authz/data/apiHooks' ;
1314
@@ -42,7 +43,7 @@ jest.mock('@src/authz/data/apiHooks', () => ({
4243
4344jest . mock ( '@src/data/apiHooks' , ( ) => ( {
4445 ...jest . requireActual ( '@src/data/apiHooks' ) ,
45- useWaffleFlags : jest . fn ( ( ) => ( { enableAuthzCourseAuthoring : false } ) ) ,
46+ useWaffleFlags : jest . fn ( ( ) => ( { enableAuthzCourseAuthoring : false , isLoading : false } ) ) ,
4647} ) ) ;
4748
4849jest . mock ( 'react-router-dom' , ( ) => ( {
@@ -370,7 +371,7 @@ describe('<CourseUpdates />', () => {
370371 store = mocks . reduxStore ;
371372 axiosMock = mocks . axiosMock ;
372373
373- ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : true } ) ;
374+ ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : true , isLoading : false } ) ;
374375 ( useUserPermissions as jest . Mock ) . mockReturnValue ( {
375376 isLoading : false ,
376377 data : { canManageCourseUpdates : true , canViewCourseUpdates : true } ,
@@ -403,6 +404,15 @@ describe('<CourseUpdates />', () => {
403404 expect ( await screen . findAllByRole ( 'button' , { name : / e d i t / i } ) ) . toHaveLength ( 4 ) ; // 3 for course updates and 1 for handouts
404405 expect ( await screen . findAllByRole ( 'button' , { name : / d e l e t e / i } ) ) . toHaveLength ( 3 ) ;
405406 } ) ;
407+
408+ it ( 'should open delete modal when clicking delete button on a course update' , async ( ) => {
409+ render ( < RootWrapper /> ) ;
410+
411+ const deleteButtons = await screen . findAllByTestId ( 'course-update-delete-button' ) ;
412+ await userEvent . click ( deleteButtons [ 0 ] ) ;
413+
414+ expect ( screen . getByText ( 'Are you sure you want to delete this update?' ) ) . toBeInTheDocument ( ) ;
415+ } ) ;
406416 } ) ;
407417
408418 describe ( 'when user does NOT have permission to manage course updates and enableAuthzCourseAuthoring is enabled' , ( ) => {
@@ -411,7 +421,7 @@ describe('<CourseUpdates />', () => {
411421 store = mocks . reduxStore ;
412422 axiosMock = mocks . axiosMock ;
413423
414- ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : true } ) ;
424+ ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : true , isLoading : false } ) ;
415425 ( useUserPermissions as jest . Mock ) . mockReturnValue ( {
416426 isLoading : false ,
417427 data : { canManageCourseUpdates : false , canViewCourseUpdates : true } ,
@@ -454,7 +464,7 @@ describe('<CourseUpdates />', () => {
454464 store = mocks . reduxStore ;
455465 axiosMock = mocks . axiosMock ;
456466
457- ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : false } ) ;
467+ ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : false , isLoading : false } ) ;
458468 ( useUserPermissions as jest . Mock ) . mockReturnValue ( {
459469 isLoading : false ,
460470 data : { canManageCourseUpdates : false } ,
@@ -479,13 +489,42 @@ describe('<CourseUpdates />', () => {
479489 } ) ;
480490 } ) ;
481491
492+ describe ( 'when permissions are still loading' , ( ) => {
493+ beforeEach ( ( ) => {
494+ const mocks = initializeMocks ( ) ;
495+ store = mocks . reduxStore ;
496+ axiosMock = mocks . axiosMock ;
497+
498+ ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : true , isLoading : false } ) ;
499+ ( useUserPermissions as jest . Mock ) . mockReturnValue ( {
500+ isLoading : true ,
501+ data : undefined ,
502+ } ) ;
503+
504+ axiosMock
505+ . onGet ( getCourseUpdatesApiUrl ( courseId ) )
506+ . reply ( 200 , courseUpdatesMock ) ;
507+ axiosMock
508+ . onGet ( getCourseHandoutApiUrl ( courseId ) )
509+ . reply ( 200 , courseHandoutsMock ) ;
510+ } ) ;
511+
512+ it ( 'should render loading spinner while permissions are loading' , ( ) => {
513+ render ( < RootWrapper /> ) ;
514+
515+ expect ( screen . getByRole ( 'status' ) ) . toBeInTheDocument ( ) ;
516+ expect ( screen . queryByText ( messages . headingTitle . defaultMessage ) ) . not . toBeInTheDocument ( ) ;
517+ expect ( screen . queryByRole ( 'button' , { name : messages . newUpdateButton . defaultMessage } ) ) . not . toBeInTheDocument ( ) ;
518+ } ) ;
519+ } ) ;
520+
482521 describe ( 'when user does NOT have permission to view course updates' , ( ) => {
483522 beforeEach ( ( ) => {
484523 const mocks = initializeMocks ( ) ;
485524 store = mocks . reduxStore ;
486525 axiosMock = mocks . axiosMock ;
487526
488- ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : true } ) ;
527+ ( apiHooks . useWaffleFlags as jest . Mock ) . mockReturnValue ( { enableAuthzCourseAuthoring : true , isLoading : false } ) ;
489528 ( useUserPermissions as jest . Mock ) . mockReturnValue ( {
490529 isLoading : false ,
491530 data : { canManageCourseUpdates : false , canViewCourseUpdates : false } ,
0 commit comments