-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathApp.js
More file actions
222 lines (200 loc) · 8.51 KB
/
App.js
File metadata and controls
222 lines (200 loc) · 8.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @format
*/
// TODO: JSI does not allow property setters to return a value, which causes Chakra to throw errors in strict mode
// https://github.com/microsoft/react-native-winrt/issues/8
// 'use strict';
import React, { Component } from 'react';
import {
SafeAreaView,
ScrollView,
View,
Text,
Button
} from 'react-native';
import { Scenario } from './Scenario';
import { styles } from './Styles';
import { TestResult } from './TestCommon'
import { makeEnumTestScenarios } from './EnumTests'
import { makePropertiesTestScenarios } from './PropertiesTests'
import { makeBasicFunctionTestScenarios } from './BasicFunctionTests'
import { makeArrayTestScenarios } from './ArrayTests'
import { makeDelegateAndEventTestScenarios } from './DelegateAndEventTests'
import { makeAsyncTestScenarios } from './AsyncTests'
import { makeCollectionsTestScenarios } from './CollectionsTests'
import { makeInheritanceTestScenarios } from './InheritanceTests'
class App extends Component {
test = new TestComponent.Test();
completedCount = 0;
passCount = 0;
failures = "Failed Scenarios:\r\n";
testSuites = [
{
name: "Enum Tests",
scenarios: makeEnumTestScenarios(this),
}, {
name: "Property Tests",
scenarios: makePropertiesTestScenarios(this),
}, {
name: "Function Tests",
scenarios: makeBasicFunctionTestScenarios(this),
}, {
name: "Array Tests",
scenarios: makeArrayTestScenarios(this),
}, {
name: "Delegate Tests",
scenarios: makeDelegateAndEventTestScenarios(this),
}, {
name: "Async Tests",
scenarios: makeAsyncTestScenarios(this),
}, {
name: "Collections Tests",
scenarios: makeCollectionsTestScenarios(this),
}, {
name: "Inheritance Tests",
scenarios: makeInheritanceTestScenarios(this),
}
]
scenarioNameToTestSuiteMap = this.testSuites.reduce((acc, testSuite) => {
testSuite.scenarios.forEach(scenario => {
acc[scenario.name] = testSuite.name
})
return acc;
}, {});
state = {
completedCount: 0,
passCount: 0,
testSuiteCompletedCount: this.testSuites.reduce((acc, testSuite) => { return {...acc, [testSuite.name]: 0}}, {}),
testSuitePassCount: this.testSuites.reduce((acc, testSuite) => { return {...acc, [testSuite.name]: 0}}, {}),
testSuiteVisibility: this.testSuites.reduce((acc, testSuite) => { return {...acc, [testSuite.name]: false}}, {}),
filterText: "",
};
runSync(scenario, fn) {
let previousResult = scenario.result;
var result = TestResult.Fail;
try {
fn();
result = TestResult.Pass;
} catch (e) {
scenario.failureText = e.message;
}
scenario.result = result;
scenario.emit('completed');
this.onSingleTestCompleted(scenario, previousResult);
}
runAsync(scenario, fn) {
let previousResult = scenario.result;
var result = TestResult.Fail;
new Promise(fn).then(() => {
result = TestResult.Pass;
scenario.result = result;
scenario.emit('completed');
this.onSingleTestCompleted(scenario, previousResult);
}).catch(e => {
scenario.failureText = e.message;
scenario.result = result;
scenario.emit('completed');
this.onSingleTestCompleted(scenario, previousResult);
})
}
onSingleTestCompleted(scenario, previousResult) {
const testSuiteName = this.scenarioNameToTestSuiteMap[scenario.name];
if (previousResult === TestResult.NotRun) ++this.completedCount;
let resultState = {
completedCount: this.completedCount,
passCount: this.passCount,
testSuiteCompletedCount: this.state.testSuiteCompletedCount,
testSuitePassCount: this.state.testSuitePassCount,
}
if (previousResult === TestResult.NotRun) resultState.testSuiteCompletedCount[testSuiteName] = this.state.testSuiteCompletedCount[testSuiteName] + 1;
if (scenario.result === TestResult.Pass && previousResult !== TestResult.Pass) {
++this.passCount;
resultState.passCount = this.passCount;
resultState.testSuitePassCount[testSuiteName] = this.state.testSuitePassCount[testSuiteName] + 1;
} else if (scenario.result === TestResult.Fail && previousResult === TestResult.Pass){
--this.passCount;
resultState.passCount = this.passCount;
resultState.testSuitePassCount[testSuiteName] = this.state.testSuitePassCount[testSuiteName] - 1;
this.failures += scenario.name + "\r\n";
}
this.setState(resultState);
}
allScenarios() {
return this.testSuites.reduce((acc, val) => acc.concat(val.scenarios), []);
}
inProgress() {
return this.state.completedCount != this.allScenarios().length;
}
passed() {
return this.state.passCount == this.allScenarios().length;
}
resultText() {
if (!this.inProgress() && !this.passed()) {
TestComponent.Test.logFailures(this.failures);
}
return this.inProgress() ? 'In Progress' :
this.passed() ? 'Pass' : 'Fail';
}
textStyle() {
return this.inProgress() ? styles.progressText :
this.passed() ? styles.passText : styles.failText;
}
componentDidMount() {
for (let scenario of this.allScenarios()) {
scenario.invoke(scenario);
}
}
toggleTestSuiteVisibility(testSuite) {
this.setState({
testSuiteVisibility: {
...this.state.testSuiteVisibility,
[testSuite.name]: !this.state.testSuiteVisibility[testSuite.name]
},
})
}
render() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: 'white' }}>
<View style={styles.headerBanner}>
<Text style={{ fontSize: 22 }}>WinRT Projection Tests</Text>
</View>
<ScrollView style={styles.scrollView}>
<View style={[styles.listEntry, { alignSelf: 'center' }]}>
<Text style={[styles.rowItem]}>Pass Rate: {this.state.passCount * 100 / this.state.completedCount}%</Text>
<Text style={[styles.rowItem, this.textStyle()]}>{this.resultText()}</Text>
</View>
{
this.testSuites.map((testSuite, idx) => (
<View key={testSuite.name}>
<View style={styles.listEntry}>
<Text style={[styles.rowItem, {fontWeight: 'bold'}]}>{testSuite.name}</Text>
<Text style={[styles.rowItem, {flex: 1}]}>{
this.state.testSuitePassCount[testSuite.name]
+ "/"
+ this.state.testSuiteCompletedCount[testSuite.name]
+ " passed. "
+ (testSuite.scenarios.length - this.state.testSuiteCompletedCount[testSuite.name])
+ " pending."
}</Text>
<Button style={[styles.rowItem, {flex: 1}]}
title={this.state.testSuiteVisibility[testSuite.name] ? "Hide all tests" : "Show all tests"}
onPress={() => this.toggleTestSuiteVisibility(testSuite)}/>
</View>
{
testSuite.scenarios.map((scenario, idx) => (
this.state.testSuiteVisibility[testSuite.name] || scenario.result !== TestResult.Pass
? <Scenario key={scenario.name} scenario={scenario} />
: <View key={idx} style={{marginHorizontal: 1}}/>
))
}
</View>
))
}
</ScrollView>
</SafeAreaView>
);
}
}
export default App;