From 9d0b43b64a0f9176499a437f8f793441fbaf3231 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Fri, 28 Mar 2014 18:19:47 -0400 Subject: [PATCH] refact(*): refactor app layout to conform to best practices --- app/{css => }/app.css | 0 app/app.js | 12 +++++++++++ .../version/version-directive.js} | 5 +---- .../version/version-directive_test.js | 6 ++---- .../version/version-filter.js} | 4 +--- .../components/version/version-filter_test.js | 8 ++------ app/components/version/version.js | 4 ++++ .../components/version/version_test.js | 7 ++----- app/css/.gitkeep | 0 app/img/.gitkeep | 0 app/index.html | 11 +++++----- app/js/app.js | 16 --------------- app/js/controllers.js | 11 ---------- app/js/services.js | 9 --------- app/partials/.gitkeep | 0 .../partial1.html => view1/view1.html} | 0 app/view1/view1.js | 12 +++++++++++ app/view1/view1_test.js | 12 +++++++++++ .../partial2.html => view2/view2.html} | 0 app/view2/view2.js | 12 +++++++++++ app/view2/view2_test.js | 11 ++++++++++ test/karma.conf.js | 1 + test/unit/controllersSpec.js | 20 ------------------- 23 files changed, 78 insertions(+), 83 deletions(-) rename app/{css => }/app.css (100%) create mode 100644 app/app.js rename app/{js/directives.js => components/version/version-directive.js} (72%) rename test/unit/directivesSpec.js => app/components/version/version-directive_test.js (76%) rename app/{js/filters.js => components/version/version-filter.js} (76%) rename test/unit/filtersSpec.js => app/components/version/version-filter_test.js (74%) create mode 100644 app/components/version/version.js rename test/unit/servicesSpec.js => app/components/version/version_test.js (60%) delete mode 100644 app/css/.gitkeep delete mode 100644 app/img/.gitkeep delete mode 100644 app/js/app.js delete mode 100644 app/js/controllers.js delete mode 100644 app/js/services.js delete mode 100644 app/partials/.gitkeep rename app/{partials/partial1.html => view1/view1.html} (100%) create mode 100644 app/view1/view1.js create mode 100644 app/view1/view1_test.js rename app/{partials/partial2.html => view2/view2.html} (100%) create mode 100644 app/view2/view2.js create mode 100644 app/view2/view2_test.js delete mode 100644 test/unit/controllersSpec.js diff --git a/app/css/app.css b/app/app.css similarity index 100% rename from app/css/app.css rename to app/app.css diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000000..21eccdb8ea --- /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/js/directives.js b/app/components/version/version-directive.js similarity index 72% rename from app/js/directives.js rename to app/components/version/version-directive.js index 9fc16cc4cb..62b8f76ac9 100644 --- a/app/js/directives.js +++ b/app/components/version/version-directive.js @@ -1,9 +1,6 @@ 'use strict'; -/* Directives */ - - -angular.module('myApp.directives', []). +angular.module('myApp.version'). directive('appVersion', ['version', function(version) { return function(scope, elm, attrs) { elm.text(version); diff --git a/test/unit/directivesSpec.js b/app/components/version/version-directive_test.js similarity index 76% rename from test/unit/directivesSpec.js rename to app/components/version/version-directive_test.js index 6061842969..b38fbba5d2 100644 --- a/test/unit/directivesSpec.js +++ b/app/components/version/version-directive_test.js @@ -1,9 +1,7 @@ 'use strict'; -/* jasmine specs for directives go here */ - -describe('directives', function() { - beforeEach(module('myApp.directives')); +describe('version directives', function() { + beforeEach(module('myApp.version')); describe('app-version', function() { it('should print current version', function() { diff --git a/app/js/filters.js b/app/components/version/version-filter.js similarity index 76% rename from app/js/filters.js rename to app/components/version/version-filter.js index 901730e63b..71c8bbcba2 100644 --- a/app/js/filters.js +++ b/app/components/version/version-filter.js @@ -1,8 +1,6 @@ 'use strict'; -/* Filters */ - -angular.module('myApp.filters', []). +angular.module('myApp.version'). filter('interpolate', ['version', function(version) { return function(text) { return String(text).replace(/\%VERSION\%/mg, version); diff --git a/test/unit/filtersSpec.js b/app/components/version/version-filter_test.js similarity index 74% rename from test/unit/filtersSpec.js rename to app/components/version/version-filter_test.js index 19af3293a1..e25bd880df 100644 --- a/test/unit/filtersSpec.js +++ b/app/components/version/version-filter_test.js @@ -1,17 +1,13 @@ 'use strict'; -/* jasmine specs for filters go here */ - -describe('filter', function() { - beforeEach(module('myApp.filters')); - +describe('version filter', function() { + beforeEach(module('myApp.version')); describe('interpolate', 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.js b/app/components/version/version.js new file mode 100644 index 0000000000..ecca360566 --- /dev/null +++ b/app/components/version/version.js @@ -0,0 +1,4 @@ +'use strict'; + +angular.module('myApp.version', []). + value('version', '0.1'); diff --git a/test/unit/servicesSpec.js b/app/components/version/version_test.js similarity index 60% rename from test/unit/servicesSpec.js rename to app/components/version/version_test.js index 3864c8d9bb..c6d99e3a7e 100644 --- a/test/unit/servicesSpec.js +++ b/app/components/version/version_test.js @@ -1,10 +1,7 @@ 'use strict'; -/* jasmine specs for services go here */ - -describe('service', function() { - beforeEach(module('myApp.services')); - +describe('version service', function() { + beforeEach(module('myApp.version')); describe('version', function() { it('should return current version', inject(function(version) { diff --git a/app/css/.gitkeep b/app/css/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/img/.gitkeep b/app/img/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/index.html b/app/index.html index ae7e943cd9..7eb1d6e804 100644 --- a/app/index.html +++ b/app/index.html @@ -33,10 +33,11 @@ --> - - - - - + + + + + + diff --git a/app/js/app.js b/app/js/app.js deleted file mode 100644 index d990ec7c9d..0000000000 --- a/app/js/app.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - - -// Declare app level module which depends on filters, and services -angular.module('myApp', [ - 'ngRoute', - 'myApp.filters', - 'myApp.services', - 'myApp.directives', - 'myApp.controllers' -]). -config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'}); - $routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'}); - $routeProvider.otherwise({redirectTo: '/view1'}); -}]); diff --git a/app/js/controllers.js b/app/js/controllers.js deleted file mode 100644 index 6ec39e1235..0000000000 --- a/app/js/controllers.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -/* Controllers */ - -angular.module('myApp.controllers', []) - .controller('MyCtrl1', ['$scope', function($scope) { - - }]) - .controller('MyCtrl2', ['$scope', function($scope) { - - }]); diff --git a/app/js/services.js b/app/js/services.js deleted file mode 100644 index 334d543f13..0000000000 --- a/app/js/services.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -/* Services */ - - -// Demonstrate how to register services -// In this case it is a simple value service. -angular.module('myApp.services', []). - value('version', '0.1'); diff --git a/app/partials/.gitkeep b/app/partials/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/partials/partial1.html b/app/view1/view1.html similarity index 100% rename from app/partials/partial1.html rename to app/view1/view1.html diff --git a/app/view1/view1.js b/app/view1/view1.js new file mode 100644 index 0000000000..6c264318dd --- /dev/null +++ b/app/view1/view1.js @@ -0,0 +1,12 @@ +'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 0000000000..800a54b3ef --- /dev/null +++ b/app/view1/view1_test.js @@ -0,0 +1,12 @@ +'use strict'; + +describe('view1 controller', function(){ + beforeEach(module('myApp.view1')); + + it('should ....', inject(function($controller) { + //spec body + var view1Ctrl = $controller('View1Ctrl'); + expect(view1Ctrl).toBeDefined(); + })); + +}); diff --git a/app/partials/partial2.html b/app/view2/view2.html similarity index 100% rename from app/partials/partial2.html rename to app/view2/view2.html diff --git a/app/view2/view2.js b/app/view2/view2.js new file mode 100644 index 0000000000..6fc374b73f --- /dev/null +++ b/app/view2/view2.js @@ -0,0 +1,12 @@ +'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 0000000000..2c3771ca6b --- /dev/null +++ b/app/view2/view2_test.js @@ -0,0 +1,11 @@ +'use strict'; + +describe('controllers', function(){ + beforeEach(module('myApp.view2')); + + it('should ....', inject(function($controller) { + //spec body + var view2Ctrl = $controller('View2Ctrl'); + expect(view2Ctrl).toBeDefined(); + })); +}); diff --git a/test/karma.conf.js b/test/karma.conf.js index 1aee850a6c..9adb703685 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -8,6 +8,7 @@ module.exports = function(config){ 'app/bower_components/angular-route/angular-route.js', 'app/bower_components/angular-mocks/angular-mocks.js', 'app/js/**/*.js', + 'app/components/version/version.js', 'test/unit/**/*.js' ], diff --git a/test/unit/controllersSpec.js b/test/unit/controllersSpec.js deleted file mode 100644 index 819bf99de3..0000000000 --- a/test/unit/controllersSpec.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -/* jasmine specs for controllers go here */ - -describe('controllers', function(){ - beforeEach(module('myApp.controllers')); - - - it('should ....', inject(function($controller) { - //spec body - var myCtrl1 = $controller('MyCtrl1', { $scope: {} }); - expect(myCtrl1).toBeDefined(); - })); - - it('should ....', inject(function($controller) { - //spec body - var myCtrl2 = $controller('MyCtrl2', { $scope: {} }); - expect(myCtrl2).toBeDefined(); - })); -});