Init to Init-UUID (#1419)

This commit is contained in:
HelloYou
2017-05-13 06:08:22 +08:00
parent 1e951fec69
commit 229d41e7ce
4 changed files with 33 additions and 15 deletions

View File

@@ -17,3 +17,5 @@ jest.mock('ScrollView', () => {
}
return ScrollView;
});
Date.now = jest.fn(() => 0);

View File

@@ -107,7 +107,7 @@ export default (
{
...action,
type: undefined,
key: 'Init',
key: `Init-${_getUuid()}`,
},
],
};
@@ -130,7 +130,7 @@ export default (
route = {
...route,
routeName: initialRouteName,
key: 'Init',
key: `Init-${_getUuid()}`,
...(params ? { params } : {}),
};
// eslint-disable-next-line no-param-reassign

View File

@@ -90,6 +90,12 @@ test('Handles no-op actions with tabs within stack router', () => {
type: NavigationActions.NAVIGATE,
routeName: 'Qux',
});
/* $FlowFixMe */
expect(state1.routes[0].key).toEqual('Init-id-0-0');
/* $FlowFixMe */
expect(state2.routes[0].key).toEqual('Init-id-0-1');
/* $FlowFixMe */
state1.routes[0].key = state2.routes[0].key;
expect(state1).toEqual(state2);
const state3 = TestRouter.getStateForAction(
{ type: NavigationActions.NAVIGATE, routeName: 'Zap' },
@@ -114,7 +120,7 @@ test('Handles deep action', () => {
index: 0,
routes: [
{
key: 'Init',
key: 'Init-id-0-2',
routeName: 'Bar',
},
],
@@ -153,6 +159,12 @@ test('Supports lazily-evaluated getScreen', () => {
type: NavigationActions.NAVIGATE,
routeName: 'Qux',
});
/* $FlowFixMe */
expect(state1.routes[0].key).toEqual('Init-id-0-4');
/* $FlowFixMe */
expect(state2.routes[0].key).toEqual('Init-id-0-5');
/* $FlowFixMe */
state1.routes[0].key = state2.routes[0].key;
expect(state1).toEqual(state2);
const state3 = TestRouter.getStateForAction(
{ type: NavigationActions.NAVIGATE, routeName: 'Zap' },

View File

@@ -325,7 +325,7 @@ describe('StackRouter', () => {
const initState = TestRouter.getStateForAction(NavigationActions.init());
expect(initState).toEqual({
index: 0,
routes: [{ key: 'Init', routeName: 'foo' }],
routes: [{ key: 'Init-id-0-0', routeName: 'foo' }],
});
const pushedState = TestRouter.getStateForAction(
NavigationActions.navigate({ routeName: 'qux' }),
@@ -355,7 +355,7 @@ describe('StackRouter', () => {
index: 0,
routes: [
{
key: 'Init',
key: 'Init-id-0-4',
routeName: 'Foo',
},
],
@@ -380,7 +380,7 @@ describe('StackRouter', () => {
index: 0,
routes: [
{
key: 'Init',
key: 'Init-id-0-4',
routeName: 'Foo',
},
],
@@ -408,7 +408,7 @@ describe('StackRouter', () => {
index: 0,
routes: [
{
key: 'Init',
key: 'Init-id-0-6',
routeName: 'Foo',
},
],
@@ -433,7 +433,7 @@ describe('StackRouter', () => {
index: 0,
routes: [
{
key: 'Init',
key: 'Init-id-0-6',
routeName: 'Foo',
},
],
@@ -499,7 +499,7 @@ describe('StackRouter', () => {
index: 0,
routes: [
{
key: 'Init',
key: 'Init-id-0-12',
routeName: 'Bar',
},
],
@@ -521,7 +521,7 @@ describe('StackRouter', () => {
index: 0,
routes: [
{
key: 'Init',
key: 'Init-id-0-13',
routeName: 'Bar',
params: { foo: 'bar' },
},
@@ -574,7 +574,7 @@ describe('StackRouter', () => {
{
type: NavigationActions.SET_PARAMS,
params: { name: 'Qux' },
key: 'Init',
key: 'Init-id-0-16',
},
state,
);
@@ -602,7 +602,7 @@ describe('StackRouter', () => {
{
type: NavigationActions.SET_PARAMS,
params: { name: 'foobar' },
key: 'Init',
key: 'Init-id-0-17',
},
state,
);
@@ -610,7 +610,7 @@ describe('StackRouter', () => {
/* $FlowFixMe */
expect(state2 && state2.routes[0].routes[0].routes).toEqual([
{
key: 'Init',
key: 'Init-id-0-17',
routeName: 'Quux',
params: { name: 'foobar' },
},
@@ -753,7 +753,7 @@ describe('StackRouter', () => {
/* $FlowFixMe */
expect(state2 && state2.routes[1].routes).toEqual([
{
key: 'Init',
key: 'Init-id-0-26',
routeName: 'Baz',
params: { foo: '42' },
},
@@ -818,7 +818,11 @@ describe('StackRouter', () => {
state = router.getStateForAction(action);
}
expect(state && state.index).toEqual(0);
expect(state && state.routes[0]).toEqual({ key: 'Init', routeName: 'Bar' });
expect(state && state.routes[0]).toEqual({
key: 'Init-id-0-30',
routeName: 'Bar',
type: undefined,
});
});
test('Gets deep path', () => {