Make sure Sandy Device Plugins can be unit testsed
Summary: Add unit tests to verify that the unit test utilities for for Sandy device plugins work as expected. Fixed a bug revealed by that and cleaned up some TODO's Reviewed By: jknoxville, passy, nikoant Differential Revision: D22693928 fbshipit-source-id: 93162db19d826d0cd7f642cef1447fd756261ac8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
91ed4e31c0
commit
1e956e1bf5
60
desktop/flipper-plugin/src/__tests__/DeviceTestPlugin.tsx
Normal file
60
desktop/flipper-plugin/src/__tests__/DeviceTestPlugin.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import {DevicePluginClient, Device} from '../plugin/DevicePlugin';
|
||||
import {usePlugin} from '../plugin/PluginContext';
|
||||
import {createState, useValue} from '../state/atom';
|
||||
|
||||
export function supportsDevice(_device: Device) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function devicePlugin(client: DevicePluginClient) {
|
||||
const logStub = jest.fn();
|
||||
const activateStub = jest.fn();
|
||||
const deactivateStub = jest.fn();
|
||||
const destroyStub = jest.fn();
|
||||
const state = createState(
|
||||
{
|
||||
count: 0,
|
||||
},
|
||||
{
|
||||
persist: 'counter',
|
||||
},
|
||||
);
|
||||
|
||||
client.device.onLogEntry((entry) => {
|
||||
state.update((d) => {
|
||||
d.count++;
|
||||
});
|
||||
logStub(entry);
|
||||
});
|
||||
client.onActivate(activateStub);
|
||||
client.onDeactivate(deactivateStub);
|
||||
client.onDestroy(destroyStub);
|
||||
|
||||
return {
|
||||
logStub,
|
||||
activateStub,
|
||||
deactivateStub,
|
||||
destroyStub,
|
||||
state,
|
||||
};
|
||||
}
|
||||
|
||||
export function Component() {
|
||||
const api = usePlugin(devicePlugin);
|
||||
const count = useValue(api.state).count;
|
||||
|
||||
// @ts-expect-error
|
||||
api.bla;
|
||||
|
||||
return <h1>Hi from test plugin {count}</h1>;
|
||||
}
|
||||
Reference in New Issue
Block a user