@@ -104,29 +104,36 @@ describe('Modal', () => {
104
104
} )
105
105
106
106
describe ( 'actions' , ( ) => {
107
- const actions = [
108
- { key : 'cancel' , content : 'Cancel' } ,
109
- { key : 'ok' , content : 'OK' , triggerClose : true } ,
110
- ]
107
+ it ( 'closes the modal on action click' , ( ) => {
108
+ wrapperMount ( < Modal actions = { [ 'OK' ] } defaultOpen /> )
111
109
112
- it ( 'handles onItemClick' , ( ) => {
113
- const onActionClick = sandbox . spy ( )
114
- const event = { target : null }
110
+ assertBodyContains ( '.ui.modal' )
111
+ domEvent . click ( '.ui.modal .actions .button' )
112
+ assertBodyContains ( '.ui.modal' , false )
113
+ } )
115
114
116
- wrapperMount ( < Modal defaultOpen actions = { { actions, onActionClick } } /> )
115
+ it ( 'calls shorthand onActionClick callback' , ( ) => {
116
+ const onActionClick = sandbox . spy ( )
117
+ const modalActions = { onActionClick, actions : [ { key : 'ok' , content : 'OK' } ] }
118
+ wrapperMount ( < Modal actions = { modalActions } defaultOpen /> )
117
119
118
- domEvent . click ( '.button:last-child' )
120
+ onActionClick . should . not . have . been . called ( )
121
+ domEvent . click ( '.ui.modal .actions .button' )
119
122
onActionClick . should . have . been . calledOnce ( )
120
- onActionClick . should . have . been . calledWithMatch ( event , { content : 'OK' } )
121
123
} )
124
+ } )
122
125
123
- it ( 'handles triggerClose prop on an action' , ( ) => {
124
- wrapperMount ( < Modal defaultOpen actions = { actions } /> )
126
+ describe ( 'onActionClick' , ( ) => {
127
+ it ( 'is called when an action is clicked' , ( ) => {
128
+ const onActionClick = sandbox . spy ( )
129
+ const event = { target : null }
130
+ const props = { actions : [ 'OK' ] , defaultOpen : true , onActionClick }
125
131
126
- domEvent . click ( '.button:first-child' )
127
- assertBodyContains ( '.ui.modal' )
128
- domEvent . click ( '.button:last-child' )
129
- assertBodyContains ( '.ui.modal' , false )
132
+ wrapperMount ( < Modal { ...props } /> )
133
+ domEvent . click ( '.ui.modal .actions .button' )
134
+
135
+ onActionClick . should . have . been . calledOnce ( )
136
+ onActionClick . should . have . been . calledWithMatch ( event , props )
130
137
} )
131
138
} )
132
139
0 commit comments