Hedger Wang 1e626027f5 Rename navigationState.children to navigationState.routes.
Summary:
[Experimental API breaking changes]

The notion of `parent` or `children` in navigaton is misleading. We have no intention to maintain or
build the nested or hierarchical navigation states. To be clear, rename `navigationState.children` to
`navigationState.route`.

Reviewed By: ericvicenti

Differential Revision: D3332115

fbshipit-source-id: c72ed08acaf030fb9c60abf22fb15cc0f44b3485
2016-05-22 16:28:27 -07:00

57 lines
1.6 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow-broken
*/
'use strict';
jest
.unmock('NavigationStateUtils');
var NavigationStateUtils = require('NavigationStateUtils');
var VALID_PARENT_STATES = [
{routes: ['a','b'], index: 0},
{routes: [{key: 'a'},{key: 'b', foo: 123}], index: 1},
{routes: [{key: 'a'},{key: 'b'}], index: 0},
{routes: [{key: 'a'},{key: 'b'}], index: 2},
];
var INVALID_PARENT_STATES = [
'foo',
{},
{routes: [{key: 'a'}], index: 4},
{routes: [{key: 'a'}], index: -1},
{routes: [{key: 'a'}]},
{routes: {key: 'foo'}},
12,
null,
undefined,
[],
];
describe('NavigationStateUtils', () => {
it('identifies parents correctly with getParent', () => {
for (var i = 0; i <= VALID_PARENT_STATES.length; i++) {
var navState = VALID_PARENT_STATES[0];
expect(NavigationStateUtils.getParent(navState)).toBe(navState);
}
for (var i = 0; i <= INVALID_PARENT_STATES.length; i++) {
var navState = INVALID_PARENT_STATES[0];
expect(NavigationStateUtils.getParent(navState)).toBe(null);
}
});
it('can get routes', () => {
var fooState = {key: 'foo'};
var navState = {routes: [{key: 'foobar'}, fooState], index: 0};
expect(NavigationStateUtils.get(navState, 'foo')).toBe(fooState);
expect(NavigationStateUtils.get(navState, 'missing')).toBe(null);
});
});