最近我们开始为我们的应用程序编写测试用例,我们需要帮助为控制器编写测试用例。我们正在使用 Mocha、chai 和 Snion 库来编写测试用例。
这是 plunker 链接,其中包含我们的控制器代码。谁能帮助我们如何为这个控制器编写测试用例?我们将在此基础上实现其余部分。我们需要使用这个控制器进行初始推送。
http://plnkr.co/edit/oginuqO0afxnWbVMos0f?p=info
这是代码:
angular.module( 'ngBoilerplate.account', [
'ui.router','ngAnimate', 'ui.bootstrap','ngBoilerplate.contact','ngResource','jcs-autoValidate','ngCookies','ngTagsInput'
])
.controller('addAccount', function($scope,industryService,$http,$state,LoggedUser){
$scope.industry = [];
industryService.query().$promise.then(function(data) {
$scope.industry = data;
});
window.onbeforeunload = function (event) {
if ($scope.addAccountForm.$dirty) {
var message = 'If you leave this page you are going to lose all the unsaved changes.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
}
};
$scope.insertAccount = function(){
$scope.address = {
'line1':$scope.line1,
'line2':$scope.line2,
'city':$scope.city,
'zipCode':$scope.zipCode,
'state':$scope.state,
'country':$scope.country
};
console.log($scope.industryId);
if($scope.industryId!== undefined) {
$scope.industry = {
'id' : $scope.industryId
};
}
$http.post('/rest/users/'+LoggedUser.getUserName()+'/accounts',{
'name' : $scope.name,
'industryBean': $scope.industry,
'email' :$scope.email,
'phone' : $scope.phone,
'fax' : $scope.fax,
'website' : $scope.website,
'headquarters' : $scope.headquarters,
'dbaName' : $scope.dbaName,
'numberOfEmployees' : $scope.numberOfEmployees,
'annualRevenue':$scope.annualRevenue,
'logo' : $scope.logo,
'primaryContact': $scope.contact,
'addressBean':$scope.address
}).success(function(data){
$scope.account=data;
$state.go('main.account', {}, {reload: true});
});
};
})
.factory("loggedInUser", function($resource) {
return $resource("/rest/users/:username");
})
.factory("industryService", function($resource) {
return $resource("/rest/accounts/industry");
})
非常感谢任何帮助。
在此先感谢您,如果您对此有任何疑问,请告诉我。