Skip to content

Commit

Permalink
Add test for Network Inspect enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Feb 5, 2019
1 parent 65f1006 commit 3d1a852
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 26 deletions.
29 changes: 28 additions & 1 deletion __e2e__/TestApp/__e2e__/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Main', () => {

describe('Context Menu', () => {
const delay200 = () => delay(200);
const delay500 = () => delay(500);
it('should show AsyncStorage content as expected', async () => {
const { client } = rndebugger;
await client.execute(() => window.invokeDevMethod('showAsyncStorage')).then(delay200);
Expand All @@ -26,7 +27,7 @@ describe('Main', () => {
logs.some(log => log.message.indexOf('[RNDebugger] No AsyncStorage content.') > -1)
).toBeTruthy();

await element(by.id('navigate-async-storage'))
await element(by.id('navigate-context-menu'))
.tap()
.then(delay200);

Expand All @@ -38,6 +39,10 @@ describe('Main', () => {
it('should clear AsyncStorage as expected', async () => {
const { client } = rndebugger;

await element(by.id('navigate-context-menu'))
.tap()
.then(delay500);

await client.execute(() => window.invokeDevMethod('clearAsyncStorage')).then(delay200);
await client.execute(() => window.invokeDevMethod('showAsyncStorage')).then(delay200);
const logs = await client.getRenderProcessLogs();
Expand All @@ -46,5 +51,27 @@ describe('Main', () => {
logs.some(log => log.message.indexOf('[RNDebugger] No AsyncStorage content.') > -1)
).toBeTruthy();
});

it('should send Network request as expected if Network Inspsect enabled', async () => {
const { client } = rndebugger;

await element(by.id('navigate-context-menu'))
.tap()
.then(delay500);
await element(by.id('send-request'))
.tap()
.then(delay200);

await client.execute(() => window.invokeDevMethod('networkInspect')).then(() => delay(300));
const logs = await client.getRenderProcessLogs();
// Print renderer process logs
expect(
logs.some(
log =>
// NOTE: https://github.com/electron/spectron/issues/282
log.message.indexOf('[RNDebugger]') > -1
)
).toBeTruthy();
});
});
});
4 changes: 2 additions & 2 deletions __e2e__/TestApp/js/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createStackNavigator, createAppContainer } from 'react-navigation';
import Home from './Home';
import TestAsyncStorage from './containers/TestAsyncStorage';
import TestContextMenu from './containers/TestContextMenu';

const AppNavigator = createStackNavigator(
{
Home: { screen: Home },
TestAsyncStorage: { screen: TestAsyncStorage },
TestContextMenu: { screen: TestContextMenu },
},
{
initialRouteName: 'Home',
Expand Down
6 changes: 3 additions & 3 deletions __e2e__/TestApp/js/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default class Home extends React.Component {
return (
<View testID="home" style={styles.container}>
<Button
testID="navigate-async-storage"
title="Test Async Storage"
onPress={() => navigation.navigate('TestAsyncStorage')}
testID="navigate-context-menu"
title="Test Context Menu"
onPress={() => navigation.navigate('TestContextMenu')}
/>
</View>
);
Expand Down
20 changes: 0 additions & 20 deletions __e2e__/TestApp/js/containers/TestAsyncStorage.js

This file was deleted.

27 changes: 27 additions & 0 deletions __e2e__/TestApp/js/containers/TestContextMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { StyleSheet, View, AsyncStorage, Button } from 'react-native';

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#333',
justifyContent: 'center',
alignItems: 'center',
},
});

export default class TestContextMenu extends React.Component {
componentDidMount() {
AsyncStorage.setItem('some', 'key');
}
sendRequest() {
fetch('http://localhost:8081');
}
render() {
return (
<View style={styles.container}>
<Button testID="send-request" title="Send request" />
</View>
);
}
}

0 comments on commit 3d1a852

Please sign in to comment.