Skip to content

Commit

Permalink
Cleanup naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jerolimov committed Dec 16, 2015
1 parent 6127693 commit 6f76aba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Expand Up @@ -3,13 +3,13 @@ function defaultCompareRoute(routeA, routeB) {
return routeA === routeB;
}

module.exports = function applyNavigatorStackChanges(prevRouteStack, nextRouteStack, navigator, compareRoute) {
module.exports = function applyNavigatorChanges(prevRouteStack, nextRouteStack, navigator, compareRoute) {
if (!prevRouteStack || !prevRouteStack.length) {
throw new Error('Prev route stack must be an array with at least one entry!');
} else if (!nextRouteStack || !nextRouteStack.length) {
throw new Error('Next route stack must be an array with at least one entry!');
} else if (!navigator) {
throw new Error('Navigator is not defined in applyNavigatorStackChanges!');
throw new Error('Navigator must be defined!');
}
if (!compareRoute) {
compareRoute = defaultCompareRoute;
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
@@ -1,6 +1,6 @@

var applyNavigatorStackChanges = require('../lib/applyNavigatorStackChanges');
var applyNavigatorChanges = require('../lib/applyNavigatorChanges');

module.exports = {
applyNavigatorStackChanges: applyNavigatorStackChanges
applyNavigatorChanges: applyNavigatorChanges
};
Expand Up @@ -2,11 +2,11 @@

var assert = require('assert');

var applyNavigatorStackChanges = require('../lib/applyNavigatorStackChanges');
var applyNavigatorChanges = require('../lib/applyNavigatorChanges');

var NavigatorMock = require('./NavigatorMock');

describe('applyNavigatorStackChanges', function() {
describe('applyNavigatorChanges', function() {
var routeA = 'routeA';
var routeB = 'routeB';
var routeC = 'routeC';
Expand All @@ -18,102 +18,102 @@ describe('applyNavigatorStackChanges', function() {
});

it('should be a function', function() {
assert.equal('function', typeof applyNavigatorStackChanges);
assert.equal('function', typeof applyNavigatorChanges);
});

it('should throw an error if prev route stack is null or empty', function() {
assert.throws(function() {
applyNavigatorStackChanges();
applyNavigatorChanges();
}, /Error: Prev route stack must be an array with at least one entry!/);
assert.throws(function() {
applyNavigatorStackChanges([]);
applyNavigatorChanges([]);
}, /Error: Prev route stack must be an array with at least one entry!/);
});

it('should throw an error if next route stack is null or empty', function() {
assert.throws(function() {
applyNavigatorStackChanges([ routeA ]);
applyNavigatorChanges([ routeA ]);
}, /Error: Next route stack must be an array with at least one entry!/);
assert.throws(function() {
applyNavigatorStackChanges([ routeA ], []);
applyNavigatorChanges([ routeA ], []);
}, /Error: Next route stack must be an array with at least one entry!/);
});

it('should throw an error if navigator is null', function() {
assert.throws(function() {
applyNavigatorStackChanges([ routeA ], [ routeB ], null);
}, /Error: Navigator is not defined in applyNavigatorStackChanges!/);
applyNavigatorChanges([ routeA ], [ routeB ], null);
}, /Error: Navigator must be defined!/);
});

it('must not call any navigator method if route stack is equal (===)', function() {
var prevRoutes = [routeA];
var nextRoutes = prevRoutes;
var expectedCallHistory = [];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

it('must not call any navigator method if nothing changes', function() {
var prevRoutes = [routeA];
var nextRoutes = [routeA];
var expectedCallHistory = [];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

it('should push a route if one was added', function() {
var prevRoutes = [routeA];
var nextRoutes = [routeA, routeB];
var expectedCallHistory = [ 'push routeB' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

it('should replace and push a route if one was added', function() {
var prevRoutes = [routeA, routeB];
var nextRoutes = [routeA, routeC, routeD];
var expectedCallHistory = [ 'replaceAtIndex routeC 1', 'push routeD' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

it('should pop a route if one was removed', function() {
var prevRoutes = [routeA, routeB];
var nextRoutes = [routeA];
var expectedCallHistory = [ 'pop' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

it('should replace and pop a route if one was removed', function() {
var prevRoutes = [routeA, routeB, routeC];
var nextRoutes = [routeA, routeD];
var expectedCallHistory = [ 'replaceAtIndex routeD 1', 'pop' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

it('should replace a route if all other are keeped', function() {
var prevRoutes = [routeA, routeB, routeC];
var nextRoutes = [routeA, routeD, routeC];
var expectedCallHistory = [ 'replaceAtIndex routeD 1' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

it('should replace the route stack if the route changes', function() {
var prevRoutes = [routeA];
var nextRoutes = [routeB, routeC];
var expectedCallHistory = [ 'immediatelyResetRouteStack routeB,routeC' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);

navigatorMock.resetMock();

prevRoutes = [routeA, routeB];
nextRoutes = [routeC];
expectedCallHistory = [ 'immediatelyResetRouteStack routeC' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});

Expand All @@ -124,7 +124,7 @@ describe('applyNavigatorStackChanges', function() {
return false;
};
var expectedCallHistory = [ 'immediatelyResetRouteStack routeA' ];
applyNavigatorStackChanges(prevRoutes, nextRoutes, navigatorMock, compareRoute);
applyNavigatorChanges(prevRoutes, nextRoutes, navigatorMock, compareRoute);
assert.deepEqual(navigatorMock.callHistory, expectedCallHistory);
});
});

0 comments on commit 6f76aba

Please sign in to comment.