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 = [
@@ -25,6 +27,9 @@ describe('DateExtensionsPage', () => {
2527 data : mockDateExtensions ,
2628 isLoading : false ,
2729 } ) ;
30+ ( useResetDateExtensionMutation as jest . Mock ) . mockReturnValue ( {
31+ mutate : jest . fn ( ) ,
32+ } ) ;
2833 } ) ;
2934
3035 const RenderWithRouter = ( ) => (
@@ -67,4 +72,37 @@ describe('DateExtensionsPage', () => {
6772 const resetLinks = screen . getAllByRole ( 'button' , { name : 'Reset Extensions' } ) ;
6873 expect ( resetLinks ) . toHaveLength ( mockDateExtensions . length ) ;
6974 } ) ;
75+
76+ it ( 'opens reset modal when reset button is clicked' , async ( ) => {
77+ render ( < RenderWithRouter /> ) ;
78+ const user = userEvent . setup ( ) ;
79+ const resetButton = screen . getByRole ( 'button' , { name : 'Reset Extensions' } ) ;
80+ await user . click ( resetButton ) ;
81+ expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
82+ expect ( screen . getByText ( / r e s e t e x t e n s i o n s f o r / i) ) . toBeInTheDocument ( ) ;
83+ const confirmButton = screen . getByRole ( 'button' , { name : / r e s e t d u e d a t e / i } ) ;
84+ expect ( confirmButton ) . toBeInTheDocument ( ) ;
85+ } ) ;
86+
87+ it ( 'calls reset mutation when confirm reset is clicked' , async ( ) => {
88+ const mutateMock = jest . fn ( ) ;
89+ ( useResetDateExtensionMutation as jest . Mock ) . mockReturnValue ( { mutate : mutateMock } ) ;
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