-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotifications.e2e.js
More file actions
251 lines (220 loc) · 10.5 KB
/
Copy pathnotifications.e2e.js
File metadata and controls
251 lines (220 loc) · 10.5 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
import { driver, expect } from '@wdio/globals';
import ForYouScreen from '../pageobjects/Home/ForYouScreen.page';
import LoginEmailScreen from '../pageobjects/Login/LoginEmail.page';
import LoginPasswordScreen from '../pageobjects/Login/LoginPassword.page';
import AllNotificationsScreen from '../pageobjects/Notifications/AllNotificationsScreen.page';
import MentionsScreen from '../pageobjects/Notifications/MentionsScreen.page';
import ProfileScreen from '../pageobjects/Profile/ProfileScreen.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 { createTestTweets } from '../utils/createTestTweets';
import { createTestUser } from '../utils/createTestUser';
import { followUser } from '../utils/followUser';
import { getAccessToken } from '../utils/getAccessToken';
import { receiveTweetActions } from '../utils/receiveTweetActions';
let testUser, tweetId, token;
describe('Notifications 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();
token = await getAccessToken(testUser.email, testUser.password);
testUser.username = await changeUsername(token);
await login();
const tweetIds = await createTestTweets(token);
tweetId = tweetIds[0];
await ForYouScreen.switchToNotificationsTab();
});
it('should display Notifications screen', async () => {
await expect(await AllNotificationsScreen.screenTitle.waitForDisplayed()).toBe(true);
});
it('should initially show no notifications and show its message', async () => {
await expect(await AllNotificationsScreen.isNoNotificationsMessageDisplayed()).toBe(true);
});
describe('Follow notifications', () => {
before(async () => {
const numOfFollowers = 1;
await followUser(testUser.username, numOfFollowers);
});
it('should show all follow notifications after users follow me', async () => {
await AllNotificationsScreen.refresh();
await expect(await AllNotificationsScreen.followNotifications.length).toBe(1);
await expect(await AllNotificationsScreen.followBackButton.length).toBe(1);
});
it('should correctly handle following back a user from notifications list', async () => {
await AllNotificationsScreen.followBackButton[0].click();
await expect(await AllNotificationsScreen.followingButton.length).toBe(1);
});
it('should navigate to user profile when clicking on the notification', async () => {
const displayName = await AllNotificationsScreen.followNotifUserDisplayName[0].getText();
await AllNotificationsScreen.followNotifications[0].click();
await ProfileScreen.displayName.waitForDisplayed();
await expect(await ProfileScreen.displayName.getText()).toBe(displayName);
});
it('should verify following status in user profile', async () => {
await expect(await ProfileScreen.isFollowingButtonDisplayed()).toBe(true);
});
it('should update state of the follow button after unfollowing user in profile', async () => {
await ProfileScreen.goBack();
await AllNotificationsScreen.followingButton[0].click();
await expect(await AllNotificationsScreen.followingButton.length).toBe(0);
await expect(await AllNotificationsScreen.followBackButton.length).toBe(1);
await AllNotificationsScreen.followNotifications[0].click();
await expect(await ProfileScreen.isFollowBackButtonDisplayed()).toBe(true);
await ProfileScreen.goBack();
});
});
describe('Tweet Actions notifications', () => {
before(async () => {
const countPerAction = 1;
await receiveTweetActions(tweetId, countPerAction, {
like: true,
retweet: true,
quote: true,
reply: true,
});
});
it('should correctly show all tweet actions notifications after users interact with my tweets', async () => {
await AllNotificationsScreen.refresh();
await driver.pause(500);
await AllNotificationsScreen.refresh();
await expect(await AllNotificationsScreen.likeNotifications.length).toBe(1);
await expect(await AllNotificationsScreen.retweetNotifications.length).toBe(1);
await expect(await AllNotificationsScreen.quoteNotifications.length).toBe(1);
await expect(await AllNotificationsScreen.replyNotifications.length).toBe(1);
});
it('should go to tweet view when clicking on a reply notification', async () => {
await AllNotificationsScreen.replyNotifications[0].click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
it('should go to tweet view when clicking on a quote notification', async () => {
await TweetDetailsScreen.goBack();
await AllNotificationsScreen.quoteNotifications[0].click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
it('should go to tweet view when clicking on a retweet notification', async () => {
await TweetDetailsScreen.goBack();
await AllNotificationsScreen.retweetNotifications[0].click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
it('should go to tweet view when clicking on a like notification', async () => {
await TweetDetailsScreen.goBack();
await AllNotificationsScreen.likeNotifications[0].click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
it('should handle liking a tweet from the notification screen', async () => {
await TweetDetailsScreen.goBack();
const initialCount = parseInt(await AllNotificationsScreen.likeCount[0].getText());
await AllNotificationsScreen.likeIcon[0].click();
await expect(await AllNotificationsScreen.likeCount[0].getText()).toBe(
String(initialCount + 1)
);
});
it('should handle retweeting a tweet from the notification screen', async () => {
const initialCount = parseInt(await AllNotificationsScreen.retweetCount[0].getText());
await AllNotificationsScreen.retweetIcon[0].click();
await expect(await AllNotificationsScreen.retweetCount[0].getText()).toBe(
String(initialCount + 1)
);
});
it('should open reply composer when clicking on the reply icon', async () => {
await AllNotificationsScreen.replyIcon[0].click();
await TweetComposerScreen.tweetInput.waitForDisplayed();
await expect(await TweetComposerScreen.isDisplayed()).toBe(true);
await TweetComposerScreen.goBack();
});
it('should show new notifications on refresh', async () => {
await TweetDetailsScreen.goBack();
await receiveTweetActions(tweetId, 5, {
like: true,
retweet: false,
quote: false,
reply: false,
});
await AllNotificationsScreen.refresh();
await driver.pause(500);
await AllNotificationsScreen.refresh();
await expect(await AllNotificationsScreen.likeNotifications.length).toBe(1);
});
});
describe('Mention Notifications', () => {
let newTweetId;
before(async () => {
const newUser = await createTestUser();
const newToken = await getAccessToken(newUser.email, newUser.password);
const ids = await createTestTweets(newToken);
newTweetId = ids[0];
await receiveTweetActions(
newTweetId,
1,
{ like: false, retweet: false, quote: false, reply: true },
`@${testUser.username}`
);
});
it('should show the mention notification in the all notifications tab', async () => {
await AllNotificationsScreen.refresh();
await driver.pause(500);
await AllNotificationsScreen.refresh();
await expect(await AllNotificationsScreen.mentionNotifications.length).toBe(1);
});
it('should navigate to tweet view when clicking on mention notification', async () => {
await AllNotificationsScreen.mentionNotifications[0].click();
await TweetDetailsScreen.screenTitle.waitForDisplayed();
await expect(await TweetDetailsScreen.isDisplayed()).toBe(true);
});
it('should initially show no mention notifications in mentions tab', async () => {
await TweetDetailsScreen.goBack();
await AllNotificationsScreen.goToMentionsTab();
await expect(await MentionsScreen.isNoNotificationsMessageDisplayed()).toBe(true);
});
it('should show the mention notification in the mentions tab', async () => {
await MentionsScreen.refresh();
await expect(await MentionsScreen.mentionNotifications.length).toBe(1);
});
it('should handle liking mention from mentions tab', async () => {
const initialCount = parseInt(await MentionsScreen.likeCount[0].getText());
await MentionsScreen.likeIcon[0].click();
await expect(await MentionsScreen.likeCount[0].getText()).toBe(String(initialCount + 1));
});
it('should handle retweeting mention from mentions tab', async () => {
const initialCount = parseInt(await MentionsScreen.retweetCount[0].getText());
await MentionsScreen.retweetIcon[0].click();
await expect(await MentionsScreen.retweetCount[0].getText()).toBe(String(initialCount + 1));
});
it('should open reply composer when clicking on reply icon in mentions tab', async () => {
await MentionsScreen.replyIcon[0].click();
await TweetComposerScreen.tweetInput.waitForDisplayed();
await expect(await TweetComposerScreen.isDisplayed()).toBe(true);
await TweetComposerScreen.goBack();
});
it('should handle showing multiple new mention notifications', async () => {
await TweetDetailsScreen.goBack();
await receiveTweetActions(
newTweetId,
3,
{
like: false,
retweet: false,
quote: true,
reply: false,
},
`@${testUser.username}`
);
await MentionsScreen.refresh();
await driver.pause(1000);
await expect(await MentionsScreen.mentionNotifications.length).toBe(4);
});
});
});