Skip to content

Commit

Permalink
Add navbar UI & dependencies for testing angular (#47)
Browse files Browse the repository at this point in the history
- Add navbar as a directive
- Add mock controller
- Improve and fix navbar issues from previous versions
  - Add top nav case for long names
- Sanitize transaltions
- Add font-awesome
- Update README.md with font-awesome configuration

- Add dependencies for testing angular
  - Add karma, jasmine and angular-mocks dependencies
  - Add karma configuration
  - Add karma coverage reporter
  - Add karma to travis CI
  - Add codecov.io to project
  - Update pre-push hook to run karma tests

- Add navbar directive test
  • Loading branch information
MatiasComercio committed Jan 15, 2017
1 parent 88ff648 commit a0947b2
Show file tree
Hide file tree
Showing 25 changed files with 623 additions and 113 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@ bower_components/
dist/
.sass-cache/
.tmp/

coverage/
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ branches:
- master
- development
- stage
node_js: 6.1
before_install:
- curl -s -o $HOME/.nvm/nvm.sh https://raw.githubusercontent.com/creationix/nvm/v0.31.0/nvm.sh
- source $HOME/.nvm/nvm.sh
- nvm install stable
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- pip install --user codecov
install:
- npm install
- npm install -g bower
- bower install
script:
- npm test
- mvn clean package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=${SONAR_TOKEN}
- mvn sonar:sonar -Dsonar.sourceEncoding=UTF-8 -Dsonar.analysis.mode=preview -Dsonar.github.repository=MatiasComercio/paw -Dsonar.github.login=MatiasComercio -Dsonar.github.oauth=${GITHUB_ACCESS_TOKEN} -Dsonar.host.url=https://sonarqube.com -Dsonar.login=${SONAR_TOKEN} -Dsonar.github.pullRequest=${TRAVIS_PULL_REQUEST}
after_success:
- mvn clean test jacoco:report coveralls:report
- codecov
cache:
directories:
- '$HOME/.m2'
Expand Down
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ module.exports = function (grunt) { // eslint-disable-line strict
outputFile: '<%= yeoman.dist %>/scripts/paths.js'
}
}
},

karma: {
unit: {
configFile: 'karma.conf.js'
}
}
});

Expand Down Expand Up @@ -511,4 +517,6 @@ module.exports = function (grunt) { // eslint-disable-line strict
'newer:eslint',
'build'
]);

grunt.loadNpmTasks('grunt-karma');
};
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SGA - Sistema de Gestión Académica


