|
@@ -0,0 +1,117 @@
|
|
1
|
+const Utils = require('./Utils');
|
|
2
|
+const Android = require('./AndroidUtils');
|
|
3
|
+const testIDs = require('../playground/src/testIDs');
|
|
4
|
+const exec = require('shell-utils').exec;
|
|
5
|
+const _ = require('lodash');
|
|
6
|
+
|
|
7
|
+const { elementByLabel, elementById, sleep } = Utils;
|
|
8
|
+const IS_RELEASE = _.includes(process.argv, '--release');
|
|
9
|
+const KEY_CODE_R = 46;
|
|
10
|
+
|
|
11
|
+describe('application lifecycle test', () => {
|
|
12
|
+ beforeEach(async () => {
|
|
13
|
+ await device.relaunchApp();
|
|
14
|
+ });
|
|
15
|
+
|
|
16
|
+ it('push a screen to ensure its not there after reload', async () => {
|
|
17
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
18
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
19
|
+ await device.reloadReactNative();
|
|
20
|
+ await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
|
|
21
|
+ });
|
|
22
|
+
|
|
23
|
+ it(':android: relaunch from background', async () => {
|
|
24
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
25
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
26
|
+
|
|
27
|
+ await device.sendToHome();
|
|
28
|
+ await device.launchApp();
|
|
29
|
+
|
|
30
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
31
|
+ });
|
|
32
|
+
|
|
33
|
+ it(':android: relaunch after close with back button', async () => {
|
|
34
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
35
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
36
|
+
|
|
37
|
+ Android.pressBack();
|
|
38
|
+
|
|
39
|
+ await device.launchApp();
|
|
40
|
+ await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
|
|
41
|
+ });
|
|
42
|
+
|
|
43
|
+ it(':android: device orientation does not destroy activity', async () => {
|
|
44
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
45
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
46
|
+
|
|
47
|
+ await device.setOrientation('landscape');
|
|
48
|
+
|
|
49
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
50
|
+ });
|
|
51
|
+
|
|
52
|
+ it(':android: relaunch after activity killed by system', async () => {
|
|
53
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
54
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
55
|
+ await device.sendToHome();
|
|
56
|
+
|
|
57
|
+ await togglePhonePermission();
|
|
58
|
+ await device.launchApp();
|
|
59
|
+
|
|
60
|
+ await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
|
|
61
|
+ await expect(elementByLabel('React Native Navigation!')).toBeVisible();
|
|
62
|
+ });
|
|
63
|
+
|
|
64
|
+ xit(':android: pressing menu opens dev menu', async () => {
|
|
65
|
+ if (!IS_RELEASE) {
|
|
66
|
+ Android.pressMenu();
|
|
67
|
+ await sleep(1000);
|
|
68
|
+ await expect(elementByLabel('Reload')).toBeVisible();
|
|
69
|
+ }
|
|
70
|
+ });
|
|
71
|
+
|
|
72
|
+ xit(':android: pressing r twice in succession reloads React Native', async () => {
|
|
73
|
+ if (!IS_RELEASE) {
|
|
74
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
75
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
76
|
+
|
|
77
|
+ Android.pressKeyCode(KEY_CODE_R);
|
|
78
|
+ Android.pressKeyCode(KEY_CODE_R);
|
|
79
|
+
|
|
80
|
+ await sleep(300);
|
|
81
|
+ await expect(elementByLabel('React Native Navigation!')).toBeVisible();
|
|
82
|
+ }
|
|
83
|
+ });
|
|
84
|
+
|
|
85
|
+ it(':android: pressing r twice with delay does nothing', async () => {
|
|
86
|
+ if (!IS_RELEASE) {
|
|
87
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
88
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
89
|
+
|
|
90
|
+ Android.pressKeyCode(KEY_CODE_R);
|
|
91
|
+ await sleep(1000);
|
|
92
|
+ Android.pressKeyCode(KEY_CODE_R);
|
|
93
|
+
|
|
94
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
95
|
+ }
|
|
96
|
+ });
|
|
97
|
+
|
|
98
|
+ xit(':android: sending reload broadcast reloads react native', async () => {
|
|
99
|
+ if (!IS_RELEASE) {
|
|
100
|
+ await elementById(testIDs.PUSH_BUTTON).tap();
|
|
101
|
+ await expect(elementByLabel('Pushed Screen')).toBeVisible();
|
|
102
|
+
|
|
103
|
+ Android.executeShellCommand('am broadcast -a com.reactnativenavigation.broadcast.RELOAD');
|
|
104
|
+
|
|
105
|
+ await sleep(1000);
|
|
106
|
+ await expect(elementByLabel('React Native Navigation!')).toBeVisible();
|
|
107
|
+ }
|
|
108
|
+ });
|
|
109
|
+
|
|
110
|
+ async function togglePhonePermission() {
|
|
111
|
+ await sleep(700);
|
|
112
|
+ Android.revokePermission();
|
|
113
|
+ await sleep(700);
|
|
114
|
+ Android.grantPermission();
|
|
115
|
+ await sleep(1000);
|
|
116
|
+ }
|
|
117
|
+});
|