Some renames

Summary:
Some non-semantic changes. Mostly an earlier rename that was accidentally done only locally rather than across the codebase

Also support `.spec` test extension, which is more idiomatic Jest, since we don't use the `.node` and `.electron` distinction anymore anyway.

Reviewed By: jknoxville

Differential Revision: D22976438

fbshipit-source-id: f3abedb36cbac1e835295177117ccbca492a67a1
This commit is contained in:
Michel Weststrate
2020-08-20 13:31:17 -07:00
committed by Facebook GitHub Bot
parent bce3d48e71
commit 744fe01922
9 changed files with 54 additions and 61 deletions

View File

@@ -13,7 +13,7 @@ import {FlipperPlugin} from '../plugin';
import {renderMockFlipperWithPlugin} from '../test-utils/createMockFlipperWithPlugin';
import {
SandyPluginDefinition,
FlipperClient,
PluginClient,
TestUtils,
usePlugin,
createState,
@@ -113,7 +113,7 @@ test('PluginContainer can render Sandy plugins', async () => {
return <div>Hello from Sandy</div>;
}
const plugin = (client: FlipperClient) => {
const plugin = (client: PluginClient) => {
const connectedStub = jest.fn();
const disconnectedStub = jest.fn();
const activatedStub = jest.fn();
@@ -254,7 +254,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
return <div>Hello from Sandy</div>;
}
const plugin = (client: FlipperClient) => {
const plugin = (client: PluginClient) => {
const connectedStub = jest.fn();
const disconnectedStub = jest.fn();
const activatedStub = jest.fn();
@@ -396,7 +396,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
test('PluginContainer + Sandy plugin supports deeplink', async () => {
const linksSeen: any[] = [];
const plugin = (client: FlipperClient) => {
const plugin = (client: PluginClient) => {
const linkState = createState('');
client.onDeepLink((link) => {
linksSeen.push(link);

View File

@@ -14,7 +14,7 @@ import {registerPlugins} from '../../reducers/plugins';
import {
SandyPluginDefinition,
SandyPluginInstance,
FlipperClient,
PluginClient,
TestUtils,
} from 'flipper-plugin';
@@ -30,7 +30,7 @@ beforeEach(() => {
initialized = false;
});
function plugin(client: FlipperClient<any, any>) {
function plugin(client: PluginClient<any, any>) {
const connectStub = jest.fn();
const disconnectStub = jest.fn();
const destroyStub = jest.fn();

View File

@@ -26,7 +26,7 @@ import {
TestUtils,
SandyPluginDefinition,
createState,
FlipperClient,
PluginClient,
} from 'flipper-plugin';
import {selectPlugin} from '../../reducers/connections';
@@ -1043,7 +1043,7 @@ const sandyTestPlugin = new SandyPluginDefinition(
TestUtils.createMockPluginDetails(),
{
plugin(
client: FlipperClient<{
client: PluginClient<{
inc: {};
}>,
) {

View File

@@ -23,7 +23,7 @@ import {registerPlugins} from '../../reducers/plugins';
import {
SandyPluginDefinition,
TestUtils,
FlipperClient,
PluginClient,
SandyPluginInstance,
} from 'flipper-plugin';
@@ -33,7 +33,7 @@ type Events = {
};
};
function plugin(client: FlipperClient<Events, {}>) {
function plugin(client: PluginClient<Events, {}>) {
const state = {
count: 0,
};

View File

@@ -10,10 +10,7 @@
import './plugin/PluginBase';
import * as TestUtilites from './test-utils/test-utils';
export {
SandyPluginInstance,
PluginClient as FlipperClient,
} from './plugin/Plugin';
export {SandyPluginInstance, PluginClient} from './plugin/Plugin';
export {
Device,
DeviceLogEntry,

View File

@@ -22,6 +22,6 @@ module.exports = {
},
clearMocks: true,
coverageReporters: ['json-summary', 'lcov', 'html'],
testMatch: ['**/**.node.(js|jsx|ts|tsx)'],
testMatch: ['**/**.(node|spec).(js|jsx|ts|tsx)'],
testEnvironment: 'jest-environment-jsdom-sixteen',
};

View File

@@ -37,20 +37,20 @@ import {act} from '@testing-library/react';
}
import {TestUtils} from 'flipper-plugin';
import * as MammalsPlugin from '../';
import * as MammalsPlugin from '..';
test('It can store rows', () => {
const {instance, ...plugin} = TestUtils.startPlugin(MammalsPlugin);
const {instance, sendEvent} = TestUtils.startPlugin(MammalsPlugin);
expect(instance.rows.get()).toEqual({});
expect(instance.selectedID.get()).toBeNull();
plugin.sendEvent('newRow', {
sendEvent('newRow', {
id: 1,
title: 'Dolphin',
url: 'http://dolphin.png',
});
plugin.sendEvent('newRow', {
sendEvent('newRow', {
id: 2,
title: 'Turtle',
url: 'http://turtle.png',
@@ -73,19 +73,23 @@ test('It can store rows', () => {
});
test('It can have selection and render details', async () => {
const {instance, renderer, act, ...plugin} = TestUtils.renderPlugin(
MammalsPlugin,
);
const {
instance,
renderer,
act,
sendEvent,
exportState,
} = TestUtils.renderPlugin(MammalsPlugin);
expect(instance.rows.get()).toEqual({});
expect(instance.selectedID.get()).toBeNull();
plugin.sendEvent('newRow', {
sendEvent('newRow', {
id: 1,
title: 'Dolphin',
url: 'http://dolphin.png',
});
plugin.sendEvent('newRow', {
sendEvent('newRow', {
id: 2,
title: 'Turtle',
url: 'http://turtle.png',
@@ -121,21 +125,19 @@ test('It can have selection and render details', async () => {
expect(await renderer.findByText('Extras')).not.toBeNull();
// Verify export
expect(plugin.exportState()).toMatchInlineSnapshot(`
Object {
"rows": Object {
"1": Object {
"id": 1,
"title": "Dolphin",
"url": "http://dolphin.png",
expect(exportState()).toEqual({
rows: {
'1': {
id: 1,
title: 'Dolphin',
url: 'http://dolphin.png',
},
"2": Object {
"id": 2,
"title": "Turtle",
"url": "http://turtle.png",
'2': {
id: 2,
title: 'Turtle',
url: 'http://turtle.png',
},
},
"selection": "2",
}
`);
selection: '2',
});
});

View File

@@ -19,12 +19,10 @@ import {
} from 'flipper';
import React, {memo} from 'react';
import {FlipperClient, usePlugin, createState, useValue} from 'flipper-plugin';
type Id = number;
import {PluginClient, usePlugin, createState, useValue} from 'flipper-plugin';
type Row = {
id: Id;
id: number;
title: string;
url: string;
};
@@ -33,20 +31,8 @@ type Events = {
newRow: Row;
};
function renderSidebar(row: Row) {
return (
<Panel floating={false} heading={'Extras'}>
<ManagedDataInspector data={row} expandRoot={true} />
</Panel>
);
}
type PersistedState = {
[key: string]: Row;
};
export function plugin(client: FlipperClient<Events, {}>) {
const rows = createState<PersistedState>({}, {persist: 'rows'});
export function plugin(client: PluginClient<Events, {}>) {
const rows = createState<Record<string, Row>>({}, {persist: 'rows'});
const selectedID = createState<string | null>(null, {persist: 'selection'});
client.addMenuEntry(
@@ -90,8 +76,8 @@ export function plugin(client: FlipperClient<Events, {}>) {
export function Component() {
const instance = usePlugin(plugin);
const selectedID = useValue(instance.selectedID);
const rows = useValue(instance.rows);
const selectedID = useValue(instance.selectedID);
return (
<Container>
@@ -110,6 +96,14 @@ export function Component() {
);
}
function renderSidebar(row: Row) {
return (
<Panel floating={false} heading={'Extras'}>
<ManagedDataInspector data={row} expandRoot={true} />
</Panel>
);
}
type CardProps = {
onSelect: (id: number) => void;
selected: boolean;

View File

@@ -37,7 +37,7 @@ import {
Layout,
} from 'flipper';
import {FlipperClient, createState, usePlugin, useValue} from 'flipper-plugin';
import {PluginClient, createState, usePlugin, useValue} from 'flipper-plugin';
const Waiting = styled(FlexBox)({
width: '100%',
@@ -74,7 +74,7 @@ type FocusInfo = {
treeNodeIndexPath?: number[];
};
export function plugin(client: FlipperClient<Events, {}>) {
export function plugin(client: PluginClient<Events, {}>) {
const generations = createState<{[id: string]: TreeGeneration}>(
{},
{persist: 'generations'},