Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
createTablePlugin using persistedState (fixes #310)
Summary: Implementing persistedState for createTablePlugin, so it doesn't lose its data when switching back and forth between plugins. When `runInBackground` is set to true on the native side, createTablePlugins are now also capable of receiving new data in the background. Adds a test suite for createTablePlugin, to make sure it: - returns a FlipperPlugin - ID, title and icon are set correctly - the resetMethod clears the data - the persistedStateReducer correctly adds new data Reviewed By: passy Differential Revision: D12939848 fbshipit-source-id: 30048f3ce2bb98c83b0c165e48df72c8e28eadcd
- Loading branch information
1 parent
21a18d3
commit db42e8e
Showing
2 changed files
with
134 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
import {createTablePlugin} from '../createTablePlugin.js'; | ||
import {FlipperPlugin} from '../plugin.js'; | ||
|
||
const PROPS = { | ||
title: 'Plugin Title', | ||
id: 'pluginID', | ||
icon: 'icon', | ||
method: 'method', | ||
resetMethod: 'resetMethod', | ||
columns: {}, | ||
columnSizes: {}, | ||
renderSidebar: () => {}, | ||
buildRow: () => {}, | ||
}; | ||
|
||
test('createTablePlugin returns FlipperPlugin', () => { | ||
const tablePlugin = createTablePlugin({...PROPS}); | ||
expect(tablePlugin.prototype).toBeInstanceOf(FlipperPlugin); | ||
}); | ||
|
||
test('Plugin ID is set', () => { | ||
const id = 'pluginID'; | ||
const tablePlugin = createTablePlugin({...PROPS, id}); | ||
expect(tablePlugin.id).toBe(id); | ||
}); | ||
|
||
test('Plugin title is set', () => { | ||
const title = 'My Plugin Title'; | ||
const tablePlugin = createTablePlugin({...PROPS, title}); | ||
expect(tablePlugin.title).toBe(title); | ||
}); | ||
|
||
test('Plugin icon is set', () => { | ||
const icon = 'icon'; | ||
const tablePlugin = createTablePlugin({...PROPS, icon}); | ||
expect(tablePlugin.icon).toBe(icon); | ||
}); | ||
|
||
test('persistedStateReducer is resetting data', () => { | ||
const resetMethod = 'resetMethod'; | ||
const tablePlugin = createTablePlugin({...PROPS, resetMethod}); | ||
|
||
// $FlowFixMe persistedStateReducer exists for createTablePlugin | ||
const {rows, datas} = tablePlugin.persistedStateReducer( | ||
{ | ||
datas: {'1': {id: '1'}}, | ||
rows: [ | ||
{ | ||
key: '1', | ||
columns: { | ||
id: { | ||
value: '1', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
resetMethod, | ||
{}, | ||
); | ||
|
||
expect(datas).toEqual({}); | ||
expect(rows).toEqual([]); | ||
}); | ||
|
||
test('persistedStateReducer is adding data', () => { | ||
const method = 'method'; | ||
const tablePlugin = createTablePlugin({...PROPS, method}); | ||
const id = '1'; | ||
|
||
// $FlowFixMe persistedStateReducer exists for createTablePlugin | ||
const {rows, datas} = tablePlugin.persistedStateReducer( | ||
{ | ||
datas: {}, | ||
rows: [], | ||
}, | ||
method, | ||
{id}, | ||
); | ||
|
||
expect(rows.length).toBe(1); | ||
expect(Object.keys(datas)).toEqual([id]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters