-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtweets.e2e.js
More file actions
430 lines (371 loc) · 16.8 KB
/
Copy pathtweets.e2e.js
File metadata and controls
430 lines (371 loc) · 16.8 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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
import { driver, expect } from '@wdio/globals';
import FollowingScreen from '../pageobjects/Home/FollowingScreen.page';
import ForYouScreen from '../pageobjects/Home/ForYouScreen.page';
import LoginEmailScreen from '../pageobjects/Login/LoginEmail.page';
import LoginPasswordScreen from '../pageobjects/Login/LoginPassword.page';
import StartScreen from '../pageobjects/StartScreen.page';
import TweetComposerScreen from '../pageobjects/Tweets/TweetComposerScreen.page';
import TweetDetailsScreen from '../pageobjects/Tweets/TweetDetailsScreen.page';
import { changeUsername } from '../utils/changeUsername';
import { createTestUser } from '../utils/createTestUser';
import { getAccessToken } from '../utils/getAccessToken';
let testUser;
describe('Tweets Flow', () => {
const login = async () => {
await StartScreen.openLoginScreen();
await LoginEmailScreen.enterEmail(testUser.email);
await LoginEmailScreen.clickNext();
await LoginPasswordScreen.enterPassword(testUser.password);
await LoginPasswordScreen.clickLogin();
await ForYouScreen.forYouTab.waitForDisplayed();
};
before(async () => {
testUser = await createTestUser();
const accessToken = await getAccessToken(testUser.email, testUser.password);
testUser.username = await changeUsername(accessToken);
await login();
});
describe('Creating Tweet Tests', () => {
before(async () => {
await ForYouScreen.clickNewTweetButton();
});
it('should show tweet composer screen', async () => {
await expect(await TweetComposerScreen.isDisplayed()).toBe(true);
});
it('should initially have post button disabled when composer is empty', async () => {
await expect(await TweetComposerScreen.isPostButtonEnabled()).toBe(false);
});
it('should enable post button upon entering any input', async () => {
await TweetComposerScreen.writeTweet('Hello!');
await expect(await TweetComposerScreen.isPostButtonEnabled()).toBe(true);
});
it('should disable posting tweet when input is too long', async () => {
await TweetComposerScreen.writeTweet('s'.repeat(281));
await expect(await TweetComposerScreen.isPostButtonEnabled()).toBe(false);
});
it('should show discard modal when going back with unsaved changes', async () => {
await TweetComposerScreen.goBack();
await expect(await TweetComposerScreen.isDiscardModalDisplayed()).toBe(true);
});
it('should stay on composer screen when canceling discard', async () => {
await TweetComposerScreen.cancelDiscardTweet();
await expect(await TweetComposerScreen.isDisplayed()).toBe(true);
});
it('should discard tweet when discarding', async () => {
await TweetComposerScreen.goBack();
await TweetComposerScreen.discardTweet();
await expect(await ForYouScreen.isDisplayed()).toBe(true);
});
it('should handle posting tweet with only text', async () => {
await ForYouScreen.clickNewTweetButton();
await TweetComposerScreen.tweetInput.waitForDisplayed();
await TweetComposerScreen.writeTweet('Hello World!');
await TweetComposerScreen.postTweet();
await ForYouScreen.forYouTab.waitForDisplayed();
await ForYouScreen.switchToFollowingTab();
await FollowingScreen.screenTitle.waitForDisplayed();
await driver.pause(500);
await expect(await FollowingScreen.tweetCard.length).toBe(1);
});
it('should verify posted tweet is the same as input', async () => {
await expect(await FollowingScreen.tweetContent[0].getText()).toBe('Hello World!');
});
it('should handle choosing media in composer', async () => {
await FollowingScreen.clickNewTweetButton();
await TweetComposerScreen.tweetInput.waitForDisplayed();
try {
await expect(await TweetComposerScreen.composerMediaImages.length).toBeGreaterThan(0);
await TweetComposerScreen.composerMediaImages[0].click();
await driver.pause(500);
await expect(await TweetComposerScreen.composerRemoveMedia.length).toBe(1);
} catch (error) {
console.error(error);
}
});
it('should max out at 4 images', async () => {
try {
await TweetComposerScreen.composerMediaImages[1].click();
await driver.pause(100);
await TweetComposerScreen.composerMediaImages[2].click();
await driver.pause(100);
await TweetComposerScreen.composerMediaImages[3].click();
await driver.pause(100);
await expect(await TweetComposerScreen.composerRemoveMedia.length).toBeGreaterThan(0);
} catch (error) {
console.error(error);
}
});
it('should handle removing media', async () => {
try {
for (let i = 0; i < 4; i++) {
await TweetComposerScreen.composerRemoveMedia[0].click();
await driver.pause(500);
}
await expect(await TweetComposerScreen.composerRemoveMedia.length).toBe(0);
} catch (error) {
console.error(error);
}
});
it('should handle posting tweet with media', async () => {
try {
await TweetComposerScreen.composerMediaImages[0].click();
await driver.pause(100);
await TweetComposerScreen.postTweet();
await ForYouScreen.forYouTab.waitForDisplayed();
await ForYouScreen.switchToFollowingTab();
await FollowingScreen.screenTitle.waitForDisplayed();
await driver.pause(500);
await expect(await FollowingScreen.tweetCard.length).toBe(2);
} catch (error) {
console.error(error);
}
});
it('should handle posting tweet with mention, hashtag, and link', async () => {
await FollowingScreen.clickNewTweetButton();
await TweetComposerScreen.tweetInput.waitForDisplayed();
await TweetComposerScreen.writeTweet(`@${testUser.username} #test https://raven.cmp27.space`);
await TweetComposerScreen.postTweet();
await ForYouScreen.forYouTab.waitForDisplayed();
await ForYouScreen.switchToFollowingTab();
await FollowingScreen.screenTitle.waitForDisplayed();
await driver.pause(500);
await expect(await FollowingScreen.tweetCard.length).toBe(3);
});
});
describe('Timeline Navigation Tests', () => {
before(async () => {
await ForYouScreen.forYouTab.waitForDisplayed();
});
it('should switch between For You and Following tabs', async () => {
await expect(await FollowingScreen.isDisplayed()).toBe(true);
await ForYouScreen.forYouTab.click();
await driver.pause(300);
await expect(await ForYouScreen.forYouTab).toBeDisplayed();
await ForYouScreen.switchToFollowingTab();
await FollowingScreen.screenTitle.waitForDisplayed();
await expect(await FollowingScreen.screenTitle).toBeDisplayed();
});
it('should display tweet cards on timeline', async () => {
const tweetCards = await FollowingScreen.tweetCard;
await expect(tweetCards.length).toBeGreaterThan(0);
});
it('should navigate to tweet detail when clicking on a tweet', async () => {
const firstTweet = await FollowingScreen.tweetCard[2];
await firstTweet.click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
it('should go back to timeline from tweet detail', async () => {
await TweetDetailsScreen.goBack();
await FollowingScreen.screenTitle.waitForDisplayed();
await expect(await FollowingScreen.isDisplayed()).toBe(true);
});
});
describe('Thread View Tests', () => {
before(async () => {
await FollowingScreen.screenTitle.waitForDisplayed();
const firstTweet = await FollowingScreen.tweetCard[2];
await firstTweet.click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
});
it('should display main tweet in detail view', async () => {
await expect(await TweetDetailsScreen.isMainTweetDisplayed()).toBe(true);
});
it('should display tweet content in detail view', async () => {
const contentElements = await TweetDetailsScreen.tweetContent;
await expect(contentElements.length).toBeGreaterThan(0);
});
it('should display tweet action buttons', async () => {
await expect(await TweetDetailsScreen.likeButton).toBeDisplayed();
await expect(await TweetDetailsScreen.retweetButton).toBeDisplayed();
await expect(await TweetDetailsScreen.replyButton).toBeDisplayed();
});
it('should display reply input at bottom', async () => {
await expect(await TweetDetailsScreen.replyInput).toBeDisplayed();
});
after(async () => {
await TweetDetailsScreen.goBack();
await FollowingScreen.screenTitle.waitForDisplayed();
});
});
describe('Reply Flow Tests', () => {
let initialReplyCount;
before(async () => {
const firstTweet = await FollowingScreen.tweetCard[2];
await firstTweet.click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
initialReplyCount = await TweetDetailsScreen.getReplyCountValue();
});
it('should show reply input with placeholder', async () => {
const replyInput = await TweetDetailsScreen.replyInput;
await expect(replyInput).toBeDisplayed();
});
it('should submit a reply using quick reply input', async () => {
await TweetDetailsScreen.typeReply('This is a test reply!');
await TweetDetailsScreen.submitReply();
await driver.pause(1000);
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
it('should update reply count after replying', async () => {
await driver.pause(500);
const newReplyCount = await TweetDetailsScreen.getReplyCountValue();
expect(newReplyCount).toBe(initialReplyCount + 1);
});
it('should show the reply in the thread', async () => {
const replies = await TweetDetailsScreen.replyContainers;
await expect(replies.length).toBeGreaterThan(0);
});
it('should navigate to reply detail when clicking on a reply', async () => {
const replies = await TweetDetailsScreen.replyContainers;
if (replies.length > 0) {
await replies[0].click();
await driver.pause(500);
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
await TweetDetailsScreen.goBack();
}
});
after(async () => {
await TweetDetailsScreen.goBack();
await FollowingScreen.screenTitle.waitForDisplayed();
});
});
describe('Tweet Interaction Tests', () => {
it('should show delete tweet modal when deleting tweet', async () => {
await FollowingScreen.tweetDrawerButton[0].click();
await FollowingScreen.deleteTweet();
await FollowingScreen.deleteTweetModal.waitForDisplayed();
await expect(await FollowingScreen.isDeleteTweetModalDisplayed()).toBe(true);
});
it('should not delete tweet when canceling deletion', async () => {
const initialCount = 3;
await FollowingScreen.cancelDeleteTweet();
await FollowingScreen.screenTitle.waitForDisplayed();
await expect(await FollowingScreen.tweetCard.length).toBe(initialCount);
});
it('should delete tweet when confirming deletion', async () => {
const initialCount = await FollowingScreen.tweetCard.length;
await FollowingScreen.tweetDrawerButton[0].click();
await FollowingScreen.deleteTweet();
await FollowingScreen.confirmDeleteTweet();
await FollowingScreen.screenTitle.waitForDisplayed();
await driver.pause(500);
await expect(await FollowingScreen.tweetCard.length).toBe(initialCount - 1);
});
it('should show ai summary when clicking on its icon', async () => {
const aiButtons = await FollowingScreen.aiSummaryButton;
if (aiButtons.length > 0) {
await aiButtons[0].click();
await driver.pause(2000);
const aiTexts = await FollowingScreen.aiSummaryText;
if (aiTexts.length > 0) {
await expect(await aiTexts[0].waitForDisplayed()).toBe(true);
}
}
});
it('should handle liking tweet', async () => {
const initialLikeCount = await FollowingScreen.tweetLikeCount[0].getText();
await FollowingScreen.tweetLikeButton[0].click();
await driver.pause(300);
const updatedLikeCount = await FollowingScreen.tweetLikeCount[0].getText();
expect(parseInt(updatedLikeCount)).toBe(parseInt(initialLikeCount) + 1);
});
it('should handle unliking tweet', async () => {
const initialLikeCount = await FollowingScreen.tweetLikeCount[0].getText();
await FollowingScreen.tweetLikeButton[0].click();
await driver.pause(300);
const updatedLikeCount = await FollowingScreen.tweetLikeCount[0].getText();
expect(parseInt(updatedLikeCount)).toBe(parseInt(initialLikeCount) - 1);
});
it('should handle retweeting tweet', async () => {
const initialRetweetCount = await FollowingScreen.tweetRetweetCount[0].getText();
await FollowingScreen.tweetRetweetButton[0].click();
await FollowingScreen.chooseRepostFromDrawer();
await FollowingScreen.screenTitle.waitForDisplayed();
await driver.pause(300);
const updatedRetweetCount = await FollowingScreen.tweetRetweetCount[0].getText();
expect(parseInt(updatedRetweetCount)).toBe(parseInt(initialRetweetCount) + 1);
});
it('should handle undo retweet', async () => {
const initialRetweetCount = await FollowingScreen.tweetRetweetCount[0].getText();
await FollowingScreen.tweetRetweetButton[0].click();
await FollowingScreen.chooseUndoRepostFromDrawer();
await FollowingScreen.screenTitle.waitForDisplayed();
await driver.pause(300);
const updatedRetweetCount = await FollowingScreen.tweetRetweetCount[0].getText();
expect(parseInt(updatedRetweetCount)).toBe(parseInt(initialRetweetCount) - 1);
});
it('should handle quoting tweet', async () => {
await FollowingScreen.tweetRetweetButton[1].click();
await FollowingScreen.chooseQuoteFromDrawer();
await TweetComposerScreen.tweetInput.waitForDisplayed();
await TweetComposerScreen.writeTweet("I'm quoting this tweet!");
await TweetComposerScreen.postTweet();
await ForYouScreen.forYouTab.waitForDisplayed();
await ForYouScreen.switchToFollowingTab();
await FollowingScreen.screenTitle.waitForDisplayed();
await driver.pause(500);
const tweetContent = await FollowingScreen.tweetContent[0].getText();
expect(tweetContent).toContain("I'm quoting this tweet!");
});
});
describe('Reply via Composer Tests', () => {
before(async () => {
const firstTweet = await FollowingScreen.tweetCard[2];
await firstTweet.click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
});
it('should open full composer when clicking reply button', async () => {
await TweetDetailsScreen.replyButton.click();
await TweetComposerScreen.tweetInput.waitForDisplayed();
await expect(await TweetComposerScreen.isDisplayed()).toBe(true);
});
it('should show replying to context in composer', async () => {
await expect(await TweetComposerScreen.tweetInput).toBeDisplayed();
});
it('should submit reply via full composer', async () => {
await TweetComposerScreen.writeTweet('Reply via full composer!');
await TweetComposerScreen.postTweet();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
after(async () => {
await TweetDetailsScreen.goBack();
await FollowingScreen.screenTitle.waitForDisplayed();
});
});
describe('Tweet Detail Interaction Tests', () => {
before(async () => {
const firstTweet = await FollowingScreen.tweetCard[2];
await firstTweet.click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
});
it('should like tweet from detail view', async () => {
const initialCount = await TweetDetailsScreen.getLikeCountValue();
await TweetDetailsScreen.toggleLike();
await driver.pause(300);
const newCount = await TweetDetailsScreen.getLikeCountValue();
expect(newCount).toBe(initialCount + 1);
});
it('should retweet from detail view', async () => {
await TweetDetailsScreen.openRetweetMenu();
await TweetDetailsScreen.repostOption.waitForDisplayed();
await expect(await TweetDetailsScreen.repostOption).toBeDisplayed();
await expect(await TweetDetailsScreen.quoteOption).toBeDisplayed();
await driver.back();
await driver.pause(300);
});
it('should show tweet drawer options', async () => {
const drawerButton = await TweetDetailsScreen.tweetDrawerButton;
if (await drawerButton.isDisplayed()) {
await drawerButton.click();
await driver.pause(500);
await driver.back();
await driver.pause(300);
}
});
after(async () => {
await TweetDetailsScreen.goBack();
await FollowingScreen.screenTitle.waitForDisplayed();
});
});
});