11import { render , screen } from '@testing-library/react' ;
2+ import userEvent from '@testing-library/user-event' ;
23import { IntlProvider } from '@openedx/frontend-base' ;
34import { MemoryRouter , Route , Routes } from 'react-router-dom' ;
45import DateExtensionsPage from './DateExtensionsPage' ;
5- import { useDateExtensions } from '../data/apiHook' ;
6+ import { useDateExtensions , useResetDateExtensionMutation } from '../data/apiHook' ;
67
78jest . mock ( '../data/apiHook' , ( ) => ( {
89 useDateExtensions : jest . fn ( ) ,
10+ useResetDateExtensionMutation : jest . fn ( ) ,
911} ) ) ;
1012
1113const mockDateExtensions = [
@@ -19,12 +21,17 @@ const mockDateExtensions = [
1921 } ,
2022] ;
2123
24+ const mutateMock = jest . fn ( ) ;
25+
2226describe ( 'DateExtensionsPage' , ( ) => {
2327 beforeEach ( ( ) => {
2428 ( useDateExtensions as jest . Mock ) . mockReturnValue ( {
2529 data : { count : mockDateExtensions . length , results : mockDateExtensions } ,
2630 isLoading : false ,
2731 } ) ;
32+ ( useResetDateExtensionMutation as jest . Mock ) . mockReturnValue ( {
33+ mutate : mutateMock ,
34+ } ) ;
2835 } ) ;
2936
3037 const RenderWithRouter = ( ) => (
@@ -67,4 +74,35 @@ describe('DateExtensionsPage', () => {
6774 const resetLinks = screen . getAllByRole ( 'button' , { name : 'Reset Extensions' } ) ;
6875 expect ( resetLinks ) . toHaveLength ( mockDateExtensions . length ) ;
6976 } ) ;
77+
78+ it ( 'opens reset modal when reset button is clicked' , async ( ) => {
79+ render ( < RenderWithRouter /> ) ;
80+ const user = userEvent . setup ( ) ;
81+ const resetButton = screen . getByRole ( 'button' , { name : 'Reset Extensions' } ) ;
82+ await user . click ( resetButton ) ;
83+ expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
84+ expect ( screen . getByText ( / r e s e t e x t e n s i o n s f o r / i) ) . toBeInTheDocument ( ) ;
85+ const confirmButton = screen . getByRole ( 'button' , { name : / r e s e t d u e d a t e / i } ) ;
86+ expect ( confirmButton ) . toBeInTheDocument ( ) ;
87+ } ) ;
88+
89+ it ( 'calls reset mutation when confirm reset is clicked' , async ( ) => {
90+ render ( < RenderWithRouter /> ) ;
91+ const user = userEvent . setup ( ) ;
92+ const resetButton = screen . getByRole ( 'button' , { name : 'Reset Extensions' } ) ;
93+ await user . click ( resetButton ) ;
94+ const confirmButton = screen . getByRole ( 'button' , { name : / r e s e t d u e d a t e / i } ) ;
95+ await user . click ( confirmButton ) ;
96+ expect ( mutateMock ) . toHaveBeenCalled ( ) ;
97+ } ) ;
98+
99+ it ( 'closes reset modal when cancel is clicked' , async ( ) => {
100+ render ( < RenderWithRouter /> ) ;
101+ const user = userEvent . setup ( ) ;
102+ const resetButton = screen . getByRole ( 'button' , { name : 'Reset Extensions' } ) ;
103+ await user . click ( resetButton ) ;
104+ const cancelButton = screen . getByRole ( 'button' , { name : / c a n c e l / i } ) ;
105+ await user . click ( cancelButton ) ;
106+ expect ( screen . queryByRole ( 'dialog' ) ) . not . toBeInTheDocument ( ) ;
107+ } ) ;
70108} ) ;
0 commit comments