@@ -239,6 +239,62 @@ describe('angular-confirm', function() {
239239 } ) ;
240240 } ) ;
241241
242+
243+ describe ( 'with checkbox' , function ( ) {
244+
245+ beforeEach ( angular . mock . inject ( function ( $compile ) {
246+ element = angular . element ( '<input type="checkbox" ng-click="click()" confirm="Are you sure?" />' ) ;
247+ $compile ( element ) ( $scope ) ;
248+ $scope . $digest ( ) ;
249+ } ) ) ;
250+
251+ it ( "should call confirm on click and not call the function" , function ( ) {
252+ element . triggerHandler ( 'click' ) ;
253+ expect ( $scope . click ) . not . toHaveBeenCalled ( ) ;
254+ expect ( $confirm ) . toHaveBeenCalled ( ) ;
255+ expect ( element [ 0 ] . checked ) . toBe ( false ) ;
256+ } ) ;
257+
258+ } ) ;
259+
260+ describe ( 'with checkbox and confirm if false' , function ( ) {
261+
262+ beforeEach ( angular . mock . inject ( function ( $compile ) {
263+ element = angular . element ( '<input type="checkbox" ng-click="click()" confirm="Are you sure?" confirm-if="truthy" />' ) ;
264+ $compile ( element ) ( $scope ) ;
265+ $scope . $digest ( ) ;
266+ } ) ) ;
267+
268+ it ( "should set the checkbox to checked" , function ( ) {
269+ expect ( element [ 0 ] . checked ) . toBe ( false ) ;
270+ $scope . truthy = false ;
271+ $scope . $apply ( ) ;
272+ element . triggerHandler ( 'click' ) ;
273+ expect ( $scope . click ) . toHaveBeenCalled ( ) ;
274+ expect ( $confirm ) . not . toHaveBeenCalled ( ) ;
275+ expect ( element [ 0 ] . checked ) . toBe ( true ) ;
276+ } ) ;
277+ } ) ;
278+
279+ describe ( 'with checkbox already checked and confirm if false' , function ( ) {
280+
281+ beforeEach ( angular . mock . inject ( function ( $compile ) {
282+ element = angular . element ( '<input type="checkbox" ng-click="click()" confirm="Are you sure?" confirm-if="truthy" checked />' ) ;
283+ $compile ( element ) ( $scope ) ;
284+ $scope . $digest ( ) ;
285+ } ) ) ;
286+
287+ it ( "should set the checkbox to checked" , function ( ) {
288+ expect ( element [ 0 ] . checked ) . toBe ( true ) ;
289+ $scope . truthy = false ;
290+ $scope . $apply ( ) ;
291+ element . triggerHandler ( 'click' ) ;
292+ expect ( $scope . click ) . toHaveBeenCalled ( ) ;
293+ expect ( $confirm ) . not . toHaveBeenCalled ( ) ;
294+ expect ( element [ 0 ] . checked ) . toBe ( false ) ;
295+ } ) ;
296+ } ) ;
297+
242298 } ) ;
243299
244300} ) ;
0 commit comments