Skip to content

Commit 0f7a923

Browse files
licanhuamsftbot[bot]
authored andcommitted
Support e2e test - webdriverio (#2975)
* move e2e testapp and test to package/E2ETest * fix fail to create link if node_modules doesn't exist
1 parent 3dc2911 commit 0f7a923

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+7296
-320
lines changed

packages/E2ETest/.eslintignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/node_modules
2+
wdio
3+
app
4+
wdio.conf.js
5+
hasteImpl.js
6+
metro.config.js
7+
postinstall.js

packages/E2ETest/.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
extends: "@react-native-community",
3+
rules:{
4+
"react-native/no-inline-styles" : 0,
5+
}
6+
};

packages/E2ETest/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
/windows/ReactUWPTestApp/Generated Files/
3+
/build
4+
reports

packages/E2ETest/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

packages/E2ETest/.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"useTabs": false,
3+
"printWidth": 80,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"trailingComma": "es5"
7+
}

packages/E2ETest/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# E2ETest project
2+
3+
This package is not published, and is just used to verify a standalone app

packages/E2ETest/app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "ReactUWPTestApp",
3+
"displayName": "ReactUWPTestApp"
4+
}

packages/E2ETest/app/Consts.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const APP_NAME = 'ReactUWPTestApp';
2+
3+
// Framework
4+
export const SEARCH_BUTTON = 'SearchButton';
5+
export const HOME_BUTTON = '_HomeButton';
6+
export const REACT_CONTROL_ERROR_TEST_ID = 'ReactControlErrorMessage';
7+
8+
// UnknownTestPage
9+
export const UNKNOWN_TESTPAGE = 'UnknownTestPage';
10+
11+
// TextInputTestPage
12+
export const TEXTINPUT_TESTPAGE = 'TextInputTestPage';
13+
14+
export const TEXTINPUT_ON_TEXTINPUT = 'TextInput';
15+
16+
// LoginTestPage
17+
export const LOGIN_TESTPAGE = 'LoginTestPage';
18+
export const USERNAME_ON_LOGIN = 'UserName';
19+
export const PASSWORD_ON_LOGIN = 'Password';
20+
export const SUBMIT_ON_LOGIN = 'Submit';
21+
export const LOGINRESULT_ON_LOGIN = 'Result';
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import React, { useState } from 'react';
7+
import { Text, TextInput, View, StyleSheet, TouchableOpacity } from 'react-native';
8+
import { USERNAME_ON_LOGIN, PASSWORD_ON_LOGIN, SUBMIT_ON_LOGIN, LOGINRESULT_ON_LOGIN } from './Consts';
9+
10+
const styles = StyleSheet.create({
11+
container: {
12+
padding: 20
13+
},
14+
input: {
15+
height: 40,
16+
backgroundColor: 'rgba(225,225,225,0.2)',
17+
marginBottom: 10,
18+
padding: 10,
19+
color: '#fff'
20+
},
21+
buttonContainer: {
22+
backgroundColor: '#2980b6',
23+
paddingVertical: 15
24+
},
25+
buttonText: {
26+
color: '#fff',
27+
textAlign: 'center',
28+
fontWeight: '700'
29+
}
30+
});
31+
32+
export function LoginTestPage() {
33+
const [loginState, setLoginState] = useState('');
34+
const [userName, setUserName] = useState('');
35+
36+
const onPress = () => {
37+
if (userName === 'username') {
38+
setLoginState('Success')
39+
} else {
40+
setLoginState('Fail');
41+
}
42+
};
43+
return (
44+
<View>
45+
<TextInput style={styles.input}
46+
placeholder='Email or Mobile Num'
47+
placeholderTextColor='rgba(225,225,225,0.7)'
48+
testID={USERNAME_ON_LOGIN}
49+
onChange={(text) => { setUserName(text.nativeEvent.text) }} />
50+
51+
<TextInput style={styles.input}
52+
placeholder='Password'
53+
testID={PASSWORD_ON_LOGIN}
54+
placeholderTextColor='rgba(225,225,225,0.7)'
55+
secureTextEntry />
56+
57+
<TouchableOpacity style={styles.buttonContainer}
58+
testID={SUBMIT_ON_LOGIN}
59+
onPress={onPress}>
60+
<Text style={styles.buttonText}>LOGIN</Text>
61+
</TouchableOpacity>
62+
63+
<Text testID={LOGINRESULT_ON_LOGIN}>{loginState}</Text>
64+
</View >);
65+
}

