Skip to content

Commit

Permalink
Big update. Writed tests, modular devided controllers #2
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiQWERTY committed Mar 1, 2016
1 parent a46782a commit d92e79b
Show file tree
Hide file tree
Showing 45 changed files with 521 additions and 216 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules
dist
coverage
public
/public
build

.tmp
Expand Down
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ node_modules
public
build

node_modules
.tmp
.sass-cache
.idea
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pavel Zinovev <[email protected]>
50 changes: 34 additions & 16 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -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'
}
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -12,14 +12,15 @@
"karma",
"protractor",
"jasmine",
"Istanbul",
"workflow",
"e2e",
"starter",
"kit",
"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",
Expand All @@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions protractor.conf.js
Original file line number Diff line number Diff line change
@@ -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: [],
Expand Down
21 changes: 20 additions & 1 deletion src/Application.e2e.js
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, February 2016
*/

describe('Application', () => {
beforeEach(() => {
browser.get('/');
});


it('should have a title', () => {
expect(browser.getTitle()).toEqual('Title');
});
Expand All @@ -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');
});
});
27 changes: 15 additions & 12 deletions src/Application.js
Original file line number Diff line number Diff line change
@@ -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;
44 changes: 36 additions & 8 deletions src/Config.js
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, 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;
30 changes: 30 additions & 0 deletions src/Runners.js
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, 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;
24 changes: 24 additions & 0 deletions src/modules/Application/Controllers.js
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, 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;
31 changes: 14 additions & 17 deletions src/modules/Layout/Index.js → src/modules/Application/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
23 changes: 23 additions & 0 deletions src/modules/Application/controller/AppCtrl.spec.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
Loading

0 comments on commit d92e79b

Please sign in to comment.