From 6172661b1b5dbdbb86520ac01e95d53e76bf4380 Mon Sep 17 00:00:00 2001 From: Thibault Cohen Date: Tue, 16 Dec 2014 17:05:07 -0500 Subject: [PATCH] First commit based on angular-seed --- .bowerrc | 3 + .gitignore | 8 +++ .jshintrc | 13 +++++ .travis.yml | 14 +++++ LICENSE | 22 +++++++ app/app.css | 30 ++++++++++ app/app.js | 12 ++++ app/components/version/interpolate-filter.js | 9 +++ .../version/interpolate-filter_test.js | 15 +++++ app/components/version/version-directive.js | 9 +++ .../version/version-directive_test.js | 17 ++++++ app/components/version/version.js | 8 +++ app/components/version/version_test.js | 11 ++++ app/index-async.html | 58 +++++++++++++++++++ app/index.html | 43 ++++++++++++++ app/view1/view1.html | 1 + app/view1/view1.js | 14 +++++ app/view1/view1_test.js | 16 +++++ app/view2/view2.html | 5 ++ app/view2/view2.js | 14 +++++ app/view2/view2_test.js | 16 +++++ bower.json | 16 +++++ e2e-tests/protractor.conf.js | 19 ++++++ e2e-tests/scenarios.js | 42 ++++++++++++++ karma.conf.js | 33 +++++++++++ package.json | 34 +++++++++++ 26 files changed, 482 insertions(+) create mode 100644 .bowerrc create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 app/app.css create mode 100644 app/app.js create mode 100644 app/components/version/interpolate-filter.js create mode 100644 app/components/version/interpolate-filter_test.js create mode 100644 app/components/version/version-directive.js create mode 100644 app/components/version/version-directive_test.js create mode 100644 app/components/version/version.js create mode 100644 app/components/version/version_test.js create mode 100644 app/index-async.html create mode 100644 app/index.html create mode 100644 app/view1/view1.html create mode 100644 app/view1/view1.js create mode 100644 app/view1/view1_test.js create mode 100644 app/view2/view2.html create mode 100644 app/view2/view2.js create mode 100644 app/view2/view2_test.js create mode 100644 bower.json create mode 100644 e2e-tests/protractor.conf.js create mode 100644 e2e-tests/scenarios.js create mode 100644 karma.conf.js create mode 100644 package.json diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000..8c58c8e --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "app/bower_components" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a32ba5f --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +logs/* +!.gitkeep +node_modules/ +bower_components/ +tmp +.DS_Store +.idea +*.swp diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..6f00218 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,13 @@ +{ + "globalstrict": true, + "globals": { + "angular": false, + "describe": false, + "it": false, + "expect": false, + "beforeEach": false, + "afterEach": false, + "module": false, + "inject": false + } +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cce5c68 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js +node_js: + - "0.10" + +before_script: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start + - npm start > /dev/null & + - npm run update-webdriver + - sleep 1 # give server time to start + +script: + - node_modules/.bin/karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox + - node_modules/.bin/protractor e2e-tests/protractor.conf.js --browser=firefox diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9ced331 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License + +Copyright (c) 2010-2014 Google, Inc. http://angularjs.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/app/app.css b/app/app.css new file mode 100644 index 0000000..c925240 --- /dev/null +++ b/app/app.css @@ -0,0 +1,30 @@ +/* app css stylesheet */ + +.menu { + list-style: none; + border-bottom: 0.1em solid black; + margin-bottom: 2em; + padding: 0 0 0.5em; +} + +.menu:before { + content: "["; +} + +.menu:after { + content: "]"; +} + +.menu > li { + display: inline; +} + +.menu > li:before { + content: "|"; + padding-right: 0.3em; +} + +.menu > li:nth-child(1):before { + content: ""; + padding: 0; +} diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000..21eccdb --- /dev/null +++ b/app/app.js @@ -0,0 +1,12 @@ +'use strict'; + +// Declare app level module which depends on views, and components +angular.module('myApp', [ + 'ngRoute', + 'myApp.view1', + 'myApp.view2', + 'myApp.version' +]). +config(['$routeProvider', function($routeProvider) { + $routeProvider.otherwise({redirectTo: '/view1'}); +}]); diff --git a/app/components/version/interpolate-filter.js b/app/components/version/interpolate-filter.js new file mode 100644 index 0000000..03bb198 --- /dev/null +++ b/app/components/version/interpolate-filter.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('myApp.version.interpolate-filter', []) + +.filter('interpolate', ['version', function(version) { + return function(text) { + return String(text).replace(/\%VERSION\%/mg, version); + }; +}]); diff --git a/app/components/version/interpolate-filter_test.js b/app/components/version/interpolate-filter_test.js new file mode 100644 index 0000000..ff56c52 --- /dev/null +++ b/app/components/version/interpolate-filter_test.js @@ -0,0 +1,15 @@ +'use strict'; + +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); + + describe('interpolate filter', function() { + beforeEach(module(function($provide) { + $provide.value('version', 'TEST_VER'); + })); + + it('should replace VERSION', inject(function(interpolateFilter) { + expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after'); + })); + }); +}); diff --git a/app/components/version/version-directive.js b/app/components/version/version-directive.js new file mode 100644 index 0000000..74088f8 --- /dev/null +++ b/app/components/version/version-directive.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('myApp.version.version-directive', []) + +.directive('appVersion', ['version', function(version) { + return function(scope, elm, attrs) { + elm.text(version); + }; +}]); diff --git a/app/components/version/version-directive_test.js b/app/components/version/version-directive_test.js new file mode 100644 index 0000000..4a59e11 --- /dev/null +++ b/app/components/version/version-directive_test.js @@ -0,0 +1,17 @@ +'use strict'; + +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); + + describe('app-version directive', function() { + it('should print current version', function() { + module(function($provide) { + $provide.value('version', 'TEST_VER'); + }); + inject(function($compile, $rootScope) { + var element = $compile('')($rootScope); + expect(element.text()).toEqual('TEST_VER'); + }); + }); + }); +}); diff --git a/app/components/version/version.js b/app/components/version/version.js new file mode 100644 index 0000000..cb7a10f --- /dev/null +++ b/app/components/version/version.js @@ -0,0 +1,8 @@ +'use strict'; + +angular.module('myApp.version', [ + 'myApp.version.interpolate-filter', + 'myApp.version.version-directive' +]) + +.value('version', '0.1'); diff --git a/app/components/version/version_test.js b/app/components/version/version_test.js new file mode 100644 index 0000000..4ca6880 --- /dev/null +++ b/app/components/version/version_test.js @@ -0,0 +1,11 @@ +'use strict'; + +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); + + describe('version service', function() { + it('should return current version', inject(function(version) { + expect(version).toEqual('0.1'); + })); + }); +}); diff --git a/app/index-async.html b/app/index-async.html new file mode 100644 index 0000000..a559b71 --- /dev/null +++ b/app/index-async.html @@ -0,0 +1,58 @@ + + + + + + + + + + My AngularJS App + + + + + +
+ +
Angular seed app: v
+ + + diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..d0aacaa --- /dev/null +++ b/app/index.html @@ -0,0 +1,43 @@ + + + + + + + + + My AngularJS App + + + + + + + + + + + + +
+ +
Angular seed app: v
+ + + + + + + + + + + + diff --git a/app/view1/view1.html b/app/view1/view1.html new file mode 100644 index 0000000..89459a6 --- /dev/null +++ b/app/view1/view1.html @@ -0,0 +1 @@ +

