Expose current connection status to Sandy plugins
Summary: Introduced `isConnected` flag on device and plugin client to reflect whether a connection is still available for the plugins, or that they have been disconnected. Potentially we could expose the (readonly) `connected` state atom for this as well, or an `onDisconnect` event for device pugins, to create a responsive UI, but there might be no need for that, in which case this suffices. Reviewed By: nikoant Differential Revision: D26249346 fbshipit-source-id: b8486713fdf2fcd520488ce54f771bd038fd13f8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7e1bf0f58b
commit
bb529411b5
@@ -29,6 +29,9 @@ test('Devices can disconnect', async () => {
|
||||
return {
|
||||
counter,
|
||||
destroy,
|
||||
get isConnected() {
|
||||
return client.device.isConnected;
|
||||
},
|
||||
};
|
||||
},
|
||||
supportsDevice() {
|
||||
@@ -42,6 +45,9 @@ test('Devices can disconnect', async () => {
|
||||
const {device} = await createMockFlipperWithPlugin(deviceplugin);
|
||||
|
||||
device.sandyPluginStates.get(deviceplugin.id)!.instanceApi.counter.set(1);
|
||||
expect(
|
||||
device.sandyPluginStates.get(deviceplugin.id)!.instanceApi.isConnected,
|
||||
).toBe(true);
|
||||
|
||||
expect(device.isArchived).toBe(false);
|
||||
|
||||
@@ -49,6 +55,7 @@ test('Devices can disconnect', async () => {
|
||||
|
||||
expect(device.isArchived).toBe(true);
|
||||
const instance = device.sandyPluginStates.get(deviceplugin.id)!;
|
||||
expect(instance.instanceApi.isConnected).toBe(false);
|
||||
expect(instance).toBeTruthy();
|
||||
expect(instance.instanceApi.counter.get()).toBe(1); // state preserved
|
||||
expect(instance.instanceApi.destroy).toBeCalledTimes(0);
|
||||
@@ -126,6 +133,9 @@ test('clients can disconnect but preserve state', async () => {
|
||||
disconnect,
|
||||
counter,
|
||||
destroy,
|
||||
get isConnected() {
|
||||
return client.isConnected;
|
||||
},
|
||||
};
|
||||
},
|
||||
Component() {
|
||||
@@ -142,6 +152,7 @@ test('clients can disconnect but preserve state', async () => {
|
||||
expect(instance.instanceApi.destroy).toBeCalledTimes(0);
|
||||
expect(instance.instanceApi.connect).toBeCalledTimes(1);
|
||||
expect(instance.instanceApi.disconnect).toBeCalledTimes(0);
|
||||
expect(instance.instanceApi.isConnected).toBe(true);
|
||||
expect(client.connected.get()).toBe(true);
|
||||
|
||||
client.disconnect();
|
||||
@@ -150,6 +161,7 @@ test('clients can disconnect but preserve state', async () => {
|
||||
instance = client.sandyPluginStates.get(plugin.id)!;
|
||||
expect(instance).toBeTruthy();
|
||||
expect(instance.instanceApi.counter.get()).toBe(1); // state preserved
|
||||
expect(instance.instanceApi.isConnected).toBe(false);
|
||||
expect(instance.instanceApi.destroy).toBeCalledTimes(0);
|
||||
expect(instance.instanceApi.connect).toBeCalledTimes(1);
|
||||
expect(instance.instanceApi.disconnect).toBeCalledTimes(1);
|
||||
|
||||
Reference in New Issue
Block a user