forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.test.js
190 lines (162 loc) · 7.65 KB
/
Stack.test.js
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
import jestExpect from 'expect';
import Utils from './Utils';
import TestIDs from '../playground/src/testIDs';
import Android from './AndroidUtils';
const { elementByLabel, elementById, sleep } = Utils;
const driver = {
root: {
navToTitleAndSubtitle: async () => {
await elementById(TestIDs.PUSH_TITLE_WITH_SUBTITLE).tap();
return driver.titleWithSubtitle;
},
},
titleWithSubtitle: {
titleId: `${TestIDs.TOPBAR_ID}.title`,
subtitleId: `${TestIDs.TOPBAR_ID}.subtitle`,
title: () => elementById(driver.titleWithSubtitle.titleId),
titleByLabel: () => elementByLabel('Title'),
subtitle: () => elementById(driver.titleWithSubtitle.subtitleId),
subtitleByLabel: () => elementByLabel('Subtitle'),
},
};
describe('Stack', () => {
beforeEach(async () => {
await device.launchApp({ newInstance: true });
await elementById(TestIDs.STACK_BTN).tap();
});
it.e2e('SetStackRoot on a non created tab should work', async () => {
await elementById(TestIDs.SET_ROOT_NAVIGATION_TAB).tap();
await elementById(TestIDs.DISMISS_MODAL_TOPBAR_BTN).tap();
await elementById(TestIDs.NAVIGATION_TAB).tap();
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.BACK_BUTTON).tap();
await expect(elementById(TestIDs.NAVIGATION_SCREEN)).toBeVisible();
});
it('push and pop screen', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
});
it('push and pop screen without animation', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.PUSH_NO_ANIM_BTN).tap();
await expect(elementByLabel('Stack Position: 2')).toBeVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementByLabel('Stack Position: 1')).toBeVisible();
});
it('pop using stack id', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.POP_USING_STACK_ID_BTN).tap();
await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
});
it('pop using previous screen id', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.PUSH_BTN).tap();
await expect(elementByLabel('Stack Position: 2')).toBeVisible();
await elementById(TestIDs.POP_USING_PREVIOUS_SCREEN_ID_BTN).tap();
await expect(elementByLabel('Stack Position: 1')).toBeVisible();
});
it('pop to specific id', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.PUSH_BTN).tap();
await expect(elementByLabel('Stack Position: 3')).toBeVisible();
await elementById(TestIDs.POP_TO_FIRST_SCREEN_BTN).tap();
await expect(elementByLabel('Stack Position: 1')).toBeVisible();
});
it('pop to root', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.POP_TO_ROOT_BTN).tap();
await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
});
it.e2e('pop component should not detach component if can`t pop', async () => {
await elementById(TestIDs.POP_NONE_EXISTENT_SCREEN_BTN).tap();
await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
});
it(':android: custom back button', async () => {
await elementById(TestIDs.PUSH_CUSTOM_BACK_BTN).tap();
await elementById(TestIDs.CUSTOM_BACK_BTN).tap();
await expect(elementByLabel('back button clicked')).toBeVisible();
});
it('push title with subtitle', async () => {
const innerDriver = await driver.root.navToTitleAndSubtitle();
await expect(innerDriver.titleByLabel()).toBeVisible();
await expect(innerDriver.subtitleByLabel()).toBeVisible();
});
it('push title & subtitle with derived test IDs', async () => {
const innerDriver = await driver.root.navToTitleAndSubtitle();
await expect(innerDriver.title()).toBeVisible();
await expect(innerDriver.subtitle()).toBeVisible();
});
it.e2e('push title & subtitle with derived test IDs (strict e2e)', async () => {
const innerDriver = await driver.root.navToTitleAndSubtitle();
const titleAttr = await innerDriver.titleByLabel().getAttributes();
jestExpect(titleAttr.identifier).toEqual(innerDriver.titleId);
const subtitleAttr = await innerDriver.subtitleByLabel().getAttributes();
jestExpect(subtitleAttr.identifier).toEqual(innerDriver.subtitleId);
});
it.e2e('screen lifecycle', async () => {
await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
await expect(elementByLabel('didAppear')).toBeVisible();
await elementById(TestIDs.PUSH_TO_TEST_DID_DISAPPEAR_BTN).tap();
await expect(elementByLabel('didDisappear')).toBeVisible();
});
it.e2e('Screen popped event', async () => {
await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
await elementById(TestIDs.SCREEN_POPPED_BTN).tap();
await expect(elementByLabel('Screen popped event')).toBeVisible();
});
it.e2e('unmount is called on pop', async () => {
await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementByLabel('componentWillUnmount')).toBeVisible();
await elementByLabel('OK').atIndex(0).tap();
await expect(elementByLabel('didDisappear')).toBeVisible();
});
it.e2e(':android: override hardware back button', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await elementById(TestIDs.ADD_BACK_HANDLER).tap();
await Android.pressBack();
await sleep(100);
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.REMOVE_BACK_HANDLER).tap();
await Android.pressBack();
await sleep(100);
await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
});
it('does not crash when setting the stack root to an existing component id', async () => {
await elementById(TestIDs.SET_STACK_ROOT_WITH_ID_BTN).tap();
await elementById(TestIDs.SET_STACK_ROOT_WITH_ID_BTN).tap();
});
it.e2e(':ios: set stack root component should be first in stack', async () => {
await elementById(TestIDs.PUSH_BTN).tap();
await expect(elementByLabel('Stack Position: 1')).toBeVisible();
await elementById(TestIDs.SET_STACK_ROOT_BUTTON).tap();
await expect(elementByLabel('Stack Position: 2')).toBeVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementByLabel('Stack Position: 2')).toBeVisible();
});
xit(':ios: set searchBar and handle onSearchUpdated event', async () => {
// Broken on iOS 13
await elementById(TestIDs.SEARCH_BTN).tap();
await expect(elementByLabel('Start Typing')).toBeVisible();
await elementByLabel('Start Typing').tap();
const query = '124';
await elementByLabel('Start Typing').typeText(query);
await expect(elementById(TestIDs.SEARCH_RESULT_ITEM)).toHaveText(`Item ${query}`);
});
it.e2e('push promise is resolved with pushed ViewController id', async () => {
await elementById(TestIDs.STACK_COMMANDS_BTN).tap();
await elementById(TestIDs.PUSH_BTN).tap();
await expect(elementByLabel('push promise resolved with: ChildId')).toBeVisible();
await expect(elementByLabel('pop promise resolved with: ChildId')).toBeVisible();
});
it('pop from root screen should do nothing', async () => {
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
});
});