Skip to content

Commit

Permalink
adds global stats directive
Browse files Browse the repository at this point in the history
  • Loading branch information
giamir committed Mar 29, 2016
1 parent d2e1f9f commit e763fe4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 25 deletions.
33 changes: 33 additions & 0 deletions public/js/directives/globalStatsDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(function() {

function globalStats() {
return {
restrict: 'EA',
template: [
'<section class="col-md-8 col-lg-8 col-xl-8">',
'<table class="table table-striped">',
'<thead>',
'<tr>',
'<th>Statistic</th>',
'<th>Season <small>(AVG)</small></th>',
'<th>Last Match</th>',
'</tr>',
'</thead>',
'<tbody>',
'<tr ng-repeat="stat in vm.globalStats">',
'<td>{{stat.featureName}}</td>',
'<td>{{stat.season}}</td>',
'<td>{{stat.lastMatch}}</td>',
'</tr>',
'</tbody>',
'</table>',
'</section>'
].join(''),
controllerAs: 'vm',
controller: 'GlobalStats'
};
}

angular.module('PlayerStats')
.directive('globalStats', globalStats);
})();
2 changes: 2 additions & 0 deletions public/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

<script src="js/controllers/globalStatsController.js"></script>
<script src="js/controllers/singleMatchStatsController.js"></script>

<script src="js/directives/globalStatsDirective.js"></script>
</head>

<body>
Expand Down
19 changes: 1 addition & 18 deletions public/views/partials/global-stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,4 @@ <h3>Name Surname</h3>
<h4>Football Team</h4>
</header>

<section class="col-md-8 col-lg-8 col-xl-8" ng-controller="GlobalStats as ctrl">
<table class="table table-striped">
<thead>
<tr>
<th>Statistic</th>
<th>Season <small>(AVG)</small></th>
<th>Last Match</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="stat in ctrl.globalStats">
<td>{{stat.featureName}}</td>
<td>{{stat.season}}</td>
<td>{{stat.lastMatch}}</td>
</tr>
</tbody>
</table>
</section>
<global-stats></global-stats>
4 changes: 2 additions & 2 deletions test/e2e/features/statisticsFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ describe('Displaying Player Statistics', function() {
it('change the match stats displayed clicking the button of the match wanted', function() {
homepage.clickLastSingleMatchLink();
expect(homepage.getSingleMatchDisplayedAlias())
.toEqual(homepage.getLastSingleMatchAlias());
.toEqual(homepage.getLastSingleMatchAlias());
});

it('change the statistic displayed in the graph clicking the button of the statistic wanted', function() {
homepage.clickLastStatisticLink();
expect(homepage.getStatisticDisplayedAlias())
.toContain(homepage.getLastStatisticAlias());
.toContain(homepage.getLastStatisticAlias());
});
});
});
10 changes: 5 additions & 5 deletions test/e2e/pages/home.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var homepage = {
},

getNameFirstGlobalStat: function() {
return element.all(by.repeater('stat in ctrl.globalStats'))
return element.all(by.repeater('stat in vm.globalStats'))
.then(function(elems) {
return elems[0].element(by.binding('stat.featureName')).getText();
});
Expand All @@ -15,14 +15,14 @@ var homepage = {
clickLastSingleMatchLink: function() {
return element.all(by.repeater('mw in ctrl.matchWeekKeys'))
.then(function(elems) {
return elems[elems.length-1].element(by.binding('mw')).click();
return elems[elems.length-1].element(by.binding('mw')).click();
});
},

getLastSingleMatchAlias: function() {
return element.all(by.repeater('mw in ctrl.matchWeekKeys'))
.then(function(elems) {
return elems[elems.length-1].element(by.binding('mw')).getText();
return elems[elems.length-1].element(by.binding('mw')).getText();
});
},

Expand All @@ -33,14 +33,14 @@ var homepage = {
clickLastStatisticLink: function() {
return element.all(by.repeater('navStat in ctrl.singleMatchStats'))
.then(function(elems) {
return elems[elems.length-1].element(by.binding('navStat.featureName')).click();
return elems[elems.length-1].element(by.binding('navStat.featureName')).click();
});
},

getLastStatisticAlias: function() {
return element.all(by.repeater('navStat in ctrl.singleMatchStats'))
.then(function(elems) {
return elems[elems.length-1].element(by.binding('navStat.featureName')).getText();
return elems[elems.length-1].element(by.binding('navStat.featureName')).getText();
});
},

Expand Down
35 changes: 35 additions & 0 deletions test/unit/directives/globalStatsDirective.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe('directive: globalStats', function() {
var compile;
var scope;
var directiveElem;

beforeEach(function() {
module('PlayerStats', function($controllerProvider) {
$controllerProvider.register('GlobalStats', function() {
jasmine.createSpyObj('GlobalStats', ['globalStats']);
});
});
});

beforeEach(function(){
inject(function($compile, $rootScope){
compile = $compile;
scope = $rootScope.$new();
});
directiveElem = getCompiledElement();
});

function getCompiledElement(){
var element = angular.element('<global-stats></global-stats>');
var compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}

it('should have a table element', function () {
var tableElement = directiveElem.find('table');
expect(tableElement.attr('class'))
.toEqual('table table-striped');
});

});

0 comments on commit e763fe4

Please sign in to comment.