Summary: Note: this is to be stacked upon https://github.com/facebook/flipper/pull/1479 Note: this PR will probably not succeed against FB internal flipper, as I'm pretty sure there are more call sites that need to be updated. So consider this WIP Currently connection errors are managed in the connection reducers, and are displayed through their own means, the error bar. Showing console.errors is also hooked up to this mechanism in FB internal flipper, but not at all in the OSS version, which means that some connection errors are never shown to the user. Besides that there is a notification system that is used by for example the crash reporter and plugin updater. Having effectively (at least) two notifications mechanisms is confusing and error prone. This PR unifies both approaches, and rather than having the connection reducer manage it's own errors, it leverages the more generic notifications reducer. Since, in the previous PR, console errors and warnings have become user facing (even in OSS and production builds, which wasn't the case before), there is no need anymore for a separate error bar. I left the notifications mechanism itself as-is, but as discussed in the Sandy project the notification screen will probably be overhauled, and the system wide notifications will become in-app notifications. ## Changelog Pull Request resolved: https://github.com/facebook/flipper/pull/1483 Test Plan: Only updated the unit tests at this point. Manual tests still need to be done. Reviewed By: passy Differential Revision: D23220896 Pulled By: mweststrate fbshipit-source-id: 8ea37cf69ce9605dc232ca90afe9e2f70da26652
110 lines
3.3 KiB
TypeScript
110 lines
3.3 KiB
TypeScript
/**
|
|
* 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 reducer from '../connections';
|
|
import {State, selectPlugin} from '../connections';
|
|
import BaseDevice from '../../devices/BaseDevice';
|
|
import MacDevice from '../../devices/MacDevice';
|
|
import {FlipperDevicePlugin} from '../../plugin';
|
|
import MetroDevice from '../../devices/MetroDevice';
|
|
|
|
test('doing a double REGISTER_DEVICE keeps the last', () => {
|
|
const device1 = new BaseDevice('serial', 'physical', 'title', 'Android');
|
|
const device2 = new BaseDevice('serial', 'physical', 'title2', 'Android');
|
|
const initialState: State = reducer(undefined, {
|
|
type: 'REGISTER_DEVICE',
|
|
payload: device1,
|
|
});
|
|
expect(initialState.devices.length).toBe(1);
|
|
expect(initialState.devices[0]).toBe(device1);
|
|
|
|
const endState = reducer(initialState, {
|
|
type: 'REGISTER_DEVICE',
|
|
payload: device2,
|
|
});
|
|
expect(endState.devices.length).toBe(1);
|
|
expect(endState.devices[0]).toBe(device2);
|
|
});
|
|
|
|
test('register, remove, re-register a metro device works correctly', () => {
|
|
const device1 = new MetroDevice('http://localhost:8081', undefined);
|
|
let state: State = reducer(undefined, {
|
|
type: 'REGISTER_DEVICE',
|
|
payload: device1,
|
|
});
|
|
expect(state.devices.length).toBe(1);
|
|
expect(state.devices[0].displayTitle()).toBe('React Native');
|
|
|
|
const archived = device1.archive();
|
|
state = reducer(state, {
|
|
type: 'UNREGISTER_DEVICES',
|
|
payload: new Set([device1.serial]),
|
|
});
|
|
expect(state.devices.length).toBe(0);
|
|
|
|
state = reducer(state, {
|
|
type: 'REGISTER_DEVICE',
|
|
payload: archived,
|
|
});
|
|
expect(state.devices.length).toBe(1);
|
|
expect(state.devices[0].displayTitle()).toBe('React Native (Offline)');
|
|
|
|
state = reducer(state, {
|
|
type: 'REGISTER_DEVICE',
|
|
payload: new MetroDevice('http://localhost:8081', undefined),
|
|
});
|
|
expect(state.devices.length).toBe(1);
|
|
expect(state.devices[0].displayTitle()).toBe('React Native');
|
|
});
|
|
|
|
test('triggering REGISTER_DEVICE before REGISTER_PLUGINS still registers device plugins', () => {
|
|
class TestDevicePlugin extends FlipperDevicePlugin<any, any, any> {
|
|
static id = 'test';
|
|
static supportsDevice() {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
const stateWithDevice = reducer(undefined, {
|
|
type: 'REGISTER_DEVICE',
|
|
payload: new MacDevice(),
|
|
});
|
|
|
|
const endState = reducer(stateWithDevice, {
|
|
type: 'REGISTER_PLUGINS',
|
|
payload: [TestDevicePlugin],
|
|
});
|
|
|
|
expect(endState.devices[0].devicePlugins).toEqual(['test']);
|
|
});
|
|
|
|
test('selectPlugin sets deepLinkPayload correctly', () => {
|
|
const state = reducer(
|
|
undefined,
|
|
selectPlugin({selectedPlugin: 'myPlugin', deepLinkPayload: 'myPayload'}),
|
|
);
|
|
expect(state.deepLinkPayload).toBe('myPayload');
|
|
});
|
|
|
|
test('UNREGISTER_DEVICE removes device', () => {
|
|
const device = new BaseDevice('serial', 'physical', 'title', 'Android');
|
|
const initialState: State = reducer(undefined, {
|
|
type: 'REGISTER_DEVICE',
|
|
payload: new BaseDevice('serial', 'physical', 'title', 'Android'),
|
|
});
|
|
|
|
expect(initialState.devices).toEqual([device]);
|
|
const endState = reducer(initialState, {
|
|
type: 'UNREGISTER_DEVICES',
|
|
payload: new Set(['serial']),
|
|
});
|
|
|
|
expect(endState.devices).toEqual([]);
|
|
});
|