Network Plugin - New functions to import, export and clear Routes (#1855)

Summary:
In the network plugin, add features to import and export routes as described in issue https://github.com/facebook/flipper/issues/1651

Primary use case is that external testers (such as QA teams) would be able to create test data, convert it to mocks and save the mocks to make bug fixes easier for devs.

Here is a screenshot showing location of buttons to perform import/export (and clearing) of mock routes:

![image](https://user-images.githubusercontent.com/337874/105658269-cb58ed80-5e8b-11eb-8118-f13efc96bf6d.png)

Here is another screenshot showing export dialog:

![image](https://user-images.githubusercontent.com/337874/105657733-afa11780-5e8a-11eb-9725-120617e1dd71.png)

Changelog: [Network] Mock routes can now be imported and exported. Thanks bizzguy!

Pull Request resolved: https://github.com/facebook/flipper/pull/1855

Test Plan:
Performed manual testing

- create new mocks
- export mocks
- clear mocks
- import mocks
- verify that mocks still work by making GET/POST requests in sample app

Performed various permutations of above manual tests, including restarting Flipper at various points to ensure that test plan still worked.  Also performed visual inspection of exported files to verify correctness.

Would be very interested in learning how to create automated tests for this functionality.

Reviewed By: passy

Differential Revision: D26072928

Pulled By: mweststrate

fbshipit-source-id: 51bd5e19e78d830b94add850d5dc9b9e45fa6fad
This commit is contained in:
bizzguy
2021-01-26 05:28:30 -08:00
committed by Facebook GitHub Bot
parent 14997a5b98
commit 6df117ba04
4 changed files with 151 additions and 52 deletions

View File

@@ -7,12 +7,15 @@
* @format
*/
import {FlexColumn, Button, styled, Layout} from 'flipper';
import {FlexColumn, Button, styled, Layout, Spacer} from 'flipper';
import {ManageMockResponsePanel} from './ManageMockResponsePanel';
import {Route, Request, Response} from './types';
import React from 'react';
import {NetworkRouteContext} from './index';
import {useContext} from 'react';
type Props = {
routes: {[id: string]: Route};
onHide: () => void;
@@ -39,6 +42,7 @@ const Row = styled(FlexColumn)({
});
export function MockResponseDialog(props: Props) {
const networkRouteManager = useContext(NetworkRouteContext);
return (
<Layout.Container pad width={1200}>
<Title>Mock Network Responses</Title>
@@ -50,7 +54,32 @@ export function MockResponseDialog(props: Props) {
responses={props.responses}
/>
</Layout.Horizontal>
<Layout.Horizontal>
<Layout.Horizontal gap>
<Button
compact
padded
onClick={() => {
networkRouteManager.importRoutes();
}}>
Import
</Button>
<Button
compact
padded
onClick={() => {
networkRouteManager.exportRoutes();
}}>
Export
</Button>
<Button
compact
padded
onClick={() => {
networkRouteManager.clearRoutes();
}}>
Clear
</Button>
<Spacer />
<Button compact padded onClick={props.onHide}>
Close
</Button>