-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
258 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* eslint prefer-arrow-callback: 0, func-names: 0, no-undef: 0 */ | ||
|
||
describe('DashboardController', function () { | ||
let $scope, $rootScope, $controller, DashboardService; | ||
const flag = 'success'; | ||
const leaderBoardGames = [ | ||
{ | ||
rank: '1', | ||
gamesWon: 2, | ||
username: 'Nkemjiks', | ||
}, | ||
{ | ||
rank: '2', | ||
gamesWon: 3, | ||
username: 'Dikaeinstein', | ||
}, | ||
]; | ||
|
||
const gamelogGames = [ | ||
{ | ||
players: [ | ||
{ username: 'Nkemjiks' }, | ||
{ username: 'Dikaeinstein' } | ||
], | ||
meta: { | ||
gameWinner: { | ||
username: 'Dikaeinstein' | ||
} | ||
} | ||
}, | ||
{ | ||
players: [ | ||
{ username: 'Nkemjiks' }, | ||
{ username: 'Dikaeinstein' } | ||
], | ||
meta: { | ||
gameWinner: { | ||
username: 'Dikaeinstein' | ||
} | ||
} | ||
} | ||
]; | ||
|
||
beforeEach(module('mean.system')); | ||
beforeEach(inject(function (_$controller_, _$rootScope_) { | ||
$rootScope = _$rootScope_; | ||
$controller = _$controller_; | ||
DashboardService = { | ||
leaderBoard: function leaderBoard() {}, | ||
gameLog: function gameLog() {} | ||
}; | ||
|
||
spyOn(DashboardService, 'leaderBoard').and.callFake(function () { | ||
return { | ||
then: function then(successCallback, errorCallback) { | ||
if (flag === 'success') successCallback({ games: leaderBoardGames }); | ||
else errorCallback('Error'); | ||
} | ||
}; | ||
}); | ||
|
||
spyOn(DashboardService, 'gameLog').and.callFake(function () { | ||
return { | ||
then: function then(successCallback, errorCallback) { | ||
if (flag === 'success') successCallback({ games: gamelogGames }); | ||
else errorCallback('Error'); | ||
} | ||
}; | ||
}); | ||
})); | ||
|
||
it('should return the leaderboard with 2 players fetched with $http', function () { | ||
$scope = $rootScope.$new(); | ||
$controller('DashboardController', { | ||
$scope, | ||
DashboardService, | ||
}); | ||
|
||
expect($scope.games.data.length).toEqual(2); | ||
expect($scope.games.data[0]).toEqual(leaderBoardGames[0]); | ||
}); | ||
|
||
it('should return the gamelog containing 2 games fetched with $http', function () { | ||
$scope = $rootScope.$new(); | ||
$controller('DashboardController', { | ||
$scope, | ||
DashboardService, | ||
}); | ||
|
||
expect($scope.currentUser.games.data.length).toEqual(0); | ||
$scope.fetchGamelog(); | ||
expect($scope.currentUser.games.data.length).toEqual(2); | ||
expect($scope.currentUser.games.data[0]).toEqual(gamelogGames[0]); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* eslint prefer-arrow-callback: 0, no-var: 0, func-names: 0, no-undef: 0, require-jsdoc: 0 */ | ||
|
||
describe('Directive: isLoading', function () { | ||
let $scope, $compile; | ||
|
||
beforeEach(module('mean.system')); | ||
beforeEach(inject(function (_$compile_, $rootScope, _$httpBackend_) { | ||
$compile = _$compile_; | ||
$scope = $rootScope.$new(); | ||
$httpBackend = _$httpBackend_; | ||
|
||
$compile(angular | ||
.element('<div is-loading></div>'))($scope); | ||
$scope.$digest(); | ||
})); | ||
|
||
it('should render hide loading indicator', function () { | ||
expect($scope.loadingIndicatorShow).toBeDefined(); | ||
expect($scope.loadingIndicatorShow).toBeFalsy(); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint prefer-arrow-callback: 0, no-var: 0, func-names: 0 */ | ||
|
||
angular.module('mean.system') | ||
.directive('isLoading', ['$http', function isLoading($http) { | ||
/** | ||
* isLoading directive factory function | ||
* | ||
* @param {object} scope Directive scope | ||
* @param {DOMElement} elem HTML element | ||
* | ||
* @returns {object} New directive instance | ||
*/ | ||
function link(scope, elem) { | ||
/** | ||
* Toggles loading indicator visibility | ||
* | ||
* @param {boolean} loading Either true or false | ||
* | ||
* @returns {null} Returns nothing | ||
*/ | ||
function toggleShowLoadingIndicator(loading) { | ||
if (loading) { | ||
scope.loadingIndicatorShow = true; | ||
elem.show(); | ||
} else { | ||
scope.loadingIndicatorShow = false; | ||
elem.hide(); | ||
} | ||
} | ||
|
||
/** | ||
* Checks request state | ||
* | ||
* @returns {boolean} true or false depending on request state | ||
*/ | ||
function isHttpLoading() { | ||
return $http.pendingRequests.length >= 1; | ||
} | ||
|
||
scope.isHttpLoading = isHttpLoading; | ||
scope.$watch(scope.isHttpLoading, toggleShowLoadingIndicator); | ||
} | ||
|
||
return { | ||
link, | ||
}; | ||
}]); |
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
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