Created
April 20, 2015 08:59
-
-
Save junderhill/e181ce866ab1ebb1f805 to your computer and use it in GitHub Desktop.
Activity controller injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('dailysummary') | |
.controller('activityController', activityController); | |
activityController.$inject = ['roleService', 'activityService', '$scope']; | |
function activityController(roleService, activityService, $scope) { | |
var vm = this; | |
vm.selectedDate = new Date(); | |
var currentRole = roleService.getCurrentRole(); | |
var currentTeam = roleService.getCurrentTeam(); | |
activityService.getActivity(vm.selectedDate, vm.selectedDate, roleService.getCurrentUser(), currentRole['AssignmentID'], currentRole['UserType'], currentTeam['ID']) | |
.then(function(data) { | |
console.log(data); | |
}, function() { | |
console.log('Error getting activity'); | |
}); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
describe('Activity controller', function(){ | |
var activityController; | |
var $httpBackend, $scope; | |
var mockRoleService; | |
beforeEach(module('dailysummary')); | |
beforeEach(inject(function($rootScope, _$httpBackend_, roleService){ | |
$scope = $rootScope.$new(); | |
$httpBackend = _$httpBackend_; | |
var stubTeamResponse = { "ClientID": 1, "CostCentre": "-1", "CountryID": 1, "Description": "Demonstration", "EndDate": null, "EtmsDescription": "Care 2", "EtmsID": 2, "ID": 3, "IsActive": false, "IsStockModuleEnabled": true, "NumberOfWeeksCare1": 20, "PharmaDatabase": "OneKey", "Stylesheet": "ai2f01.css", "TeamTypeID": 7, "UserID": "100201", "WorkingDays": 7, "DatabaseID": 0, "CompanyID": 1, "ExpensesCurrencyID": 3228 }; | |
$httpBackend.when('GET', /^(http:\/\/)[a-z.:0-9]*(\/api\/User\/GetTeamForAssignment\?assignmentId=\d+&assignmentType=\d)$/).respond(200, stubTeamResponse); | |
mockRoleService = roleService; | |
mockRoleService.setCurrentRole({"AssignmentID":21,"EndDate":"2049-12-31T00:00:00","StartDate":"2000-01-01T00:00:00","UserType":1,"AccessLevel":"00000000-0000-0000-0000-000000000000","Description":"Demonstration Territory 1","TeamID":null}); | |
mockRoleService.setCurrentUser('100607'); | |
})); | |
describe("on initialisation", function () { | |
beforeEach(inject(function($controller) { | |
console.log(activityController); | |
activityController = $controller('activityController', { | |
'$scope': $scope, | |
'roleService' : mockRoleService | |
}); | |
console.log("TEST"); | |
})); | |
it("selected date is not null", function(){ | |
expect(activityController.selectedDate).not.toBeNull(); | |
}); | |
it("sets the selected date to current date", function(){ | |
var currentDate = new Date(); | |
expect(activityController.selectedDate).toEqual(currentDate); | |
}); | |
it("calls the web service", function(){ | |
$httpBackend.expectGET(/^(http:\/\/)[a-z.:0-9]*(\/api\/Activity\/GetActivitiesForDateRange\?from=.{20}&to=.{20}&userId=\d{6}&roleId=\d{1,4}&roleTypeId=\d{1}&teamId=\d{1,4})$/); | |
$httpBackend.flush(); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('dailysummary').service('activityService', activityService); | |
function activityService($http, $q){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('dailysummary').service('roleService', roleService); | |
function roleService($http, $q) { | |
var currentRole = null; | |
var currentTeam = null; | |
var currentUser = null; | |
this.getRolesForUser = function(userId){ | |
var deferred = $q.defer(); | |
$http.get("http://localhost:14938/api/User/GetRoles?userId=" + userId) | |
.success(function(data){ | |
deferred.resolve(data); | |
}); | |
return deferred.promise; | |
} | |
this.setCurrentRole = function(role){ | |
currentRole = role; | |
$http.get("http://localhost:14938/api/User/GetTeamForAssignment?assignmentId=" + role["AssignmentID"] + "&assignmentType=" + role["UserType"]) | |
.success(function (data) { | |
currentTeam = data; | |
}); | |
} | |
this.getCurrentRole = function(){ | |
return currentRole; | |
} | |
this.setCurrentTeam = function(team){ | |
currentTeam = team; | |
} | |
this.getCurrentTeam = function(){ | |
return currentTeam; | |
} | |
this.setCurrentUser = function(user){ | |
currentUser = user; | |
} | |
this.getCurrentUser = function(){ | |
return currentUser; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment