@@ -37,29 +37,57 @@ const CheckboxModal: React.FunctionComponent = () => {
3737 </ >
3838} ;
3939
40+ const TextConfirmationModal : React . FunctionComponent = ( ) => {
41+ const [ isOpen , setIsOpen ] = React . useState ( false ) ;
42+ return < >
43+ < Button onClick = { ( ) => setIsOpen ( true ) } > Open modal</ Button >
44+ < WarningModal
45+ isOpen = { isOpen }
46+ title = 'Delete item?'
47+ confirmButtonLabel = 'Yes'
48+ cancelButtonLabel = 'No'
49+ onClose = { ( ) => setIsOpen ( false ) }
50+ onConfirm = { ( ) => setIsOpen ( false ) }
51+ textConfirmation = { { type : 'text' , isRequired : true } }
52+ deleteName = 'Item1' >
53+ The item will be deleted.
54+ </ WarningModal >
55+ </ >
56+ } ;
57+
4058describe ( 'WarningModal' , ( ) => {
4159 it ( 'renders WarningModal' , ( ) => {
42- cy . mount ( < BasicModal /> )
60+ cy . mount ( < BasicModal /> ) ;
4361 cy . get ( 'button' ) . click ( ) ;
4462 cy . get ( '[data-ouia-component-id="WarningModal"]' ) . should ( 'exist' ) ;
4563 cy . get ( '[data-ouia-component-id="WarningModal"]' ) . contains ( 'Unsaved changes' ) ;
4664 cy . get ( '[data-ouia-component-id="WarningModal"]' ) . contains ( 'Your page contains unsaved changes. Do you want to leave?' ) ;
4765 } ) ;
4866
4967 it ( 'confirm button should be disabled if checkbox is not checked' , ( ) => {
50- cy . mount ( < CheckboxModal /> )
68+ cy . mount ( < CheckboxModal /> ) ;
5169 cy . get ( 'button' ) . click ( ) ;
52- cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'have.attr' , 'disabled' )
70+ cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'have.attr' , 'disabled' ) ;
5371 cy . get ( '[data-ouia-component-id="WarningModal-confirm-checkbox"' ) . click ( ) ;
54- cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'not.have.attr' , 'disabled' )
72+ cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'not.have.attr' , 'disabled' ) ;
5573 } ) ;
5674
5775 it ( 'should reset the confirmation checkbox once reopened' , ( ) => {
58- cy . mount ( < CheckboxModal /> )
76+ cy . mount ( < CheckboxModal /> ) ;
5977 cy . get ( 'button' ) . click ( ) ;
6078 cy . get ( '[data-ouia-component-id="WarningModal-confirm-checkbox"' ) . click ( ) ;
6179 cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . click ( ) ;
6280 cy . get ( 'button' ) . click ( ) ;
63- cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'have.attr' , 'disabled' )
64- } )
81+ cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'have.attr' , 'disabled' ) ;
82+ } ) ;
83+
84+ it ( 'confirm button should be enabled only when confirmation text matches the item name' , ( ) => {
85+ cy . mount ( < TextConfirmationModal /> ) ;
86+ cy . get ( 'button' ) . click ( ) ;
87+ cy . get ( '[data-ouia-component-id="WarningModal-confirmation-text-input"' ) . type ( 'abcd' ) ;
88+ cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'have.attr' , 'disabled' ) ;
89+ cy . get ( '[data-ouia-component-id="WarningModal-confirmation-text-input"' ) . clear ( ) ;
90+ cy . get ( '[data-ouia-component-id="WarningModal-confirmation-text-input"' ) . type ( 'Item1' ) ;
91+ cy . get ( '[data-ouia-component-id="WarningModal-confirm-button"' ) . should ( 'not.have.attr' , 'disabled' ) ;
92+ } ) ;
6593} ) ;
0 commit comments