2014-09-23 47 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"); 
});