Files
flipper/src/plugins/navigation/__tests__/testNavigationPlugin.node.js
Benjamin Elo 84f9a1d8b5 Added ability to save bookmarks in Nav Plugin
Summary:
This is a glue commit that glues all the components I've added in the past together.

Favouriting a page (i.e. clicking on the star) adds it as a bookmark.

There's four main parts to make your rreview easier:
1. Add bookmarks and favouriting to all the components that support it, including their parents. (NavigationInfoBox, SearchBar, Timeline)

2. Persist bookmarks using the indexedDB. (index.js)

3. Add saving to db through the SaveBookmarksDialog

4. Various other changes due to a changed architecture. i.e. moving bookmarks from persistedState to state.

Still to come.

1. Removing bookmarks.

2. Pressing enter to save the bookmarks when the SaveBookmarksDialog pops up.

3. Alphabetizing bookmarks? Order seems to jump around.

Reviewed By: jknoxville

Differential Revision: D16518013

fbshipit-source-id: 2e0cef14123c611db43cca360bc66dc4c05b11ed
2019-07-28 12:50:31 -07:00

107 lines
2.6 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
* @flow strict-local
*/
import NavigationPlugin from '../';
import type {PersistedState} from '../';
function constructPersistedStateMock(): PersistedState {
return {
navigationEvents: [],
};
}
function constructPersistedStateMockWithEvents(): PersistedState {
return {
navigationEvents: [
{
uri: 'mock://this_is_a_mock_uri/mock/1',
date: DATE_MOCK_2,
},
{
uri: 'mock://this_is_a_mock_uri/mock/2',
date: DATE_MOCK_3,
},
],
};
}
const DATE_MOCK_1 = new Date(2019, 6, 17, 11, 10, 0, 0);
const DATE_MOCK_2 = new Date(2019, 6, 18, 11, 10, 0, 0);
const DATE_MOCK_3 = new Date(2019, 6, 19, 11, 10, 0, 0);
const INCOMING_NAV_EVENT = {
uri: 'mock://this_is_a_mock_uri/mock',
date: DATE_MOCK_1,
};
const INCOMING_UNDEFINED_NAV_EVENT = {
date: DATE_MOCK_1,
};
test('add incoming nav event to persisted state', () => {
const persistedState = constructPersistedStateMock();
const reducer = NavigationPlugin.persistedStateReducer;
if (reducer) {
const newPersistedState = reducer(
persistedState,
'nav_event',
INCOMING_NAV_EVENT,
);
expect(newPersistedState.navigationEvents).toEqual([
{
uri: 'mock://this_is_a_mock_uri/mock',
date: DATE_MOCK_1,
},
]);
} else {
expect(reducer).not.toBeNull();
}
});
test('add incoming nav event to persisted state with nav events', () => {
const persistedState = constructPersistedStateMockWithEvents();
const reducer = NavigationPlugin.persistedStateReducer;
if (reducer) {
const newPersistedState = reducer(
persistedState,
'nav_event',
INCOMING_NAV_EVENT,
);
expect(newPersistedState.navigationEvents).toEqual([
{
uri: 'mock://this_is_a_mock_uri/mock',
date: DATE_MOCK_1,
},
...persistedState.navigationEvents,
]);
} else {
expect(reducer).not.toBeNull();
}
});
test('add incoming nav event with undefined uri to persisted state', () => {
const persistedState = constructPersistedStateMock();
const reducer = NavigationPlugin.persistedStateReducer;
if (reducer) {
const newPersistedState = reducer(
persistedState,
'nav_event',
INCOMING_UNDEFINED_NAV_EVENT,
);
expect(newPersistedState.navigationEvents).toEqual([
{
uri: null,
date: DATE_MOCK_1,
},
]);
} else {
expect(reducer).not.toBeNull();
}
});