Skip to content

Commit 106bb18

Browse files
committed
Merge pull request #15 from jrichardlai/fix-tests
Fix tests
2 parents e0ff150 + dc40e45 commit 106bb18

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

App/Root.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function getEnvironmentState() {
3333
};
3434

3535
function getDebugState() {
36-
return { savedPath: DebugStore.get().currentRoutePath };
36+
return {
37+
debug: DebugStore.get()
38+
};
3739
}
3840

3941
var Root = React.createClass({
@@ -48,7 +50,10 @@ var Root = React.createClass({
4850
},
4951

5052
onUserChange: function() {
51-
this.setState(getUserState());
53+
var state = getUserState();
54+
// reset the route stack on user change.
55+
state.routeStack = null;
56+
this.setState(state);
5257
},
5358

5459
onEnvChange: function() {
@@ -76,17 +81,27 @@ var Root = React.createClass({
7681
CurrentUserStore.removeChangeListener(this.onUserChange);
7782
},
7883

79-
getSavedPath: function() {
80-
if (!this.state.environment) { return null; }
81-
if (!this.state.environment.data.simulator) { return null; }
84+
getSavedCurrentRoutePath: function() {
85+
if (!this.state.environment.data.simulator) { return null; }
86+
if (this.state.environment.data.name === 'test') { return null; }
87+
88+
return this.state.debug.currentRoutePath;
89+
},
8290

83-
return this.state.savedPath;
91+
getDefaultRouteStack: function() {
92+
return Routes.parse(null, this.state.user.isLoggedIn(), true);
8493
},
8594

8695
renderContent: function() {
8796
if (this.state.routeUnderTest) return null;
8897

89-
var routeStack = Routes.parse(this.getSavedPath(), this.state.user.isLoggedIn(), true);
98+
var routeStack = this.state.routeStack;
99+
if (!routeStack && this.getSavedCurrentRoutePath()) {
100+
routeStack = Routes.parse(this.getSavedCurrentRoutePath(), this.state.user.isLoggedIn(), true);
101+
}
102+
if (!routeStack) {
103+
routeStack = this.getDefaultRouteStack();
104+
}
90105

91106
if(this.state.user.isLoggedIn()) {
92107
return (
@@ -103,7 +118,7 @@ var Root = React.createClass({
103118

104119
render: function() {
105120
// need to fetch current user and environment before launching
106-
if (!this.state.user || !this.state.environment) {
121+
if (!this.state.user || !this.state.environment || !this.state.debug) {
107122
return(<Launch ref="current" />);
108123
}
109124
else if (this.state.environment.data.name === 'test') {

App/Stores/DebugStore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ const EnvironmentManager = React.NativeModules.EnvironmentManager;
1010
const CHANGE_EVENT = 'change';
1111
const DEBUG_CURRENT_ROUTE_PATH_KEY = AppConstants.DEBUG_CURRENT_ROUTE_PATH_KEY;
1212

13-
var _values = {};
13+
var _values = null;
1414

1515
function setCurrentRoutePath(routePath) {
16+
_values = _values || {};
1617
_values.currentRoutePath = routePath;
1718
}
1819

@@ -50,7 +51,6 @@ Dispatcher.register(function(action) {
5051
if (action.routePath) {
5152
LocalKeyStore.setKey(DEBUG_CURRENT_ROUTE_PATH_KEY, action.routePath);
5253
setCurrentRoutePath(action.routePath);
53-
SingletonStore.emitChange();
5454
}
5555
break;
5656
case AppConstants.LOGOUT_REQUESTED:
@@ -63,4 +63,4 @@ Dispatcher.register(function(action) {
6363
}
6464
});
6565

66-
export default SingletonStore;
66+
module.exports = SingletonStore;

0 commit comments

Comments
 (0)