forked from taskrabbit/ReactNativeSampleApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.js
More file actions
110 lines (95 loc) · 2.39 KB
/
Copy pathbootstrap.js
File metadata and controls
110 lines (95 loc) · 2.39 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
var server = require("./server");
var dispatcher = require("../helpers/dispatcher");
var assign = require('object-assign');
var Bootstrap = function() {
this.actions = [];
};
Bootstrap.prototype.login = function() {
this.addAction("LOGIN_USER", dispatcher.login());
return this;
};
Bootstrap.prototype.time = function(time, timezoneOffsetHours) {
this.addAction("STUB_TIME", {time: time, timezoneOffset: -(timezoneOffsetHours * 60)});
return this;
};
Bootstrap.prototype.nav = function(path) {
this.addAction("LAUNCH_ROUTE_PATH", {routePath: path});
return this;
};
Bootstrap.prototype.show = function(componentName, props, state) {
var defaultProps = {
currentRoute: {}
};
this.addAction("TEST_COMPONENT_ROUTE", {
routeUnderTest: {
component: componentName,
passProps: assign(defaultProps, props),
setState: state
}
});
return this;
};
Bootstrap.prototype.addAction = function(type, options) {
this.actions.push({type: type, options: options});
return this;
};
Bootstrap.prototype.launch = function* (driver, options) {
if (options && options.debug === true) {
yield this.debug(driver);
}
var url = 'test/bootstrap.json';
for (var i=0; i<this.actions.length; i++) {
var action = this.actions[i];
if (i > 0) {
yield driver.sleep(50);
}
server.get(url, { actions: [action] });
yield driver.elementById('Bootstrap').click();
}
return this;
};
Bootstrap.prototype.debug = function* (driver) {
console.log('Bootstrap debugging');
for (var i=0; i<50; i++) {
// Open the menu
try {
yield driver.elementById('DevMenu').click();
break;
}
catch (e) {
// wait for a bit
yield driver.sleep(500);
}
}
for (var i=0; i<50; i++) {
// Click on the Menu
// If Debug in Chrome is not displayed then Disable Chrome Debugging should be
try {
try {
yield driver.elementById('Debug in Chrome').click();
}
catch (e) {
yield driver.elementById('Disable Chrome Debugging');
}
break;
}
catch (e) {
// wait for a bit
yield driver.sleep(500);
}
}
for (var i=0; i<50; i++) {
// wait til it reloads
try {
yield driver.elementById('ResetTest');
break;
}
catch (e) {
// wait for a bit
yield driver.sleep(500);
}
}
};
module.exports = function() {
return new Bootstrap();
};