[![Build Status](https://travis-ci.org/MatiasComercio/paw.svg?branch=development)](https://travis-ci.org/MatiasComercio/paw) [![Coverage Status](https://coveralls.io/repos/github/MatiasComercio/paw/badge.svg)](https://coveralls.io/github/MatiasComercio/paw) [![Code Climate](https://codeclimate.com/github/MatiasComercio/paw/badges/gpa.svg)](https://codeclimate.com/github/MatiasComercio/paw)
[![Build Status](https://travis-ci.org/MatiasComercio/paw.svg?branch=development)](https://travis-ci.org/MatiasComercio/paw) [![codecov](https://codecov.io/gh/MatiasComercio/paw/branch/development/graph/badge.svg)](https://codecov.io/gh/MatiasComercio/paw) [![Code Climate](https://codeclimate.com/github/MatiasComercio/paw/badges/gpa.svg)](https://codeclimate.com/github/MatiasComercio/paw)

[![alt text][2]][1]

Expand All @@ -22,6 +22,31 @@ You can modify the [pre-push.sh](scripts/pre-push.sh) script to run different sc

You can skip the hook by adding `--no-verify` to your `git push`.

## Font Awesome configuration

Thanks: http://likesalmon.net/use-font-awesome-on-yeoman-angularjs-projects/

- Install Font Awesome:
- `$ bower install font-awesome --save`
- Add Bootstrap to the top of `main.scss`:
- `@import "bootstrap-sass/lib/bootstrap";`
- Change the font path (`font-awesome/scss/_variables.scss`):
- `$fa-font-path: "/bower_components/font-awesome/fonts";`
- Add the Font Awesome CSS to `main.scss`:
- `@import "font-awesome/scss/font-awesome";`

## Karma & Jasmine
We are using Karma alongside with Jasmine for our Angular unit tests.
It may be useful to install karma-cli globally.

`$ npm install -g karma-cli`

Then, you can run Karma simply by `karma` from anywhere and it will always run the local version.

For example, to run Angular tests, simply run

`$ karma start`

## Accounts
- Admin:
- DNI: 38457012
Expand Down
32 changes: 17 additions & 15 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,36 @@
<![endif]-->
<!-- Add your site or application content here -->
<div class='container'>
<div class='header'>
<ul class='nav nav-pills pull-right'>
<li class='active'><a ng-href='#'>Home</a></li>
<li><a ng-href='#/about'>About</a></li>
<li><a ng-href='#'>Contact</a></li>
</ul>
<h3 class='text-muted'>paw</h3>
<xnavbar></xnavbar>

<div class='content'>
<div class='header'>
<h3 class='text-muted'>paw</h3>
<hr />
</div>
<p translate='{{ controller.bodyControllerText }}'></p>

<div ng-view=''></div>
</div>
<p translate='{{ controller.bodyControllerText }}'></p>
<div ng-view=''></div>

<div class='footer'>
<hr />
<p><span class='glyphicon glyphicon-heart'></span> from the Yeoman team</p>
</div>
</div>

<!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-X');
ga('send', 'pageview');
</script>
ga('create', 'UA-XXXXX-X');
ga('send', 'pageview');
</script>

<!-- build:js(.) scripts/oldieshim.js -->
<!-- build:js(.) scripts/oldieshim.js -->
<!--[if lt IE 9]>
<script src="bower_components/es5-shim/es5-shim.js"></script>
<script src="bower_components/json3/lib/json3.js"></script>
Expand Down
5 changes: 4 additions & 1 deletion app/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require.config({
angular: '../../bower_components/angular/angular',
'angular-route': '../../bower_components/angular-route/angular-route',
'angular-translate': '../../bower_components/angular-translate/angular-translate',
'angular-mocks': '../../bower_components/angular-mocks/angular-mocks',
button: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/button',
bootstrap: '../../bower_components/bootstrap/dist/js/bootstrap',
carousel: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/carousel',
Expand All @@ -23,7 +24,9 @@ require.config({
scrollspy: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/scrollspy',
tab: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab',
tooltip: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tooltip',
transition: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition'
transition: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition',
'font-awesome': '../../bower_components/font-awesome',
'bootstrap-sass-official': '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap'
},
shim: {
angular: {
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/controllers/BodyController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

define(['paw'], function(paw) {
paw.controller('BodyController', function($scope) {
define(['paw', 'directives/navbar'], function(paw) {
paw.controller('BodyController', ['$scope', function($scope) {
this.bodyControllerText = 'bodyControllerText';
});
}]);
});
18 changes: 18 additions & 0 deletions app/scripts/directives/navbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

define(['paw'], function(paw) {
paw.controller('NavbarController', ['$scope', function NavbarController($scope) {
this.user = {
'fullName': 'Matías Nicolás Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas',
'profileUrl': '/users/1'
};
}])
.directive('xnavbar', function() {
return {
restrict: 'E',
templateUrl: '/views/navbar.html',
controller: 'NavbarController',
controllerAs: 'controller'
};
});
});
6 changes: 5 additions & 1 deletion app/scripts/i18n/translations.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
define([], function() {
return {
WELCOME_MESSAGE: 'Un placer ayudarte a construir el comienzo de tu app',
bodyControllerText: 'Texto del BodyController'
bodyControllerText: 'Texto del BodyController',
i18nProfile: 'Mi perfil',
i18nLogout: 'Cerrar sesión',
i18nWebAbbreviation: 'SGA',
i18nWebName: 'Sistema de Gestión Académica'
};
});
1 change: 1 addition & 0 deletions app/scripts/paw.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ define(['routes',

$translateProvider.translations('preferredLanguage', i18n);
$translateProvider.preferredLanguage('preferredLanguage');
$translateProvider.useSanitizeValueStrategy('escape');
}]);
return paw;
}
Expand Down
56 changes: 56 additions & 0 deletions app/specs/directives/navbar.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

define(['paw', 'angular-mocks', 'directives/navbar', 'navbar-template'], function() {
beforeEach(module('paw'));

describe('NavbarController', function() {
var $controller;

beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));

describe('controller.user', function() {
var $scope, controller;
// for now, hardcoded data (when API integration is ready ==> replace this)
var user = {
'fullName': 'Matías Nicolás Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas',
'profileUrl': '/users/1'
};

beforeEach(function() {
$scope = {};
controller = $controller('NavbarController', {$scope: $scope});
});

it('correctly sets the user', function() {
expect(controller.user).toEqual(user);
});
});
});

describe('NavbarDirective', function() {
beforeEach(module('directive-templates'));

var $compile, $rootScope, element, scope;

beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));

beforeEach(function() {
element = angular.element('<xnavbar></xnavbar>');
$compile(element)($rootScope);
$rootScope.$digest();
});

it('contains the navbar brand', function() {
expect(element.find('.navbar-brand')[0]).toBeDefined();
});

it('is defined', function() {
expect(element.find('.top-nav')[0]).toBeDefined();
});
});
});
107 changes: 107 additions & 0 deletions app/specs/test-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
'use strict';

var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;

// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function (file) {
if (TEST_REGEXP.test(file)) {
allTestFiles.push(file);
}
});

require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base/app/scripts',

// this is from where requirejs will search dependencies, prepending the baseUrl to
// the specified files
paths: {
'paw': 'paw',
'routes': 'routes',
'services/dependencyResolverFor': 'services/dependencyResolverFor',
'i18n/i18nLoader': 'i18n/i18nLoader',
'i18n/translations.es': 'i18n/translations.es',
affix: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/affix',
alert: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/alert',
angular: '../../bower_components/angular/angular',
'angular-route': '../../bower_components/angular-route/angular-route',
'angular-translate': '../../bower_components/angular-translate/angular-translate',
'angular-mocks': '../../bower_components/angular-mocks/angular-mocks',
button: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/button',
bootstrap: '../../bower_components/bootstrap/dist/js/bootstrap',
carousel: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/carousel',
collapse: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/collapse',
dropdown: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/dropdown',
'es5-shim': '../../bower_components/es5-shim/es5-shim',
jquery: '../../bower_components/jquery/dist/jquery',
json3: '../../bower_components/json3/lib/json3',
modal: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/modal',
moment: '../../bower_components/moment/moment',
popover: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/popover',
requirejs: '../../bower_components/requirejs/require',
scrollspy: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/scrollspy',
tab: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab',
tooltip: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tooltip',
transition: '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition',
'font-awesome': '../../bower_components/font-awesome',
'bootstrap-sass-official': '../../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap',
'navbar-template': '../views/navbar.html'
},
shim: {
angular: {
deps: [
'jquery'
]
},
'angular-route': {
deps: [
'angular'
]
},
'angular-mocks': {
deps: [
'angular'
]
},
bootstrap: {
deps: [
'jquery',
'modal'
]
},
modal: {
deps: [
'jquery'
]
},
tooltip: {
deps: [
'jquery'
]
},
'angular-translate': {
deps: [
'angular'
]
},
// all directives templates should be declared as follows
'navbar-template': {
deps: [
'angular'
]
}
},
packages: [

],

// dynamically load all test files
deps: allTestFiles,

// we have to kickoff jasmine, as it is asynchronous
callback: function() {
console.log('load complete');
window.__karma__.start();
}
});
Loading

0 comments on commit a0947b2

Please sign in to comment.