Added Nav Plugin tests

Summary:
Here I added two tests to test the persisted state reducer in the navigation pliugin.

I uncovered that my state reducer is not pure, as it calls the Date constructor, but I will fix this in a future update by passing the date recorded on the Android device when the nav event occurs and sending that via the socket connection.

For now I have modified the state reducer to take a date as part of the payload on a nav_event, or if none exists record the date as before. Also, if a page has no uri, but we want to record a nav event, I send null uri from the Android side. This doesn't send the uri as null to flipper; the uri object property simply doesn't exist. In this case I explicitly cast the undefined value for uri to null.

Reviewed By: jknoxville

Differential Revision: D16330958

fbshipit-source-id: fe338ea3a244df6ef33356bc7fdef8da9291dc68
This commit is contained in:
Benjamin Elo
2019-07-18 02:45:18 -07:00
committed by Facebook Github Bot
parent a6fb1a9d86
commit beb656c84e
2 changed files with 116 additions and 7 deletions

View File

@@ -14,12 +14,12 @@ type State = {||};
type Data = {||};
type NavigationEvent = {|
date: Date,
uri: ?String,
date: ?Date,
uri: ?string,
|};
type PersistedState = {|
navigationEvents: [NavigationEvent],
export type PersistedState = {|
navigationEvents: Array<NavigationEvent>,
|};
export default class extends FlipperPlugin<State, {}, PersistedState> {
@@ -35,7 +35,7 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
static persistedStateReducer = (
persistedState: PersistedState,
method: string,
payload: Object,
payload: NavigationEvent,
): $Shape<PersistedState> => {
switch (method) {
case 'nav_event':
@@ -43,7 +43,10 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
...persistedState,
navigationEvents: [
...persistedState.navigationEvents,
{uri: payload.uri, date: new Date()},
{
uri: payload.uri === undefined ? null : payload.uri,
date: payload.date || new Date(),
},
],
};
default:
@@ -55,7 +58,7 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
onKeyboardAction = (action: string) => {
if (action === 'clear') {
this.props.setPersistedState({data: []});
this.props.setPersistedState({navigationEvents: []});
}
};