diff --git a/client/src/app/projects/projects-list.tpl.html b/client/src/app/projects/projects-list.tpl.html index bfa4011c..3e56f7e3 100644 --- a/client/src/app/projects/projects-list.tpl.html +++ b/client/src/app/projects/projects-list.tpl.html @@ -9,14 +9,12 @@ - {{project.name}} - {{project.desc}} + {{project.name}} + {{project.desc}} + {{ getMyRoles(project) }} - {{project.getRoles(authService.currentUser.id)}} - - - Product backlog - Sprints + Product backlog + Sprints diff --git a/client/src/app/projects/projects.js b/client/src/app/projects/projects.js index 70f0ab4e..dce44383 100644 --- a/client/src/app/projects/projects.js +++ b/client/src/app/projects/projects.js @@ -14,18 +14,22 @@ angular.module('projects', ['resources.projects', 'productbacklog', 'sprints', ' }); }]) -.controller('ProjectsViewCtrl', ['$scope', '$location', 'projects', function ($scope, $location, projects) { +.controller('ProjectsViewCtrl', ['$scope', '$location', 'projects', 'security', function ($scope, $location, projects, security) { $scope.projects = projects; - $scope.viewProject = function (projectId) { - $location.path('/projects/'+projectId); + $scope.viewProject = function (project) { + $location.path('/projects/'+project.$id()); }; - $scope.manageBacklog = function (projectId) { - $location.path('/projects/'+projectId+'/productbacklog'); + $scope.manageBacklog = function (project) { + $location.path('/projects/'+project.$id()+'/productbacklog'); }; - $scope.manageSprints = function (projectId) { - $location.path('/projects/'+projectId+'/sprints'); + $scope.manageSprints = function (project) { + $location.path('/projects/'+project.$id()+'/sprints'); + }; + + $scope.getMyRoles = function(project) { + return project.getRoles(security.currentUser.id); }; }]); diff --git a/client/test/unit/app/projects/projects.spec.js b/client/test/unit/app/projects/projects.spec.js new file mode 100644 index 00000000..bc84e4c3 --- /dev/null +++ b/client/test/unit/app/projects/projects.spec.js @@ -0,0 +1,84 @@ +describe('ProjectsViewCtrl', function() { + + beforeEach(module('projects')); + + function runController($scope, projects) { + inject(function($controller) { + $controller('ProjectsViewCtrl', { $scope: $scope, projects: projects }); + }); + } + + function createMockProject(id) { + return { + $id: function() { return id; }, + getRoles: jasmine.createSpy('getRoles') + }; + } + + function createMockProjectList() { + return [ createMockProject('project-id') ]; + } + + it("attaches the list of projects to the scope", function() { + var $scope = {}, + projects = createMockProjectList(); + + runController($scope, projects); + expect($scope.projects).toBe(projects); + }); + + describe('viewProject(projectId)', function() { + var $scope = {}, + projects = createMockProjectList(); + + it('changes the location', inject(function($location) { + spyOn($location, 'path'); + runController($scope, projects); + + $scope.viewProject(projects[0]); + + expect($location.path).toHaveBeenCalledWith('/projects/project-id'); + })); + }); + + describe('manageBacklog(projectId)', function() { + var $scope = {}, + projects = createMockProjectList(); + + it('changes the location', inject(function($location) { + spyOn($location, 'path'); + runController($scope, projects); + + $scope.manageBacklog(projects[0]); + + expect($location.path).toHaveBeenCalledWith('/projects/project-id/productbacklog'); + })); + }); + + describe('manageSprints(projectId)', function() { + var $scope = {}, + projects = createMockProjectList(); + + it('changes the location', inject(function($location) { + spyOn($location, 'path'); + runController($scope, projects); + + $scope.manageSprints(projects[0]); + + expect($location.path).toHaveBeenCalledWith('/projects/project-id/sprints'); + })); + }); + + describe('getMyRoles(project)', function() { + var $scope = {}, + projects = createMockProjectList(); + + it('calls getRoles on the project with the current user', inject(function(security) { + security.currentUser = { id: 'current-user-id'}; + runController($scope, projects); + $scope.getMyRoles(projects[0]); + expect(projects[0].getRoles).toHaveBeenCalledWith('current-user-id'); + })); + + }); +}); \ No newline at end of file