2014-09-23 49 views
0

我有一个kendo排序的现有案例,我试图使用业力和茉莉测试提示函数。有关如何使用Kendo Sortable模拟拖动事件以便调用提示函数的任何想法?Kendo Sortable + Karma:单元测试提示功能

$element.find("#sortable-container").kendoSortable({ 
    axis: "none", 
    cursor: "move", 
    container: "#sortable-container", 
    hint: function (element) { //this is not called and is messing with my karma coverage 
     var elementHint = element.clone(); 

     elementHint.find('[ng-transclude=""]').removeAttr("ng-transclude"); 
     elementHint.find(".hw-closeable").removeClass("hw-closeable"); 

     return elementHint.addClass("sortable-tooltip"); 
    } 
}); 

回答

0

对于单元测试,手动调用提示函数对我来说已经足够了。我同意,对于集成测试来说,需要一些更好的东西。

我的代码如下所示:

指令

angular.module('appSample').directive('sortableDiv', function() { 
    return { 
     restrict: 'A', 
     transclude: true, 
     templateUrl: 'src/widgets/sortable-div/sortable-div.html', 
     controller: function ($scope, $element) { 
      $element.find("#sortable-container").kendoSortable({ 
       axis: "none", 
       cursor: "move", 
       container: "#sortable-container", 
       hint: function (element) { 
        return element.clone().addClass("sortable-tooltip"); 
       } 
      }); 
     } 
    }; 
}); 

指令HTML

<div id="sortable-container" class="row sortable-container" ng-transclude></div> 

噶测试

function sortableDiv() { 
    var el = angular.element('<div sortable-div><div id="sort1">Sort me!</div> <div id="sort2">Sort me again!</div></div>'); 

    compile(el)(scope); 

    scope.$digest(); 
    timeout.flush(); 

    return el; 
} 

it('should hint a sortable div', function() { 

    var el = sortableDiv(); 

    var elHint = el.find("#sortable-container").data("kendoSortable").options.hint(el.find("#sort1")); 

    expect(elHint.attr("class")).toContain("sortable-tooltip"); 
});