Я пишу модульный тест, и мне нужно иметь возможность смоделировать объект сетки кендо.
Я написал следующий модульный тест с использованием среды жасмина:
describe("Asset Configuration Grid", () => {
var ctrl: AssetConfigurationGridController;
var $http: ng.IHttpService;
var $state: ng.ui.IStateService;
var $jsonBlobService: JsonBlobsService;
var ctrl: AssetConfigurationGridController;
beforeEach(() => {
ctrl = new AssetConfigurationGridController($http, $state, $jsonBlobService);
});
describe("Test search for active components", () => {
it("Should show only the active components only", () => {
let gridOptions = ctrl.savedAssetOptions(true);
ctrl.setActiveTab('Active');
ctrl.searchQuery = 'someString';
});
});
});
Вот пример HTML моей сетки кендо:
<md-tab>
<md-tab-title ng-click="$ctrl.setActiveTab('active')">
Active
</md-tab-title>
<md-tab-body>
<div kendo-grid="$ctrl.activeAssetsGrid" k-options="$ctrl.savedAssetOptions(true)">
</div>
</md-tab-body>
</md-tab>
Исходя из приведенного выше кода, я хотел бы написать модульный тест для макета следующего объекта:
<div kendo-grid="$ctrl.activeAssetsGrid" k-options="$ctrl.savedAssetOptions(true)">
Вот мой код контроллера:
export class AssetConfigurationGridController {
private _searchQuery: string;
private activeAssetsGrid: kendo.ui.Grid;
private inactiveAssetsGrid: kendo.ui.Grid;
private incompleteAssetsGrid: kendo.ui.Grid;
private activeTab: string = 'active';
static $inject = ['$http', '$state', 'jsonBlobsService'];
constructor(private http: ng.IHttpService, private state: ng.ui.IStateService, private jsonBlobsService: JsonBlobsService) {
}
get searchQuery(): string {
return this._searchQuery;
}
set searchQuery(value: string) {
this._searchQuery = value;
if (this.activeTab === 'active') {
if (this.activeAssetsGrid) {
this.activeAssetsGrid.dataSource.fetch();
}
} else if (this.activeTab === 'inactive') {
if (this.inactiveAssetsGrid) {
this.inactiveAssetsGrid.dataSource.fetch();
}
} else if (this.activeTab === 'incomplete') {
if (this.incompleteAssetsGrid) {
this.incompleteAssetsGrid.dataSource.fetch();
}
}
}
setActiveTab(value: string) {
this.activeTab = value;
this.searchQuery = "";
}
private baseGridOptions: kendo.ui.GridOptions = {
pageable: true,
sortable: true,
groupable: false,
selectable: false,
dataSource: {
}
};
savedAssetOptions(active: boolean): kendo.ui.GridOptions {
//Some code here
}
get incompleteResourceOptions(): kendo.ui.GridOptions {
//Some code here
}
edit(id: number) {
}
draft(id: number) {
}
}
Ожидаемый результат - имитация объекта сетки кендо.