export default function reducer(state = initialNavState, action) {
  switch (action.type) {
    case NAV_PUSH:
      if (state.routes[state.index].key === (action.state && action.state.key)) {
        return state;
      }
      return NavigationStateUtils.push(state, action.data);

    case NAV_POP:
      if (state.index === 0 || state.routes.length === 1) {
        return state;
      }
      return NavigationStateUtils.pop(state);

    case NAV_JUMP_TO_KEY:
      return NavigationStateUtils.jumpTo(state, action.key);

    case NAV_JUMP_TO_INDEX:
      return NavigationStateUtils.jumpToIndex(state, action.index);

    case NAV_RESET:
      return NavigationStateUtils.reset(state, action.routes, action.index);

    default:
      return state;
  }
}
  it('Resets routes', () => {
    const state = {index: 0, routes: [{key: 'a'}, {key: 'b'}]};
    const newState = {index: 1, routes: [{key: 'x'}, {key: 'y'}]};
    expect(
      NavigationStateUtils.reset(
        state,
        [{key: 'x'}, {key: 'y'}],
      )
    ).toEqual(newState);

    expect(() => {
      NavigationStateUtils.reset(state, []);
    }).toThrow();
  });
 expect(() => {
   NavigationStateUtils.reset(state, [{key: 'x'}, {key: 'y'}], 100);
 }).toThrow();
 expect(() => {
   NavigationStateUtils.reset(state, []);
 }).toThrow();