-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
feed.js
233 lines (205 loc) · 6.88 KB
/
feed.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
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
223
224
225
226
227
228
229
230
231
232
233
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const wd = require('wd');
async function scrollDownUntil(driver, conditionFn) {
for (let _ of Array(10)) {
let action = new wd.TouchAction(driver);
action
.press({x: 600, y: 1100})
.wait(200)
.moveTo({x: 600, y: 600})
.release();
await action.perform();
await driver.sleep(300);
if (await conditionFn()) return;
}
}
async function scrollUpUntil(driver, conditionFn) {
for (let _ of Array(10)) {
let action = new wd.TouchAction(driver);
action
.press({x: 600, y: 600})
.wait(200)
.moveTo({x: 600, y: 1100})
.release();
await action.perform();
await driver.sleep(300);
if (await conditionFn()) return;
}
}
module.exports = function(driver, t) {
t.test('Central screen shows messages with Etc button', async function(t) {
t.ok(
await driver.elementByAndroidUIAutomator(
'new UiSelector().text("Messages")',
),
'I see the Messages header in the Central screen',
);
const chevron = await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Etc Button")',
6000,
);
t.ok(chevron, 'I see the Etc Button on a message');
await chevron.click();
t.pass('I tap it');
const menuItem = await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().text("View raw message")',
6000,
);
t.ok(menuItem, 'I see a menu with an option "View raw message"');
await menuItem.click();
t.pass('I tap it');
t.ok(
await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().text("Raw message")',
6000,
),
'I see the Raw Message screen',
);
await driver.back();
t.pass('I press the (hardware) back button');
t.end();
});
t.test('Central screen shows many in scrolling feed', async function(t) {
const fab1 = await driver.elementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Floating Action Button")',
6000,
);
t.ok(fab1, 'I see the Floating Action Button');
const AMOUNT = 10;
t.pass('I begin creating ' + AMOUNT + ' public messages');
for (let i = 1; i <= AMOUNT; i++) {
const fab = await driver.elementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Floating Action Button")',
6000,
);
await fab.click();
await driver.sleep(500);
const composeTextInput = await driver.elementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Compose Text Input")',
4000,
);
await composeTextInput.keys('Message number ' + i + 'a');
const composePublishButton = await driver.elementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Compose Publish Button")',
6000,
);
await composePublishButton.click();
await driver.sleep(1000);
}
t.pass('I created ' + AMOUNT + ' public messages');
t.ok(
await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Message number ' + AMOUNT + 'a")',
6000,
),
'I see message number ' + AMOUNT + ' on the feed',
);
await scrollDownUntil(driver, async () => {
try {
return !!(await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Message number 1a")',
1000,
));
} catch (err) {
return false;
}
});
t.pass('I scroll down through the feed');
t.ok(
await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Message number 1a")',
6000,
),
'I see message number 1 on the feed',
);
await scrollUpUntil(driver, async () => {
try {
return !!(await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Message number ' + AMOUNT + 'a")',
1000,
));
} catch (err) {
return false;
}
});
t.pass('I scroll back up');
t.end();
});
t.skip('(TODO) Feed displays follows and blocks', async function(t) {
t.end();
});
t.test('A message in the feed can be liked', async function(t) {
t.ok(
await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().text("Messages")',
6000,
),
'I see the Messages header in the Central screen',
);
const fab = await driver.elementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Floating Action Button")',
6000,
);
t.ok(fab, 'I see the Floating Action Button');
await fab.click();
const composeTextInput = await driver.elementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Compose Text Input")',
6000,
);
await composeTextInput.keys('Please like this message');
const composePublishButton = await driver.elementByAndroidUIAutomator(
'new UiSelector().descriptionContains("Compose Publish Button")',
6000,
);
await composePublishButton.click();
t.pass('I created a public message');
t.ok(
await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Please like this message")',
6000,
),
'I see that message on the feed',
);
const likeButton = await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Please like this message")' +
'.fromParent(new UiSelector().descriptionContains("Like Button"))',
6000,
);
t.ok(likeButton, 'I see a like button on that message');
await likeButton.click();
t.pass('I tap the like button');
await driver.sleep(1000);
const likeCount = await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Please like this message")' +
'.fromParent(' +
'new UiSelector().descriptionContains("Like Count Button")' +
'.childSelector(new UiSelector().textContains("like"))' +
')',
6000,
);
const count = await likeCount.text();
t.equals(count, '1 like', 'I see "1 like" as the counter');
t.end();
});
t.test('I can see that someone has liked a message in the Accounts screen', async function(t) {
const likeCount = await driver.waitForElementByAndroidUIAutomator(
'new UiSelector().textContains("Please like this message")' +
'.fromParent(' +
'new UiSelector().descriptionContains("Like Count Button")' +
')',
6000,
);
t.pass('I see the like count');
await likeCount.click();
t.pass('I tap it')
const likeList = await driver.waitForElementsByAndroidUIAutomator(
'new UiSelector().descriptionContains("Link To Account")',
6000,
)
t.equals(likeList.length, 1, 'I see 1 person having liked the message');
await driver.back();
t.pass('I press the (hardware) back button');
t.end();
})
};