This is the partial for view 1.

diff --git a/app/view1/view1.js b/app/view1/view1.js new file mode 100644 index 0000000..4ce0b4f --- /dev/null +++ b/app/view1/view1.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('myApp.view1', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/view1', { + templateUrl: 'view1/view1.html', + controller: 'View1Ctrl' + }); +}]) + +.controller('View1Ctrl', [function() { + +}]); \ No newline at end of file diff --git a/app/view1/view1_test.js b/app/view1/view1_test.js new file mode 100644 index 0000000..14ba79b --- /dev/null +++ b/app/view1/view1_test.js @@ -0,0 +1,16 @@ +'use strict'; + +describe('myApp.view1 module', function() { + + beforeEach(module('myApp.view1')); + + describe('view1 controller', function(){ + + it('should ....', inject(function($controller) { + //spec body + var view1Ctrl = $controller('View1Ctrl'); + expect(view1Ctrl).toBeDefined(); + })); + + }); +}); \ No newline at end of file diff --git a/app/view2/view2.html b/app/view2/view2.html new file mode 100644 index 0000000..b6503ee --- /dev/null +++ b/app/view2/view2.html @@ -0,0 +1,5 @@ +

This is the partial for view 2.

+

+ Showing of 'interpolate' filter: + {{ 'Current version is v%VERSION%.' | interpolate }} +

diff --git a/app/view2/view2.js b/app/view2/view2.js new file mode 100644 index 0000000..a0ff97d --- /dev/null +++ b/app/view2/view2.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('myApp.view2', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/view2', { + templateUrl: 'view2/view2.html', + controller: 'View2Ctrl' + }); +}]) + +.controller('View2Ctrl', [function() { + +}]); \ No newline at end of file diff --git a/app/view2/view2_test.js b/app/view2/view2_test.js new file mode 100644 index 0000000..07b34d6 --- /dev/null +++ b/app/view2/view2_test.js @@ -0,0 +1,16 @@ +'use strict'; + +describe('myApp.view2 module', function() { + + beforeEach(module('myApp.view2')); + + describe('view2 controller', function(){ + + it('should ....', inject(function($controller) { + //spec body + var view2Ctrl = $controller('View2Ctrl'); + expect(view2Ctrl).toBeDefined(); + })); + + }); +}); \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..b0bec06 --- /dev/null +++ b/bower.json @@ -0,0 +1,16 @@ +{ + "name": "adagios", + "description": "Adagios front-end", + "version": "0.1.0", + "homepage": "https://github.com/titilambert/adagios-frontend", + "license": "AGPLv3", + "private": true, + "dependencies": { + "angular": "1.2.x", + "angular-route": "1.2.x", + "angular-loader": "1.2.x", + "angular-mocks": "~1.2.x", + "html5-boilerplate": "~4.3.0", + "bootstrap": "3.3.1" + } +} diff --git a/e2e-tests/protractor.conf.js b/e2e-tests/protractor.conf.js new file mode 100644 index 0000000..b45a117 --- /dev/null +++ b/e2e-tests/protractor.conf.js @@ -0,0 +1,19 @@ +exports.config = { + allScriptsTimeout: 11000, + + specs: [ + '*.js' + ], + + capabilities: { + 'browserName': 'chrome' + }, + + baseUrl: 'http://localhost:8000/app/', + + framework: 'jasmine', + + jasmineNodeOpts: { + defaultTimeoutInterval: 30000 + } +}; diff --git a/e2e-tests/scenarios.js b/e2e-tests/scenarios.js new file mode 100644 index 0000000..e66d140 --- /dev/null +++ b/e2e-tests/scenarios.js @@ -0,0 +1,42 @@ +'use strict'; + +/* https://github.com/angular/protractor/blob/master/docs/toc.md */ + +describe('my app', function() { + + browser.get('index.html'); + + it('should automatically redirect to /view1 when location hash/fragment is empty', function() { + expect(browser.getLocationAbsUrl()).toMatch("/view1"); + }); + + + describe('view1', function() { + + beforeEach(function() { + browser.get('index.html#/view1'); + }); + + + it('should render view1 when user navigates to /view1', function() { + expect(element.all(by.css('[ng-view] p')).first().getText()). + toMatch(/partial for view 1/); + }); + + }); + + + describe('view2', function() { + + beforeEach(function() { + browser.get('index.html#/view2'); + }); + + + it('should render view2 when user navigates to /view2', function() { + expect(element.all(by.css('[ng-view] p')).first().getText()). + toMatch(/partial for view 2/); + }); + + }); +}); diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..44bb29f --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,33 @@ +module.exports = function(config){ + config.set({ + + basePath : './', + + files : [ + 'app/bower_components/angular/angular.js', + 'app/bower_components/angular-route/angular-route.js', + 'app/bower_components/angular-mocks/angular-mocks.js', + 'app/components/**/*.js', + 'app/view*/**/*.js' + ], + + autoWatch : true, + + frameworks: ['jasmine'], + + browsers : ['Chrome'], + + plugins : [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-jasmine', + 'karma-junit-reporter' + ], + + junitReporter : { + outputFile: 'test_out/unit.xml', + suite: 'unit' + } + + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..73cd4e1 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "adagios", + "private": true, + "version": "0.1.0", + "description": "Adagios front-end", + "repository": "https://github.com/titilambert/adagios-frontend", + "license": "AGPLv3", + "devDependencies": { + "karma": "~0.10", + "protractor": "^1.1.1", + "http-server": "^0.6.1", + "bower": "^1.3.1", + "shelljs": "^0.2.6", + "karma-junit-reporter": "^0.2.2" + }, + "scripts": { + "postinstall": "bower install", + + "prestart": "npm install", + "start": "http-server -a localhost -p 8000 -c-1", + + "pretest": "npm install", + "test": "karma start karma.conf.js", + "test-single-run": "karma start karma.conf.js --single-run", + + "preupdate-webdriver": "npm install", + "update-webdriver": "webdriver-manager update", + + "preprotractor": "npm run update-webdriver", + "protractor": "protractor e2e-tests/protractor.conf.js", + + "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\"" + } +}