Fixed re-enabling a still selected plugin

Summary: While testing manually discovered the sandy plugin infra din't cover the case that a plugin can be selected but not enabled at the same time. Added test and fixed that.

Reviewed By: nikoant

Differential Revision: D22308597

fbshipit-source-id: 6cef2b543013ee81cee449396d523dd9a657ad1c
This commit is contained in:
Michel Weststrate
2020-07-01 08:58:40 -07:00
committed by Facebook GitHub Bot
parent d16c6061c1
commit 581ddafd18
6 changed files with 69 additions and 31 deletions

View File

@@ -7,18 +7,17 @@
* @format
*/
import React, {useContext} from 'react';
import React from 'react';
import produce from 'immer';
import {FlipperPlugin} from '../plugin';
import {renderMockFlipperWithPlugin} from '../test-utils/createMockFlipperWithPlugin';
import {
SandyPluginContext,
SandyPluginDefinition,
FlipperClient,
TestUtils,
usePlugin,
} from 'flipper-plugin';
import {selectPlugin} from '../reducers/connections';
import {selectPlugin, starPlugin} from '../reducers/connections';
interface PersistedState {
count: 1;
@@ -132,6 +131,9 @@ test('PluginContainer can render Sandy plugins', async () => {
client,
store,
} = await renderMockFlipperWithPlugin(definition);
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
expect(renderer.baseElement).toMatchInlineSnapshot(`
<body>
<div>
@@ -164,8 +166,6 @@ test('PluginContainer can render Sandy plugins', async () => {
expect(pluginInstance.connectedStub).toBeCalledTimes(1);
expect(pluginInstance.disconnectedStub).toBeCalledTimes(0);
// TODO: check that messages have arrived T68683442
// select non existing plugin
act(() => {
store.dispatch(
@@ -176,6 +176,8 @@ test('PluginContainer can render Sandy plugins', async () => {
);
});
expect(client.rawSend).toBeCalledWith('deinit', {plugin: 'TestPlugin'});
expect(renderer.baseElement).toMatchInlineSnapshot(`
<body>
<div />
@@ -195,4 +197,36 @@ test('PluginContainer can render Sandy plugins', async () => {
});
expect(pluginInstance.connectedStub).toBeCalledTimes(2);
expect(pluginInstance.disconnectedStub).toBeCalledTimes(1);
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
// disable
act(() => {
store.dispatch(
starPlugin({
plugin: definition,
selectedApp: client.query.app,
}),
);
});
expect(pluginInstance.connectedStub).toBeCalledTimes(2);
expect(pluginInstance.disconnectedStub).toBeCalledTimes(2);
expect(client.rawSend).toBeCalledWith('deinit', {plugin: 'TestPlugin'});
// re-enable
act(() => {
store.dispatch(
starPlugin({
plugin: definition,
selectedApp: client.query.app,
}),
);
});
// note: this is the old pluginInstance, so that one is not reconnected!
expect(pluginInstance.connectedStub).toBeCalledTimes(2);
expect(pluginInstance.disconnectedStub).toBeCalledTimes(2);
expect(
client.sandyPluginStates.get('TestPlugin')!.instanceApi.connectedStub,
).toBeCalledTimes(1);
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
});