-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchat.test.ts
More file actions
236 lines (188 loc) · 9.3 KB
/
chat.test.ts
File metadata and controls
236 lines (188 loc) · 9.3 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
import { test, expect, firefox, chromium } from '@playwright/test'
import { login, newWindow, randomString, register } from './generic'
import { createGroup, deleteGroup, gotoGroup, joinGroup } from './group'
import 'dotenv/config'
test('Group-Chat', async ({ page }) => {
test.skip()
await login(page)
const group = { name: 'test-group-chat' + randomString(), public: true }
await createGroup(page, group)
const bPage = await newWindow()
await login(bPage, {
username: process.env.SECONDUSER_NAME,
password: process.env.SECONDUSER_PASS,
})
await joinGroup(bPage, group)
await page.reload()
await bPage.reload()
await page.getByRole('button', { name: 'open chat' }).click()
await page.getByPlaceholder('Search chatters').click()
await page.getByPlaceholder('Search chatters').fill(group.name)
await page
.getByRole('button', { name: `avatar ${group.name}` })
.first()
.click()
await page.getByPlaceholder('Write a message...').click()
await page.getByPlaceholder('Write a message...').fill('Hello!! :D')
await page.waitForTimeout(300)
await page.locator('form > button:nth-child(2)').click()
await page.getByPlaceholder('Write a message...').click()
await page.waitForTimeout(300)
await bPage.getByRole('button', { name: 'open chat' }).click()
await bPage.getByPlaceholder('Search chatters').click()
await bPage.getByPlaceholder('Search chatters').fill(group.name)
await bPage.getByRole('button', { name: group.name }).first().click()
await page.waitForTimeout(300)
await bPage.getByPlaceholder('Write a message...').fill('Hello!! :D')
await bPage.getByPlaceholder('Write a message...').press('Enter')
await page.waitForTimeout(300)
await expect(page.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(page.getByText('Hello!! :D').nth(2)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible()
await gotoGroup(page, group)
await deleteGroup(page, group)
})
test('Direct-Chat-Via-Group', async ({ page }) => {
test.skip()
await login(page)
const group = { name: 'Test Group Chat 2' + randomString(), public: true }
await createGroup(page, group)
const browser = await chromium.launch()
const bContext = await browser.newContext()
const bPage = await bContext.newPage()
await login(bPage, {
username: process.env.SECONDUSER_NAME,
password: process.env.SECONDUSER_PASS,
})
await joinGroup(bPage, group)
await gotoGroup(bPage, group)
await page.getByRole('button', { name: 'Members', exact: true }).click()
await page.locator('.text-primary').click()
await page.getByPlaceholder('Write a message...').click()
await page.getByPlaceholder('Write a message...').fill('Hello!! :D')
await page.locator('form > button:nth-child(2)').click()
await page.getByPlaceholder('Write a message...').click()
await bPage.getByRole('button', { name: 'Members', exact: true }).click()
await bPage.locator('.text-primary').click()
await bPage.getByPlaceholder('Write a message...').fill('Hello!! :D')
await bPage.getByPlaceholder('Write a message...').press('Enter')
await expect(page.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(page.getByText('Hello!! :D').nth(2)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible()
await page.getByRole('button', { name: 'Close modal' }).click()
await deleteGroup(page, group)
})
test('Workgroup-Chat', async ({ page }) => {
test.skip()
await login(page)
const group = {
name: 'Test Group Chat Workgroup' + randomString(),
public: true,
}
await createGroup(page, group)
const bPage = await newWindow()
await login(bPage, {
username: process.env.SECONDUSER_NAME,
password: process.env.SECONDUSER_PASS,
})
await joinGroup(bPage, group)
await gotoGroup(bPage, group)
await page.getByRole('button', { name: 'Work Groups' }).click()
await page.getByRole('button', { name: '+ Add Workgroup' }).click()
await page.getByLabel('Name').click()
const workgroup = 'Workgroup for chatting in yay' + randomString()
await page.getByLabel('Name').fill(workgroup)
await page.getByRole('button', { name: 'Create', exact: true }).click()
await page.getByRole('button', { name: 'Join', exact: true }).click()
await bPage.getByRole('button', { name: 'Work Groups' }).click()
await bPage.getByRole('button', { name: 'Join', exact: true }).click()
await page.getByRole('button', { name: 'open chat' }).click()
await page.getByPlaceholder('Search chatters').click()
await page.getByPlaceholder('Search chatters').fill(workgroup)
await page.getByRole('button', { name: workgroup }).click()
await page.getByPlaceholder('Write a message...').click()
await page.getByPlaceholder('Write a message...').fill('Hello!! :D')
await page.locator('form > button:nth-child(2)').click()
await page.getByPlaceholder('Write a message...').click()
await bPage.getByRole('button', { name: 'open chat' }).click()
await bPage.getByPlaceholder('Search chatters').click()
await bPage.getByPlaceholder('Search chatters').fill(workgroup)
await bPage.getByRole('button', { name: workgroup }).click()
await bPage.getByPlaceholder('Write a message...').click()
await bPage.getByPlaceholder('Write a message...').fill('Hello!! :D')
await bPage.locator('form > button:nth-child(2)').click()
await bPage.getByPlaceholder('Write a message...').click()
await expect(page.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(page.getByText('Hello!! :D').nth(2)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible()
await page.getByRole('button', { name: 'Close modal' }).click()
})
// TODO Fix this, will require finessing with registring new users
test('Group-Chat-Creation', async ({ page }) => {
test.skip()
await login(page)
// Testing error functionality
await page.getByRole('button', { name: 'open chat' }).click()
await page.getByRole('button', { name: '+ New Group' }).click()
await page.getByRole('button', { name: 'Cancel' }).click()
await page.getByRole('button', { name: '+ New Group' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(page.getByText('Failed to created group chat')).toBeVisible()
// Have other users chat
const bPage = await newWindow()
await login(bPage, {
username: process.env.SECONDUSER_NAME,
password: process.env.SECONDUSER_PASS,
})
const cPage = await newWindow()
// TODO: Fix so a recently registered account is also included
// const { username } = await register(cPage)
const username = process.env.FOURTHUSER_NAME
await login(cPage, {
username: process.env.FOURTHUSER_NAME,
password: process.env.FOURTHUSER_PASS,
})
await page.getByRole('button', { name: 'avatar + Invite user' }).nth(1).click()
await page.getByRole('textbox', { name: 'User to invite' }).click()
await page.getByRole('textbox', { name: 'User to invite' }).fill(username)
await page.getByRole('button', { name: 'Add Me!', exact: true }).click()
await page.getByRole('button', { name: 'Close modal' }).nth(3).click()
await page.getByRole('button', { name: 'Confirm', exact: true }).click()
await expect(page.getByText('Failed to created group chat')).not.toBe
const groupname = `${process.env.MAINUSER_NAME}, ${process.env.SECONDUSER_NAME}, ${username}`
// Write messages and check that they are visible
await page.getByPlaceholder('Write a message...').click()
await page.getByPlaceholder('Write a message...').fill('Hello!! :D')
await page.waitForTimeout(300)
await page.locator('form > button:nth-child(2)').click()
await page.getByPlaceholder('Write a message...').click()
await page.waitForTimeout(300)
await bPage.getByRole('button', { name: 'open chat' }).click()
await bPage.getByPlaceholder('Search chatters').click()
await bPage.getByPlaceholder('Search chatters').fill(groupname)
await bPage.getByRole('button', { name: groupname }).first().click()
await page.waitForTimeout(300)
await bPage.getByPlaceholder('Write a message...').fill('Hello!! :D')
await bPage.getByPlaceholder('Write a message...').press('Enter')
await page.waitForTimeout(300)
await cPage.getByRole('button', { name: 'open chat' }).click()
await cPage.getByPlaceholder('Search chatters').click()
await cPage.getByPlaceholder('Search chatters').fill(groupname)
await cPage.getByRole('button', { name: groupname }).first().click()
await page.waitForTimeout(300)
await cPage.getByPlaceholder('Write a message...').fill('Hello!! :D')
await cPage.getByPlaceholder('Write a message...').press('Enter')
await page.waitForTimeout(300)
await expect(page.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(page.getByText('Hello!! :D').nth(2)).toBeVisible()
await expect(page.getByText('Hello!! :D').nth(3)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible()
await expect(bPage.getByText('Hello!! :D').nth(3)).toBeVisible()
await expect(cPage.getByText('Hello!! :D').nth(1)).toBeVisible()
await expect(cPage.getByText('Hello!! :D').nth(2)).toBeVisible()
await expect(cPage.getByText('Hello!! :D').nth(3)).toBeVisible()
})