Skip to content
This repository was archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Added unit tests for nav.js
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankDeGroot committed Jan 6, 2013
1 parent ca3bba6 commit 209f4f6
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 20 deletions.
5 changes: 3 additions & 2 deletions app/js/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

/*global ProjectCreateCtrl ProjectEditCtrl ProjectListCtrl */
angular.module('main', ['resProject']).
config(function ($routeProvider) {
'use strict';

$routeProvider.
when('/', { templateUrl: 'partials/home.html' }).
when('/about', { templateUrl: 'partials/about.html' }).
Expand Down
21 changes: 10 additions & 11 deletions app/js/ctrl/nav.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
'use strict';
function NavCtrl($scope, $location) {
'use strict';

function NavCtrl($scope, $location) {
$scope.isUrl = function (path, className) {
if ($location.path() == path) {
if ($location.path() === path) {
return className;
} else {
return "";
}
}
return "";
};

$scope.hasUrl = function (path, className) {
if ($location.path().substring(0, path.length) == path) {
if ($location.path().search(path) === 0) {
return className;
} else {
return "";
}
}
}
return "";
};
}
NavCtrl.$inject = ['$scope', '$location'];
4 changes: 3 additions & 1 deletion app/js/ctrl/project/create.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function ProjectCreateCtrl($scope, $location, Project) {
'use strict';

$scope.save = function () {
Project.save($scope.project, function (project) {
$location.path('/project');
});
}
};
}
2 changes: 2 additions & 0 deletions app/js/ctrl/project/edit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function ProjectEditCtrl($scope, $location, $routeParams, Project) {
'use strict';

var self = this;

Project.get({ id: $routeParams.projectId }, function (project) {
Expand Down
2 changes: 2 additions & 0 deletions app/js/ctrl/project/list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
function ProjectListCtrl($scope, Project) {
'use strict';

$scope.projects = Project.query();
}
4 changes: 3 additions & 1 deletion app/js/ctrl/signin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function SignInCtrl($scope) {
$scope.signIn = function() {
'use strict';

$scope.signIn = function () {
alert('Sign in of ' + $scope.name);
};
}
8 changes: 4 additions & 4 deletions app/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/* Filters */

angular.module('myApp.filters', []).
filter('interpolate', ['version', function(version) {
return function(text) {
return String(text).replace(/\%VERSION\%/mg, version);
}
filter('interpolate', ['version', function (version) {
return function (text) {
return String(text).replace(/\%VERSION\%/mg, version);
};
}]);
37 changes: 36 additions & 1 deletion test/unit/ctrl/navSpec.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
'use strict';
/*global beforeEach describe expect inject it NavCtrl */
describe('NavCtrl', function () {
'use strict';

var controller, path, location, scope;

beforeEach(inject(function ($rootScope, $controller) {
path = undefined;
location = {
path: function () {
return path;
}
};
scope = $rootScope.$new();
controller = $controller(NavCtrl, { $scope: scope, $location: location });
}));

it('Should return an empty string when url does not match.', function () {
path = 'url1';
expect(scope.isUrl('url2', 'className1')).toEqual('');
});

it('Should return the className when url does match.', function () {
path = 'url1';
expect(scope.isUrl('url1', 'className1')).toEqual('className1');
});

it('Should return an empty string when current url does not start with the supplied url.', function () {
path = 'url1-url';
expect(scope.hasUrl('url2', 'className1')).toEqual('');
});

it('Should return the className when current url starts with the supplied url.', function () {
path = 'url1-url';
expect(scope.hasUrl('url1', 'className1')).toEqual('className1');
});
});
14 changes: 14 additions & 0 deletions test/unit/ctrl/project/listSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('ProjectListCtrl', function () {
'use strict';

var controller, scope;

beforeEach(inject(function ($rootScope, $controller, $httpBackend) {
scope = $rootScope.$new()
controller = $controller(ProjectListCtrl, { $scope: scope, Project: Project });
}));

//it('Should query for all projects and assign it to projects.', function () {

//});
});

0 comments on commit 209f4f6

Please sign in to comment.