forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainPage.ts
More file actions
63 lines (52 loc) · 2.44 KB
/
mainPage.ts
File metadata and controls
63 lines (52 loc) · 2.44 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
import { Page } from "tns-core-modules/ui/page";
import * as trace from "tns-core-modules/trace";
import * as tests from "../testRunner";
import { Label } from "tns-core-modules/ui/label";
import * as application from "tns-core-modules/application";
import * as platform from "tns-core-modules/platform";
trace.enable();
trace.addCategories(trace.categories.Test + "," + trace.categories.Error);
// When debugging
// trace.setCategories(trace.categories.concat(
// trace.categories.Test,
// trace.categories.Navigation,
// trace.categories.Transition,
// trace.categories.NativeLifecycle,
// trace.categories.ViewHierarchy,
// trace.categories.VisualTreeEvents
// ));
let page = new Page();
page.id = "mainPage";
page.on(Page.navigatedToEvent, onNavigatedTo);
function runTests() {
setTimeout(() => tests.runAll(''), 10);
}
function onNavigatedTo(args) {
let label = new Label();
label.text = "Running non-UI tests...";
page.content = label;
args.object.off(Page.navigatedToEvent, onNavigatedTo);
// Request permission to write test-results.xml file for API >= 23
// if (platform.isAndroid && parseInt(platform.device.sdkVersion) >= 23) {
// let handler = (args: application.AndroidActivityRequestPermissionsEventData) => {
// application.android.off(application.AndroidApplication.activityRequestPermissionsEvent, handler);
// if (args.requestCode === 1234 && args.grantResults.length > 0 && args.grantResults[0] === android.content.pm.PackageManager.PERMISSION_GRANTED) {
// runTests();
// } else {
// trace.write("Permission for write to external storage not granted!", trace.categories.Error, trace.messageType.error);
// }
// };
// application.android.on(application.AndroidApplication.activityRequestPermissionsEvent, handler);
// if ((<any>android.support.v4.content.ContextCompat).checkSelfPermission(application.android.currentContext, (<any>android).Manifest.permission.WRITE_EXTERNAL_STORAGE) !== android.content.pm.PackageManager.PERMISSION_GRANTED) {
// (<any>android.support.v4.app.ActivityCompat).requestPermissions(application.android.currentContext, [(<any>android).Manifest.permission.WRITE_EXTERNAL_STORAGE], 1234);
// } else {
// runTests();
// }
// } else {
// runTests();
// }
runTests();
}
export function createPage() {
return page;
}