Skip to content

Commit

Permalink
Version 1.2.1
Browse files Browse the repository at this point in the history
- Allow defining 'parent' as string
- Some cleanup
  • Loading branch information
Mark Lagendijk committed Dec 29, 2014
1 parent 14802ce commit 5fd7c99
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-ui-router.stateHelper",
"main": "statehelper.js",
"version": "1.2.0",
"version": "1.2.1",
"homepage": "https://github.com/marklagendijk/ui-router.stateHelper",
"authors": [
"Mark Lagendijk <[email protected]>"
Expand Down
8 changes: 5 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ var karma = require("gulp-karma");
var config = require('./config/config.js');

gulp.task("test", ["minify"], function(){
gulp.src(config.testFiles)
return gulp.src(config.testFiles)
.pipe(karma({
configFile: 'config/karma.conf.js',
action: 'run'
}));
});

gulp.task("minify", function(){
gulp.src("statehelper.js")
return gulp.src("statehelper.js")
.pipe(ngmin())
.pipe(uglify())
.pipe(rename("statehelper.min.js"))
.pipe(gulp.dest("./"));
});
});

gulp.task("default", ["minify", "test"]);
2 changes: 1 addition & 1 deletion statehelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ angular.module('ui.router.stateHelper', [ 'ui.router' ])
if(state.children && state.children.length){
state.children.forEach(function(childState){
childState.parent = state;
self.setNestedState(childState, keepOriginalNames);
self.state(childState, keepOriginalNames);
});
}

Expand Down
2 changes: 1 addition & 1 deletion statehelper.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 43 additions & 43 deletions test/statehelperSpec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
/* globals: beforeEach, describe, it, module, inject, expect */
describe('ui-router.stateHelper', function(){
var stateHelperProvider, $stateProvider, rootState, expectedState;
var stateHelperProvider, $stateProvider, rootState, expectedState;

beforeEach(module('ui.router.stateHelper', function(_stateHelperProvider_, _$stateProvider_){
beforeEach(module('ui.router.stateHelper', function(_stateHelperProvider_, _$stateProvider_){
stateHelperProvider = _stateHelperProvider_;
$stateProvider = _$stateProvider_;
}));

beforeEach(inject(function(){
rootState = {
name: 'root',
children: [
{
name: 'login',
templateUrl: '/partials/views/login.html'
},
{
name: 'backup',
children: [
{
name: 'dashboard'
}
]
}
]
};

spyOn($stateProvider, 'state');
}));

describe('.state', function(){
$stateProvider = _$stateProvider_;
}));

beforeEach(inject(function(){
rootState = {
name: 'root',
children: [
{
name: 'login',
templateUrl: '/partials/views/login.html'
},
{
name: 'backup',
children: [
{
name: 'dashboard'
}
]
}
]
};

spyOn($stateProvider, 'state');
}));

describe('.state', function(){
beforeEach(inject(function(){
expectedState = {
name: 'root',
Expand All @@ -52,26 +52,26 @@ describe('ui-router.stateHelper', function(){
stateHelperProvider.state(rootState);
}));

it('should set each state', function(){
expect($stateProvider.state.callCount).toBe(4);
});
it('should set each state', function(){
expect($stateProvider.state.callCount).toBe(4);
});

it('should convert names to dot notation, set parent references', function(){
// Since the states are objects which contain references to each other, we are testing the eventual
// root state object (and not the root state object as it is passed to $stateProvider.$state).
// Because of this we have to test everything at once
it('should convert names to dot notation, set parent references', function(){
// Since the states are objects which contain references to each other, we are testing the eventual
// root state object (and not the root state object as it is passed to $stateProvider.$state).
// Because of this we have to test everything at once

expectedState.children[0].parent = expectedState;
expectedState.children[1].parent = expectedState;
expectedState.children[1].children[0].parent = expectedState.children[1];
expectedState.children[0].parent = expectedState;
expectedState.children[1].parent = expectedState;
expectedState.children[1].children[0].parent = expectedState.children[1];

expect($stateProvider.state.argsForCall[0][0]).toEqual(expectedState);
});
expect($stateProvider.state.argsForCall[0][0]).toEqual(expectedState);
});

it('should return itself to support chaining', function(){
expect($stateProvider.state(rootState)).toBe($stateProvider);
})
});
expect(stateHelperProvider.state(rootState)).toBe(stateHelperProvider);
});
});

describe('.state with keepOriginalNames set to true', function(){
beforeEach(inject(function(){
Expand Down

0 comments on commit 5fd7c99

Please sign in to comment.