Fix TabRouter-test

This commit is contained in:
Brent Vatne
2018-03-09 10:46:05 -08:00
parent bdda6fa5be
commit 47f357f332
2 changed files with 19 additions and 12 deletions

View File

@@ -27,7 +27,6 @@ export default (routeConfigs, config = {}) => {
: true;
const initialRouteIndex = order.indexOf(initialRouteName);
const childRouters = {};
order.forEach(routeName => {
const routeConfig = routeConfigs[routeName];
paths[routeName] =
@@ -157,9 +156,8 @@ export default (routeConfigs, config = {}) => {
let didNavigate = false;
if (action.type === NavigationActions.NAVIGATE) {
const navigateAction = action;
didNavigate = !!order.find((childId, i) => {
if (childId === navigateAction.routeName) {
if (childId === action.routeName) {
activeChildIndex = i;
return true;
}
@@ -174,7 +172,7 @@ export default (routeConfigs, config = {}) => {
newChildState = childRouter
? childRouter.getStateForAction(action.action, childState)
: null;
} else if (!childRouter && action.params) {
} else if (!action.action && !childRouter && action.params) {
newChildState = {
...childState,
params: {
@@ -192,6 +190,12 @@ export default (routeConfigs, config = {}) => {
routes,
index: activeChildIndex,
});
} else if (
!newChildState &&
state.index === activeChildIndex &&
prevState
) {
return null;
}
}
}

View File

@@ -351,7 +351,7 @@ describe('TabRouter', () => {
});
const MidNavigator = () => <div />;
MidNavigator.router = TabRouter({
Foo: { screen: ChildNavigator0 },
Fee: { screen: ChildNavigator0 },
Bar: { screen: ChildNavigator1 },
});
const router = TabRouter({
@@ -371,8 +371,8 @@ describe('TabRouter', () => {
routes: [
{
index: 0,
key: 'Foo',
routeName: 'Foo',
key: 'Fee',
routeName: 'Fee',
isTransitioning: false,
routes: [
{ key: 'Boo', routeName: 'Boo' },
@@ -410,8 +410,8 @@ describe('TabRouter', () => {
routes: [
{
index: 0,
key: 'Foo',
routeName: 'Foo',
key: 'Fee',
routeName: 'Fee',
isTransitioning: false,
routes: [
{ key: 'Boo', routeName: 'Boo' },
@@ -444,7 +444,10 @@ describe('TabRouter', () => {
action: {
type: NavigationActions.NAVIGATE,
routeName: 'Bar',
action: { type: NavigationActions.NAVIGATE, routeName: 'Zap' },
action: {
type: NavigationActions.NAVIGATE,
routeName: 'Zap',
},
},
});
expect(state4).toEqual({
@@ -459,8 +462,8 @@ describe('TabRouter', () => {
routes: [
{
index: 0,
key: 'Foo',
routeName: 'Foo',
key: 'Fee',
routeName: 'Fee',
isTransitioning: false,
routes: [
{ key: 'Boo', routeName: 'Boo' },