packages/E2ETest/app/TestApp.tsx

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import React, { useState } from "react";
7+
import TestPages, { ITestPage } from './TestPages'
8+
import { TouchableOpacity, Text, View, TextInput, FlatList, Button, StyleSheet } from 'react-native'
9+
import { SEARCH_BUTTON, HOME_BUTTON } from './Consts'
10+
11+
12+
interface TestPageListProps {
13+
onNavigateTo: (pageTestId: string) => void,
14+
testPages: ITestPage[]
15+
}
16+
17+
function TestPageList(props: TestPageListProps) {
18+
const [filter, setFilter] = useState("");
19+
20+
const _renderItem = ({ item }: {item: ITestPage}) => (
21+
<TouchableOpacity onPress={() => { props.onNavigateTo(item.testId) }} testID={item.testId}>
22+
<View>
23+
<Text>{item.description}</Text>
24+
</View>
25+
</TouchableOpacity >
26+
);
27+
28+
const data = props.testPages.filter((item: ITestPage) => !filter || (item.testId && item.testId.includes(filter)) || (item.description && item.description.includes(filter)))
29+
30+
return (
31+
<View>
32+
<TextInput placeholder='Search test page' onChangeText={(text) => setFilter(text)} value={filter} testID={SEARCH_BUTTON} />
33+
<FlatList<ITestPage> data={data} renderItem={_renderItem} keyExtractor={(item) => item.testId}/>
34+
</View>)
35+
}
36+
37+
interface TestPageDetailProps {
38+
testPage: ITestPage
39+
}
40+
41+
function TestPageDetail(props: TestPageDetailProps) {
42+
return <props.testPage.content />
43+
}
44+
45+
interface HeaderProps {
46+
onNavigateTo: (pageTestId: string) => void,
47+
description: string
48+
}
49+
50+
function Header(props: HeaderProps) {
51+
return (
52+
<View style={styles.headerContainer}>
53+
<View style={styles.header}>
54+
<View style={styles.headerCenter}>
55+
<Text style={styles.title}>{props.description}</Text>
56+
</View>
57+
<Button title='Home' onPress={() => { props.onNavigateTo('') }} testID={HOME_BUTTON} />
58+
</View>
59+
</View>);
60+
}
61+
62+
const styles = StyleSheet.create({
63+
headerContainer: {
64+
borderBottomWidth: StyleSheet.hairlineWidth,
65+
borderBottomColor: '#96969A',
66+
},
67+
header: {
68+
height: 40,
69+
flexDirection: 'row'
70+
},
71+
headerLeft: {},
72+
headerCenter: {
73+
flex: 1,
74+
position: 'absolute',
75+
top: 7,
76+
left: 0,
77+
right: 0
78+
},
79+
title: {
80+
fontSize: 19,
81+
fontWeight: '600',
82+
textAlign: 'center'
83+
},
84+
testPageContainer: {
85+
flex: 1
86+
}
87+
});
88+
89+
90+
export default function TestApp() {
91+
const [toPageTestId, setToPageTestId] = useState("");
92+
93+
const _onNavigateTo = (pageTestId: string) => { setToPageTestId(pageTestId) };
94+
95+
if (toPageTestId.length > 0) {
96+
const page = TestPages.filter(testPage => testPage.testId === toPageTestId)[0];
97+
return (
98+
<View style={styles.testPageContainer}>
99+
<Header onNavigateTo={() => { _onNavigateTo('') }} description={page.description} />
100+
<TestPageDetail testPage={page} />
101+
</View>)
102+
} else {
103+
return (
104+
<View style={styles.testPageContainer}>
105+
<Header onNavigateTo={() => { }} description='Home' />
106+
<TestPageList testPages={TestPages} onNavigateTo={(testPageId) => { _onNavigateTo(testPageId) }} />
107+
</View>)
108+
}
109+
}

0 commit comments

Comments
 (0)