diff --git a/.gitignore b/.gitignore index 7d92a06..4893c28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ node_modules dist coverage -public +/public build .tmp diff --git a/.npmignore b/.npmignore index 7aaf89f..5666388 100644 --- a/.npmignore +++ b/.npmignore @@ -2,7 +2,6 @@ node_modules public build -node_modules .tmp .sass-cache .idea diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..9d3aa3d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1 @@ +Pavel Zinovev diff --git a/karma.conf.js b/karma.conf.js index d921cb9..d19d9ae 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,42 +1,60 @@ -// Reference: http://karma-runner.github.io/0.12/config/configuration-file.html +/** Reference: http://karma-runner.github.io/0.12/config/configuration-file.html */ module.exports = function karmaConfig (config) { config.set({ + logLevel: config.LOG_INFO, /** Log our errors */ + + client: { + captureConsole: true + }, + frameworks: [ - // Reference: https://github.com/karma-runner/karma-jasmine - // Set framework to jasmine + + /** + * Reference: https://github.com/karma-runner/karma-jasmine + * Set framework to jasmine + */ 'jasmine' ], reporters: [ - // Reference: https://github.com/mlex/karma-spec-reporter - // Set reporter to print detailed results to console + + /** + * Reference: https://github.com/mlex/karma-spec-reporter + * Set reporter to print detailed results to console + */ 'progress', - // Reference: https://github.com/karma-runner/karma-coverage - // Output code coverage files + /** + * Reference: https://github.com/karma-runner/karma-coverage + * Output code coverage files + */ 'coverage' ], files: [ - // Grab all files in the app folder that contain .spec. - 'src/tests.webpack.js' + /** Grab all files in the app folder that contain .spec. */ + './src/specs.webpack.js' + /** each file acts as entry point for the webpack configuration */ ], preprocessors: { - // Reference: http://webpack.github.io/docs/testing.html - // Reference: https://github.com/webpack/karma-webpack - // Convert files with webpack and load sourcemaps - 'src/tests.webpack.js': ['webpack', 'sourcemap'] + + /** + * Reference: http://webpack.github.io/docs/testing.html + * Reference: https://github.com/webpack/karma-webpack + * Convert files with webpack and load sourcemaps + */ + './src/specs.webpack.js': ['webpack', 'sourcemap'] }, browsers: [ - // Run tests using PhantomJS2 + /** Run tests using PhantomJS2 */ 'PhantomJS2' ], singleRun: true, - // Configure code coverage reporter + /** Configure code coverage reporter */ coverageReporter: { dir: 'coverage/', reporters: [ @@ -47,7 +65,7 @@ module.exports = function karmaConfig (config) { webpack: require('./webpack.config'), - // Hide webpack build information from output + /** Hide webpack build information from output */ webpackMiddleware: { noInfo: 'errors-only' } diff --git a/package.json b/package.json index 5ed6561..b356050 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "angular-webpack-starter-kit", - "version": "5.0.5", - "description": "An Angular Webpack Starter kit featuring Angular 1.x (ngRoute, Tests, E2E, Dev/Prod), Karma, Protractor, Jasmine, Babel, Postcss, Jade, livereload and Webpack", + "version": "5.1.1", + "description": "An Angular Webpack Starter kit featuring Angular 1.x (ui-router, Tests, E2E, Dev/Prod), Karma, Protractor, Jasmine, Istanbul, Babel, Postcss, Jade, livereload and Webpack", "keywords": [ "angular", "webpack", @@ -12,6 +12,7 @@ "karma", "protractor", "jasmine", + "Istanbul", "workflow", "e2e", "starter", @@ -19,7 +20,7 @@ "starter kit" ], "scripts": { - "build": "rimraf dist && webpack --bail --progress --profile", + "build": "rimraf dist && webpack --bail --progress --profile && cp -r ./src/content/ ./dist/", "server": "webpack-dev-server --history-api-fallback --inline --progress", "test": "karma start", "test-watch": "karma start --auto-watch --no-single-run", @@ -42,6 +43,7 @@ "dependencies": { "angular": "^1.5.0", "angular-ui-router": "^0.2.18", + "angular-ui-router.statehelper": "^1.3.1", "fastclick": "^1.0.6" }, "devDependencies": { diff --git a/protractor.conf.js b/protractor.conf.js index f28daf5..8c177fa 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -1,9 +1,8 @@ exports.config = { baseUrl: 'http://localhost:8080/', - // use `npm run e2e` + /** use `npm run e2e` */ specs: [ - './src/**/**.e2e.js', './src/**/*.e2e.js' ], exclude: [], diff --git a/src/Application.e2e.js b/src/Application.e2e.js index 08aa17a..4426812 100644 --- a/src/Application.e2e.js +++ b/src/Application.e2e.js @@ -1,9 +1,14 @@ +/* Copyright (C) Simply.info + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Pavel Zinovev , February 2016 + */ + describe('Application', () => { beforeEach(() => { browser.get('/'); }); - it('should have a title', () => { expect(browser.getTitle()).toEqual('Title'); }); @@ -16,5 +21,19 @@ describe('Application', () => { expect(element(by.css('.wrapper')).isPresent()).toEqual(true); }); + it('should have content', () => { + expect(element(by.css('.page-content')).isPresent()).toEqual(true); + }); + + it('should get the current state', function (){ + const currentStateName = browser.executeAsyncScript((callback) => { + const el = document.querySelector('html'); + const injector = angular.element(el).injector(); + const service = injector.get('$state'); + + callback(service.current.name); + }); + expect(currentStateName).toEqual('home'); + }); }); diff --git a/src/Application.js b/src/Application.js index dbe61d2..d744b1c 100644 --- a/src/Application.js +++ b/src/Application.js @@ -1,18 +1,21 @@ -import angular from 'angular'; -import uiRouter from 'angular-ui-router'; +import angular from 'angular'; +import uiRouter from 'angular-ui-router'; +import uiRouterStateHelper from 'angular-ui-router.statehelper'; -import Config from './Config'; -import layoutView from './modules/Layout/views/layout.jade'; +import Config from './Config'; +import Runners from './Runners'; +import AppView from './modules/Application/views/layout.jade'; -import Layout from './modules/Layout/Index'; -import Home from './modules/Home/Index'; +import Controllers from './modules/Application/Controllers'; +const appname = 'Workflow'; /** App and root module name */ +const deps = [uiRouter, 'ui.router.stateHelper']; /** All global dependencies */ +const modules = [Controllers]; /** All app dependencies */ -const appname = 'Workflow'; -const deps = [uiRouter]; -const modules = [Layout, Home]; +document.getElementById('app-container').innerHTML = AppView(); /** Store our app. (Getting html from jade) */ +angular.module(appname, deps.concat(modules)).config(Config).run(Runners); /** Declare root module */ +angular.bootstrap(document, [appname]); /** Bootstrap our application. Поехали! */ -document.getElementById('app-container').innerHTML = layoutView(); -angular.module(appname, deps.concat(modules)).config(Config); -angular.bootstrap(document, [appname]); +/** Export appname. Just in case. */ +export default appname; diff --git a/src/Config.js b/src/Config.js index b1eab22..d8c402d 100644 --- a/src/Config.js +++ b/src/Config.js @@ -1,14 +1,42 @@ -const Config = ($stateProvider, $urlRouterProvider, $locationProvider) => { /*@ngInject*/ - $locationProvider.html5Mode(true); +/* Copyright (C) Simply.info + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Pavel Zinovev , March 2016 + */ - $urlRouterProvider.otherwise('/'); +/** + * @module Config + * @see Application + * @param {Object} stateHelperProvider - Ui-router module for right nesting. + * @param {Object} $urlRouterProvider - Configures how the application routing. + * @param {Object} $locationProvider - Configures how the application deep linking paths are stored. + * @param {Object} $logProvider - Configures how the application logs messages. + */ +const Config = (stateHelperProvider, $urlRouterProvider, $locationProvider, $logProvider) => { + /*@ngInject*/ - $stateProvider - .state('home', { - url: '/', - template: require('./modules/Home/views/home.jade')(), - controller: 'HomeController' + $logProvider.debugEnabled(true); /** Turn debug mode on/off */ + $locationProvider.html5Mode(true); /** Turn html5 mode on */ + $urlRouterProvider.otherwise('/home'); /** If current route not in routes then redirect to home */ + + /** + * Url processing. + * @param {Object} $injector - Ability to inject providers. + * @param {Object} $location - Current location. + */ + $urlRouterProvider.rule(($injector, $location) => { + const path = $location.path(); + $location.path(path[path.length - 1] === '/' ? path.slice(0, -1) : path); /** If route like as /home/ then /home */ + }); + + stateHelperProvider /** Describe our states */ + .state({ + url: '/', + name: 'home', + controller: 'HomeController', + template: require('./modules/Home/views/home.jade')() }); }; +/** Export our config */ export default Config; diff --git a/src/Runners.js b/src/Runners.js new file mode 100644 index 0000000..b38d75d --- /dev/null +++ b/src/Runners.js @@ -0,0 +1,30 @@ +/* Copyright (C) Simply.info + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Pavel Zinovev , March 2016 + */ + +/** + * Adding redirectTo from config ability. + * @module Runners + * @see Application + * @param {Object} $rootScope - Global application model. + * @param {Object} $state - Provides interfaces to current state. + */ +const Runners = ($rootScope, $state) => { /*@ngInject*/ + + /** + * Waiting route change start event. + * @param {Object} event. + * @param {Object} to - Next state. + */ + $rootScope.$on('$stateChangeStart', (event, to) => { + if (to.redirectTo) { + event.preventDefault(); + $state.go(to.redirectTo); + } + }); +}; + +/** Export our runners */ +export default Runners; diff --git a/src/modules/Application/Controllers.js b/src/modules/Application/Controllers.js new file mode 100644 index 0000000..9ef1b87 --- /dev/null +++ b/src/modules/Application/Controllers.js @@ -0,0 +1,24 @@ +/* Copyright (C) Simply.info + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Pavel Zinovev , March 2016 + */ + +/* + * Javascripts + * ========================================================================== */ + +import angular from 'angular'; + +import Layout from './Index'; +import Home from '../Home/Index'; + +/** + * Define app module. + * @param {String} moduleName. + * @param {Array} dependencies. + * @export Controllers module + */ +export default angular.module('Simply.App.controllers', [ + Layout, Home +]).name; diff --git a/src/modules/Layout/Index.js b/src/modules/Application/Index.js similarity index 50% rename from src/modules/Layout/Index.js rename to src/modules/Application/Index.js index 292237d..be4419d 100644 --- a/src/modules/Layout/Index.js +++ b/src/modules/Application/Index.js @@ -2,9 +2,11 @@ * Javascripts * ========================================================================== */ -import angular from 'angular'; -import LayoutController from './controller/LayoutCtrl'; -import PointerEvents from './directives/PointerEvents/PointerEventsDirective'; +import angular from 'angular'; +import AppController from './controller/AppCtrl'; + +import PointerEvents from './directives/PointerEvents/PointerEventsDirective'; +import ThirdParties from './directives/ThirdParties/ThirdPartiesDirective'; /* * Stylesheets @@ -22,19 +24,14 @@ import './stylesheets/globals.scss'; import './stylesheets/layout.scss'; -/* Header - * ===================================== */ - -import './subModules/Header/header.scss'; - -/* Footer - * ===================================== */ - -import './subModules/Footer/footer.scss'; - /* ========================================================================== */ - -export default angular.module('Workflow.Layout', [ - PointerEvents -]).controller('LayoutController', LayoutController).name; +/** + * Define app module. + * @param {String} moduleName. + * @param {Array} dependencies. + * @export Module name - name of root module of Simply app + */ +export default angular.module('Workflow.App', [ + PointerEvents, ThirdParties +]).controller('AppController', AppController).name; diff --git a/src/modules/Application/controller/AppCtrl.spec.js b/src/modules/Application/controller/AppCtrl.spec.js new file mode 100644 index 0000000..2713b3b --- /dev/null +++ b/src/modules/Application/controller/AppCtrl.spec.js @@ -0,0 +1,23 @@ +import App from '../Index'; + +describe('Controller: App', () => { + let $scope, $controller, controller; + + beforeEach(angular.mock.module(App)); + + beforeEach(angular.mock.inject((_$controller_, _$rootScope_) => { + $controller = _$controller_; + $scope = _$rootScope_.$new(); + + controller = $controller('AppController', { $scope }); + $scope.$digest(); + })); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); + + it('should have scope', () => { + expect(typeof controller.$scope).toBe('object'); + }); +}); diff --git a/src/modules/Application/directives/PointerEvents/PointerEventsDirective.e2e.js b/src/modules/Application/directives/PointerEvents/PointerEventsDirective.e2e.js new file mode 100644 index 0000000..582625e --- /dev/null +++ b/src/modules/Application/directives/PointerEvents/PointerEventsDirective.e2e.js @@ -0,0 +1,12 @@ +describe('PointerEvents', () => { + beforeEach(() => { + browser.get('/home'); + }); + + it('should have no-hover class while scrolling', () => { + const script = `document.body.style.height='2000px';window.scrollTo(0,1000);`; + browser.driver.executeScript(script).then(() => { + expect(element(by.css('.no-hover')).isPresent()).toEqual(true); + }); + }); +}); diff --git a/src/modules/Application/directives/PointerEvents/PointerEventsDirective.js b/src/modules/Application/directives/PointerEvents/PointerEventsDirective.js new file mode 100644 index 0000000..f84f800 --- /dev/null +++ b/src/modules/Application/directives/PointerEvents/PointerEventsDirective.js @@ -0,0 +1,35 @@ +import angular from 'angular'; + +/** + * Set pointer-events property to none on scroll for boosting + * performance (up to 60fps). Disable css hover events + * @module Pointer Events + * @param {Object} $timeout - Timeout provider. + */ +const PointerEvents = $timeout => { /*@ngInject*/ + return { + restrict: 'A', + link(scope, $element) { + let timeout; + window.addEventListener('scroll', () => { + $timeout.cancel(timeout); + + if(!$element[0].classList.contains('no-hover')) { + $element[0].classList.add('no-hover'); + } + + if($element[0].classList.contains('no-hover')) { + timeout = $timeout(() => $element[0].classList.remove('no-hover'), 500); /** Enable it every 500ms */ + } + }); + } + }; +}; + +/** + * Define PointerEvents module. + * @param {String} moduleName. + * @param {Array} dependencies. + * @export Module name - name of this module of Simply app + */ +export default angular.module('Workflow.App.PointerEvents', []).directive('pointerEvents', PointerEvents).name; diff --git a/src/modules/Application/directives/PointerEvents/PointerEventsDirective.spec.js b/src/modules/Application/directives/PointerEvents/PointerEventsDirective.spec.js new file mode 100644 index 0000000..e013e5b --- /dev/null +++ b/src/modules/Application/directives/PointerEvents/PointerEventsDirective.spec.js @@ -0,0 +1,16 @@ +import PointerEvents from './PointerEventsDirective'; + +describe('Directive: PointerEvents', () => { + let $compile, $rootScope; + + beforeEach(angular.mock.module(PointerEvents)); + + beforeEach(inject((_$compile_, _$rootScope_) => { + $compile = _$compile_; + $rootScope = _$rootScope_; + })); + + it('should be defined', () => { + expect($compile).toBeDefined(); + }); +}); diff --git a/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.e2e.js b/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.e2e.js new file mode 100644 index 0000000..9707ce9 --- /dev/null +++ b/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.e2e.js @@ -0,0 +1,5 @@ +describe('ThirdParties', () => { + beforeEach(() => { + browser.get('/home'); + }); +}); diff --git a/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.js b/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.js new file mode 100644 index 0000000..7b8fda1 --- /dev/null +++ b/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.js @@ -0,0 +1,23 @@ +import angular from 'angular'; +import FastClick from 'Fastclick'; + +/** + * Enable all third-party scripts + * @module ThirdParties + */ +const ThirdParties = () => { /*@ngInject*/ + return { + restrict: 'A', + link() { + new FastClick(document.body); /** Remove 300ms delay on touch devices */ + } + }; +}; + +/** + * Define ThirdParties module. + * @param {String} moduleName. + * @param {Array} dependencies. + * @export Module name - name of this module of Simply app + */ +export default angular.module('Workflow.App.ThirdParties', []).directive('thirdParties', ThirdParties).name; diff --git a/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.spec.js b/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.spec.js new file mode 100644 index 0000000..6c1c014 --- /dev/null +++ b/src/modules/Application/directives/ThirdParties/ThirdPartiesDirective.spec.js @@ -0,0 +1,16 @@ +import ThirdParties from './ThirdPartiesDirective'; + +describe('Directive: ThirdParties', () => { + let $compile, $rootScope; + + beforeEach(angular.mock.module(ThirdParties)); + + beforeEach(inject((_$compile_, _$rootScope_) => { + $compile = _$compile_; + $rootScope = _$rootScope_; + })); + + it('should be defined', () => { + expect($compile).toBeDefined(); + }); +}); diff --git a/src/modules/Application/stylesheets/fonts.scss b/src/modules/Application/stylesheets/fonts.scss new file mode 100644 index 0000000..e950c05 --- /dev/null +++ b/src/modules/Application/stylesheets/fonts.scss @@ -0,0 +1,31 @@ +/* +@each $type in Light, LightItalic, Medium, MediumItalic { + @font-face { + font-family: "My Font"; + src: url("./fonts/MyFont/$(type)/MyFont-$(type).eot"); + src: url("./fonts/MyFont/$(type)/MyFont-$(type).eot?#iefix") format("embedded-opentype"), + url("./fonts/MyFont/$(type)/MyFont-$(type).woff") format("woff"), + url("./fonts/MyFont/$(type)/MyFont-$(type).ttf") format("truetype"); + + @if $type == Light { + font-style: normal; + font-weight: 400; + } + + @if $type == LightItalic { + font-style: italic; + font-weight: 400; + } + + @if $type == Medium { + font-style: normal; + font-weight: 700; + } + + @if $type == MediumItalic { + font-style: italic; + font-weight: 700; + } + } +} +*/ diff --git a/src/modules/Layout/stylesheets/fonts/.gitkeep b/src/modules/Application/stylesheets/fonts/.gitkeep similarity index 100% rename from src/modules/Layout/stylesheets/fonts/.gitkeep rename to src/modules/Application/stylesheets/fonts/.gitkeep diff --git a/src/modules/Layout/stylesheets/globals.scss b/src/modules/Application/stylesheets/globals.scss similarity index 100% rename from src/modules/Layout/stylesheets/globals.scss rename to src/modules/Application/stylesheets/globals.scss diff --git a/src/modules/Layout/stylesheets/layout.scss b/src/modules/Application/stylesheets/layout.scss similarity index 100% rename from src/modules/Layout/stylesheets/layout.scss rename to src/modules/Application/stylesheets/layout.scss diff --git a/src/modules/Layout/stylesheets/reset.scss b/src/modules/Application/stylesheets/reset.scss similarity index 100% rename from src/modules/Layout/stylesheets/reset.scss rename to src/modules/Application/stylesheets/reset.scss diff --git a/src/modules/Layout/subModules/Footer/footer.jade b/src/modules/Application/subModules/Footer/footer.jade similarity index 100% rename from src/modules/Layout/subModules/Footer/footer.jade rename to src/modules/Application/subModules/Footer/footer.jade diff --git a/src/modules/Layout/subModules/Footer/footer.scss b/src/modules/Application/subModules/Footer/footer.scss similarity index 100% rename from src/modules/Layout/subModules/Footer/footer.scss rename to src/modules/Application/subModules/Footer/footer.scss diff --git a/src/modules/Layout/subModules/Footer/images/.gitkeep b/src/modules/Application/subModules/Footer/images/.gitkeep similarity index 100% rename from src/modules/Layout/subModules/Footer/images/.gitkeep rename to src/modules/Application/subModules/Footer/images/.gitkeep diff --git a/src/modules/Layout/subModules/Header/header.jade b/src/modules/Application/subModules/Header/header.jade similarity index 100% rename from src/modules/Layout/subModules/Header/header.jade rename to src/modules/Application/subModules/Header/header.jade diff --git a/src/modules/Layout/subModules/Header/header.scss b/src/modules/Application/subModules/Header/header.scss similarity index 100% rename from src/modules/Layout/subModules/Header/header.scss rename to src/modules/Application/subModules/Header/header.scss diff --git a/src/modules/Layout/subModules/Header/images/.gitkeep b/src/modules/Application/subModules/Header/images/.gitkeep similarity index 100% rename from src/modules/Layout/subModules/Header/images/.gitkeep rename to src/modules/Application/subModules/Header/images/.gitkeep diff --git a/src/modules/Layout/views/layout.html b/src/modules/Application/views/layout.html similarity index 100% rename from src/modules/Layout/views/layout.html rename to src/modules/Application/views/layout.html diff --git a/src/modules/Layout/views/layout.jade b/src/modules/Application/views/layout.jade similarity index 55% rename from src/modules/Layout/views/layout.jade rename to src/modules/Application/views/layout.jade index ff9688c..14f24f8 100644 --- a/src/modules/Layout/views/layout.jade +++ b/src/modules/Application/views/layout.jade @@ -1,4 +1,8 @@ -section.wrapper(ng-controller="LayoutController", pointer-events="") +section.wrapper( + ng-controller="AppController" + pointer-events="" + third-parties="") + include ../subModules/Header/header.jade main.main(ui-view="") include ../subModules/Footer/footer.jade diff --git a/src/modules/Home/Index.js b/src/modules/Home/Index.js index dd46e14..9911c92 100644 --- a/src/modules/Home/Index.js +++ b/src/modules/Home/Index.js @@ -13,5 +13,10 @@ import './stylesheets/home.scss'; /* ========================================================================== */ - -export default angular.module('Workflow.Home', []).controller('HomeController', HomeController).name; +/** + * Define app public section home page module. + * @param {String} moduleName. + * @param {Array} dependencies. + * @export Module name - name of this module of Workflow app + */ +export default angular.module('Workflow.App.Home', []).controller('HomeController', HomeController).name; diff --git a/src/modules/Home/controller/Home.e2e.js b/src/modules/Home/controller/Home.e2e.js new file mode 100644 index 0000000..525afa8 --- /dev/null +++ b/src/modules/Home/controller/Home.e2e.js @@ -0,0 +1,25 @@ +describe('Home page', () => { + beforeEach(() => { + browser.get('/'); + }); + + it('should have a title', () => { + expect(browser.getTitle()).toEqual('Title'); + }); + + it('should have page content', () => { + expect(element(by.css('.page_home')).isPresent()).toEqual(true); + }); + + it('should get the current state', function (){ + const currentStateName = browser.executeAsyncScript((callback) => { + const el = document.querySelector('html'); + const injector = angular.element(el).injector(); + const service = injector.get('$state'); + + callback(service.current.name); + }); + + expect(currentStateName).toEqual('home'); + }); +}); diff --git a/src/modules/Home/controller/HomeCtrl.js b/src/modules/Home/controller/HomeCtrl.js index 7fc2e61..aada38a 100644 --- a/src/modules/Home/controller/HomeCtrl.js +++ b/src/modules/Home/controller/HomeCtrl.js @@ -1,4 +1,12 @@ +/** + * @module Controller for page home of public section layout. + * @class HomeController + */ export default class HomeController { /*@ngInject*/ + /** + * @constructor + * @param {object} $scope - Local (in this controller) application model. + */ constructor($scope) { this.$scope = $scope; } diff --git a/src/modules/Home/controller/HomeCtrl.spec.js b/src/modules/Home/controller/HomeCtrl.spec.js index c133699..2b72d1d 100644 --- a/src/modules/Home/controller/HomeCtrl.spec.js +++ b/src/modules/Home/controller/HomeCtrl.spec.js @@ -1,17 +1,23 @@ import Home from '../Index'; describe('Controller: Home', () => { - beforeEach(module(Home)); + let $scope, $controller, controller; - let $controller; + beforeEach(angular.mock.module(Home)); - beforeEach(inject(_$controller_ => $controller = _$controller_)); + beforeEach(angular.mock.inject((_$controller_, _$rootScope_) => { + $controller = _$controller_; + $scope = _$rootScope_.$new(); - describe('Is Home defined?', () => { - it('Is Home defined?', () => { - const $scope = {}; - const controller = $controller('HomeController', { $scope }); - expect(controller).toBeDefined(); - }); + controller = $controller('HomeController', { $scope }); + $scope.$digest(); + })); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); + + it('should have scope', () => { + expect(typeof controller.$scope).toBe('object'); }); }); diff --git a/src/modules/Layout/controller/LayoutCtrl.spec.js b/src/modules/Layout/controller/LayoutCtrl.spec.js deleted file mode 100644 index 0a0cb17..0000000 --- a/src/modules/Layout/controller/LayoutCtrl.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -import Layout from '../Index'; - -describe('Controller: Layout', () => { - beforeEach(module(Layout)); - - let $controller; - - beforeEach(inject(_$controller_ => $controller = _$controller_)); - - describe('Is Layout defined?', () => { - it('Is Layout defined?', () => { - const $scope = {}; - const controller = $controller('LayoutController', { $scope }); - expect(controller).toBeDefined(); - }); - }); -}); diff --git a/src/modules/Layout/directives/PointerEvents/PointerEvents.spec.js b/src/modules/Layout/directives/PointerEvents/PointerEvents.spec.js deleted file mode 100644 index 499ecb8..0000000 --- a/src/modules/Layout/directives/PointerEvents/PointerEvents.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -import PointerEvents from './PointerEventsDirective'; - -describe('Directive: PointerEvents', () => { - let $compile, $rootScope; - - // Load the myApp module, which contains the directive - beforeEach(module(PointerEvents)); - - // Store references to $rootScope and $compile - // so they are available to all tests in this describe block - beforeEach(inject(function(_$compile_, _$rootScope_){ - // The injector unwraps the underscores (_) from around the parameter names when matching - $compile = _$compile_; - $rootScope = _$rootScope_; - })); -}); diff --git a/src/modules/Layout/directives/PointerEvents/PointerEventsDirective.e2e.js b/src/modules/Layout/directives/PointerEvents/PointerEventsDirective.e2e.js deleted file mode 100644 index 58ae550..0000000 --- a/src/modules/Layout/directives/PointerEvents/PointerEventsDirective.e2e.js +++ /dev/null @@ -1,8 +0,0 @@ -describe('PointerEvents', () => { - beforeEach(() => { - browser.get('/'); - }); - -}); - - diff --git a/src/modules/Layout/directives/PointerEvents/PointerEventsDirective.js b/src/modules/Layout/directives/PointerEvents/PointerEventsDirective.js deleted file mode 100644 index 14710b1..0000000 --- a/src/modules/Layout/directives/PointerEvents/PointerEventsDirective.js +++ /dev/null @@ -1,21 +0,0 @@ -import angular from 'angular'; - -const PointerEvents = $timeout => { - /*@ngInject*/ - return { - restrict: 'A', - link(scope, $element) { - let timeout; - window.addEventListener('scroll', () => { - $timeout.cancel(timeout); - if(!$element[0].classList.contains('no-hover')) { - $element[0].classList.add('no-hover'); - } else { - timeout = $timeout(() => $element[0].classList.remove('no-hover'), 500); - } - }); - } - }; -}; - -export default angular.module('Workflow.Layout.PointerEvents', []).directive('pointerEvents', PointerEvents).name; diff --git a/src/modules/Layout/stylesheets/fonts.scss b/src/modules/Layout/stylesheets/fonts.scss deleted file mode 100644 index 2ba1c40..0000000 --- a/src/modules/Layout/stylesheets/fonts.scss +++ /dev/null @@ -1,11 +0,0 @@ -/* -@font-face { - font-family: "My Font"; - src: url("./fonts/MyFont/MyFontRegular/MyFont.eot"); - src: url("./fonts/MyFont/MyFontRegular/MyFont.eot?#iefix") format("embedded-opentype"), - url("./fonts/MyFont/MyFontRegular/MyFont.woff") format("woff"), - url("./fonts/MyFont/MyFontRegular/MyFont.ttf") format("truetype"); - font-style: normal; - font-weight: normal; -} -*/ diff --git a/src/specs.webpack.js b/src/specs.webpack.js new file mode 100644 index 0000000..269c957 --- /dev/null +++ b/src/specs.webpack.js @@ -0,0 +1,10 @@ +/** + * This file is an entry point for angular tests. + * Avoids some weird issues when using webpack + angular. + * */ + +import 'angular'; +import 'angular-mocks/angular-mocks'; + +const testsContext = require.context('./', true, /.spec$/); +testsContext.keys().forEach(testsContext); diff --git a/src/stylesheets/mixins.scss b/src/stylesheets/mixins.scss index df5a530..eb86bf0 100755 --- a/src/stylesheets/mixins.scss +++ b/src/stylesheets/mixins.scss @@ -1,3 +1,4 @@ +/* @mixin clearfix {} */ @define-mixin clearfix { &::before, &::after { content: " "; diff --git a/src/tests.webpack.js b/src/tests.webpack.js deleted file mode 100644 index 63d831e..0000000 --- a/src/tests.webpack.js +++ /dev/null @@ -1,8 +0,0 @@ -// This file is an entry point for angular tests -// Avoids some weird issues when using webpack + angular. - -import 'angular'; -import 'angular-mocks/angular-mocks'; - -const testsContext = require.context('.', true, /.spec$/); -testsContext.keys().forEach(testsContext); diff --git a/webpack.config.js b/webpack.config.js index 6af2514..8bc13bb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,4 @@ -'use strict'; - -// Modules +/** Modules */ var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); @@ -13,6 +11,12 @@ var CopyWebpackPlugin = require('copy-webpack-plugin'); var ENV = process.env.npm_lifecycle_event; module.exports = (function makeWebpackConfig () { + /** + * Port + * This is default port for dev server + */ + var port = 8080; + /** * Config * Reference: http://webpack.github.io/docs/configuration.html @@ -37,19 +41,24 @@ module.exports = (function makeWebpackConfig () { * Karma will handle setting it up for you when it's a test build */ config.output = ENV === 'test' ? {} : { - // Absolute output directory - path: __dirname + '/dist', + path: __dirname + '/dist', /** Absolute output directory */ - // Output path from the view of the page - // Uses webpack-dev-server in development - publicPath: ENV === 'build' ? '/' : 'http://localhost:8080/', + /** + * Output path from the view of the page + * Uses webpack-dev-server in development + */ + publicPath: ENV === 'build' ? '/' : 'http://localhost:' + port + '/', - // Filename for entry points - // Only adds hash in build mode + /** + * Filename for entry points + * Only adds hash in build mode + */ filename: ENV === 'build' ? '[name].[hash].js' : '[name].bundle.js', - // Filename for non-entry points - // Only adds hash in build mode + /** + * Filename for non-entry points + * Only adds hash in build mode + */ chunkFilename: ENV === 'build' ? '[name].[hash].js' : '[name].bundle.js' }; @@ -73,65 +82,87 @@ module.exports = (function makeWebpackConfig () { * This handles most of the magic responsible for converting modules */ - // Initialize module + /** Initialize module */ config.module = { preLoaders: [], loaders: [{ - // JS LOADER - // Reference: https://github.com/babel/babel-loader - // Transpile .js files using babel-loader - // Compiles ES6 and ES7 into ES5 code + /** + * JS LOADER + * Reference: https://github.com/babel/babel-loader + * Transpile .js files using babel-loader + * Compiles ES6 and ES7 into ES5 code + */ test: /\.js$/, loaders: ['ng-annotate', 'babel'], exclude: /node_modules/ }, { - // CSS LOADER - // Reference: https://github.com/webpack/css-loader - // Allow loading css through js - // - // Reference: https://github.com/postcss/postcss-loader - // Postprocess your css with PostCSS plugins + /** + * CSS LOADER + * Reference: https://github.com/webpack/css-loader + * Allow loading css through js + * Compiles ES6 and ES7 into ES5 code + * + * Reference: https://github.com/postcss/postcss-loader + * Postprocess your css with PostCSS plugins + */ test: /\.scss$/, - // Reference: https://github.com/webpack/extract-text-webpack-plugin - // Extract css files in production builds - // - // Reference: https://github.com/webpack/style-loader - // Use style-loader in development. + + /** + * CSS LOADER + * Reference: https://github.com/webpack/extract-text-webpack-plugin + * Extract css files in production builds + * Compiles ES6 and ES7 into ES5 code + * + * Reference: https://github.com/webpack/style-loader + * Use style-loader in development. + */ loader: ENV === 'test' ? 'null' : ExtractTextPlugin.extract('style', 'css?sourceMap!postcss') }, { - // ASSET LOADER - // Reference: https://github.com/webpack/file-loader - // Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output - // Rename the file using the asset hash - // Pass along the updated reference to your code - // You can add here any file extension you want to get copied to your output + + /** + * ASSET LOADER + * Reference: https://github.com/webpack/file-loader + * Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output + * Rename the file using the asset hash + * Pass along the updated reference to your code + * You can add here any file extension you want to get copied to your output + */ test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/, loader: 'file' }, { - // HTML LOADER - // Reference: https://github.com/webpack/raw-loader - // Allow loading html through js + + /** + * HTML LOADER + * Reference: https://github.com/webpack/raw-loader + * Allow loading html through js + */ test: /\.html$/, loader: 'html' }, { - // JADE LOADER - // Reference: https://github.com/webpack/jade-loader - // Allow loading jade through js + + /** + * JADE LOADER + * Reference: https://github.com/webpack/jade-loader + * Allow loading jade through js + */ test: /\.jade$/, loader: 'jade' }] }; - // ISPARTA LOADER - // Reference: https://github.com/ColCh/isparta-instrumenter-loader - // Instrument JS files with Isparta for subsequent code coverage reporting - // Skips node_modules and files that end with .test.js + /** + * ISPARTA LOADER + * Reference: https://github.com/ColCh/isparta-instrumenter-loader + * Instrument JS files with Isparta for subsequent code coverage reporting + * Skips node_modules and files that end with .spec.js and .e2e.js + */ if (ENV === 'test') { config.module.preLoaders.push({ test: /\.js$/, exclude: [ /node_modules/, - /\.spec\.js$/ + /\.spec\.js$/, + /\.e2e\.js$/ ], loader: 'isparta-instrumenter' }); @@ -164,40 +195,54 @@ module.exports = (function makeWebpackConfig () { */ config.plugins = []; - // Skip rendering index.html in test mode + /** Skip rendering index.html in test mode */ if (ENV !== 'test') { - // Reference: https://github.com/ampedandwired/html-webpack-plugin - // Render index.html + + /** + * Reference: https://github.com/ampedandwired/html-webpack-plugin + * Render index.html + */ config.plugins.push( new HtmlWebpackPlugin({ - template: './src/modules/Layout/views/layout.html', + template: './src/modules/Application/views/layout.html', inject: 'body' }), - // Reference: https://github.com/webpack/extract-text-webpack-plugin - // Extract css files - // Disabled when in test mode or not in build mode + /** + * Reference: https://github.com/webpack/extract-text-webpack-plugin + * Extract css files + * Disabled when in test mode or not in build mode + */ new ExtractTextPlugin('[name].[hash].css', {disable: ENV !== 'build'}) ); } - // Add build specific plugins + /** Add build specific plugins */ if (ENV === 'build') { config.plugins.push( - // Reference: http://webpack.github.io/docs/list-of-plugins.html#noerrorsplugin - // Only emit files when there are no errors + + /** + * Reference: http://webpack.github.io/docs/list-of-plugins.html#noerrorsplugin + * Only emit files when there are no errors + */ new webpack.NoErrorsPlugin(), - // Reference: http://webpack.github.io/docs/list-of-plugins.html#dedupeplugin - // Dedupe modules in the output + /** + * Reference: http://webpack.github.io/docs/list-of-plugins.html#dedupeplugin + * Dedupe modules in the output + */ new webpack.optimize.DedupePlugin(), - // Reference: http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin - // Minify all javascript, switch loaders to minimizing mode + /** + * Reference: http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin + * Minify all javascript, switch loaders to minimizing mode + */ new webpack.optimize.UglifyJsPlugin(), - // Copy assets from the public folder - // Reference: https://github.com/kevlened/copy-webpack-plugin + /** + * Reference: https://github.com/kevlened/copy-webpack-plugin + * Copy assets from the public folder + */ new CopyWebpackPlugin([{ from: __dirname + '/src/public' }]) @@ -211,7 +256,8 @@ module.exports = (function makeWebpackConfig () { */ config.devServer = { contentBase: './src/public', - stats: 'minimal' + stats: 'minimal', + port: port }; return config;