2014-05-07 40 views
0

我有一個KendoUI網格,其中一列是命令。測試Kendo網格命令

$("#table").kendoGrid({ 
    columns: [{ 
     command: { text: $scope.open, click: $scope.openItem}, 
     title: $scope.link, 
     field: "Id 
    }] 

命令綁定到看起來像這樣

$scope.openItem= function (e) { 
    e.preventDefault(); 

    var row = $(e.currentTarget).closest("tr"); 

    var dataItem = this.dataItem(row); 

    var id = dataItem.Id; 
    var evalId = dataItem.EvaluationId; 

    performeAction(id, evalId); 
}; 

我們正在使用的業力做我們的測試的範圍angularJS功能和我打了一個路障與此「openItem」功能。

這是測試如何看待當下

it("Button testing", inject(function ($compile){ 
    var object = {}; 
    element = angular.element('<myAngularDirective></myAngularDirective>'); 
    $compile(element)(scope); 
    scope.$digest(); 

    //element.scope().openSelectedInstantCoach(object); 
})); 

的部分是造成問題的是註釋行。上述三行對其他測試正常工作。由於kendoUI處理點擊的方式,我不知道我需要傳遞給函數。

任何想法?

回答

0

你真的需要模擬Kendo UI如何處理命令上的「點擊」嗎?也許它更容易模擬點擊並讓Kendo UI生成參數。

舉例:grid是KendoUI網格對象初始化爲:

var grid = $("#grid").kendoGrid({ 
    ..., 
    columns : [ 
     { command : { text: "open", click: myClick }, title: "Cmd" }, 
     ... 
    ] 

}).data("kendoGrid"); 

當你想在0行點擊open命令,你可以做到這一點是:

var btn = $("tr:nth(0) .k-grid-open", grid.tbody); 
btn.trigger("click"); 

我使用tr:nth(0)和目標button在特定行中使用k-grid-open CSS類找到該行(這是KendoUI從生成的東西你的按鈕的0)。

現在,觸發按鈕就像調用trigger("click")一樣簡單。

你可以在這裏看到一個例子:http://jsfiddle.net/OnaBai/5APDW/