-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpoll.test.ts
More file actions
414 lines (285 loc) · 11.6 KB
/
Copy pathpoll.test.ts
File metadata and controls
414 lines (285 loc) · 11.6 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
import { test, expect } from '@playwright/test'
import {
areaVote,
createPoll,
createProposal,
fastForward,
goToPost,
predictionProbability,
predictionStatementCreate,
results,
vote,
} from './poll'
import { register, newWindow, randomString, idfy } from './generic'
import { gotoGroup, createArea, createGroup, joinGroup } from './group'
import 'dotenv/config'
test.describe('Basic-Post-Integration-Tests', () => {
test.describe.configure({ mode: 'serial' })
// Public so the second (freshly registered) user can join and reach the poll
const group = { name: 'Test Group Poll' + randomString(), public: true }
const poll = { title: 'Test Poll Create and Go ' + randomString(), date: false }
test('Create-Post', async ({ page }) => {
await register(page)
await createGroup(page, group)
//Random poll name
await createPoll(page, poll)
})
test('Go-To-Post', async ({ page }) => {
await register(page)
// Different user than Create-Post, so join the group before viewing the poll
await joinGroup(page, group)
await gotoGroup(page, group)
//Random poll name
await goToPost(page, poll)
})
})
test.skip('Area-Vote', async ({ page }) => {
test.setTimeout(0)
await register(page)
const group = { name: 'Test Poll Area ' + randomString(), public: false }
await createGroup(page, group)
const area = 'Test Tag ' + randomString()
await createArea(page, group, area)
await gotoGroup(page, group)
await createPoll(page, { phase_time: 1 })
// Testing that there's atleaest one default tag, and testing canceling that vote
await page.getByRole('radio').nth(0).check()
await page.getByRole('button', { name: 'Submit' }).click()
await expect(page.getByText('Successfully voted for area')).toBeVisible()
await page.getByRole('button', { name: 'Cancel' }).click()
await expect(page.getByText('Vote cancelled')).toBeVisible()
await areaVote(page, { area })
await fastForward(page, 1)
await page.waitForTimeout(1000)
await expect(page.getByRole('button', { name: area })).toBeVisible()
// await page.waitForTimeout(8000)
// await page.mouse.wheel(0, -250000)
// await page.screenshot({ path: 'tests/screenshots/area.png', fullPage: true });
await page.reload()
await page.waitForLoadState('networkidle')
// await expect(page).toHaveScreenshot('tests/screenshots/area.png');
await expect(page.getByRole('button', { name: area })).toBeVisible()
})
test('Proposal-Spam-Test', async ({ page }) => {
test.setTimeout(120000)
await register(page)
const rand = randomString()
const group = { name: 'Test Group Proposals ' + rand, public: false }
await createGroup(page, group)
await gotoGroup(page, group)
await createPoll(page, { phase_time: 1 })
for (let i = 0; i < 10; i++) {
await createProposal(page, { title: `Title ${i}`, description: `Description ${i}` })
}
expect(page.getByText('Title 9 Description 9 0')).toBeDefined()
expect(page.getByText('Title 0 Description 0 0')).toBeDefined()
// Wait for all of the "Successfully added proposal" to go away before screenshotting, since they don't remain on reload
// await page.waitForTimeout(8000)
// await page.mouse.wheel(0, -20000)
// const before = await page.screenshot();
// await page.reload();
// await page.waitForLoadState('networkidle');
// const after = await page.screenshot();
// expect(after).toEqual(before)
})
test.skip('Prediction-Creation', async ({ page }) => {
await register(page)
const group = { name: 'Test Poll Prediction ' + randomString(), public: false }
await createGroup(page, group)
const area = 'Test Tag ' + randomString()
await createArea(page, group, area)
await gotoGroup(page, group)
await createPoll(page, { phase_time: 1 })
await areaVote(page, { area })
await fastForward(page, 1)
const proposal = { title: 'Test Proposal' }
await createProposal(page, proposal)
await fastForward(page, 1)
const prediction = { title: 'Test Prediction' }
await predictionStatementCreate(page, proposal, prediction)
await predictionStatementCreate(page, proposal, prediction)
await predictionStatementCreate(page, proposal, prediction)
await predictionStatementCreate(page, proposal, prediction)
})
test.skip('Prediction-Statements', async ({ page }) => {
// test.setTimeout(520000);
await register(page)
const group = { name: 'Test Prediction Statement ' + randomString(), public: true }
await createGroup(page, group)
const area = 'Tag imact test ' + Math.random().toString(36).slice(2, 10)
await createArea(page, group, area)
await gotoGroup(page, group)
//TODO: Make this test faster by decreasing time between phases more
await createPoll(page, { phase_time: 1 })
await areaVote(page, { area })
await fastForward(page, 1)
const proposal = { title: 'Test 1' }
const proposal2 = { title: 'Test 2' }
await createProposal(page, proposal)
await createProposal(page, proposal2)
await fastForward(page, 1)
await predictionStatementCreate(page, proposal, { title: 'Pred1-1' })
await predictionStatementCreate(page, proposal, { title: 'Pred1-2' })
await predictionStatementCreate(page, proposal, { title: 'Pred1-3' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-1' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-2' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-3' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-4' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-5' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-6' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-7' })
await predictionStatementCreate(page, proposal2, { title: 'Pred2-8' })
//TODO Screenshot tests
})
test.skip('Prediction-Probability', async ({ page }) => {
test.setTimeout(50000)
// await page.waitForTimeout(12000)
await register(page)
const group = { name: 'Test Group Probability Voting', public: true }
await createGroup(page, group)
const area = 'Probability test ' + randomString()
await createArea(page, group, area)
await gotoGroup(page, group)
await createPoll(page, { phase_time: 1 })
await areaVote(page, { area })
await fastForward(page, 1)
const proposal = { title: 'Test ' + randomString() }
await createProposal(page, proposal)
await createProposal(page, proposal)
await fastForward(page, 1)
const prediction = { title: 'Test Pred ' + randomString(), vote: 2 }
await predictionStatementCreate(page, proposal)
await fastForward(page, 1)
await predictionProbability(page, proposal, prediction)
await fastForward(page, 1)
await page.waitForTimeout(300)
await page.reload()
await page
.locator(`#${idfy(proposal.title)}`)
.first()
.locator('button', { hasText: 'See More' })
.click()
// Wait for probability to be calculated. If a single better bets 40% on an area that no one has ever voted on before, expect 40% aggregate bet
expect(await page.getByText('Probability: 40%').click({ timeout: 10000 }))
})
test.skip('Prediction-Probabilities', async ({ page }) => {
test.setTimeout(50000)
// await page.waitForTimeout(12000)
await register(page)
const group = { name: 'Test Group Probability-voting', public: true }
const area = 'Tag imact test ' + randomString()
const poll = { phase_time: 1, title: 'Test Poll' + randomString() }
const proposal = { title: 'Test ' + randomString() }
const prediction = { title: 'Test Pred ' + randomString(), vote: 2 }
await createGroup(page, group)
await createArea(page, group, area)
await gotoGroup(page, group)
await createPoll(page, poll)
await areaVote(page, { area })
await fastForward(page, 1)
await createProposal(page, proposal)
await createProposal(page, proposal)
await fastForward(page, 1)
await predictionStatementCreate(page, proposal, prediction)
await fastForward(page, 1)
const bPage = await newWindow()
await register(bPage)
await joinGroup(bPage, group)
await goToPost(bPage, poll)
await predictionProbability(page, proposal, prediction)
await predictionProbability(bPage, proposal, prediction)
await fastForward(page, 1)
await page.waitForTimeout(400)
await page.reload()
await page
.locator(`#${idfy(proposal.title)}`)
.first()
.locator('button', { hasText: 'See More' })
.click()
expect(await page.getByText('Probability: 40%').click({ timeout: 10000 }))
})
test.skip('Prediction-Probabilities-2', async ({ page }) => {
test.setTimeout(50000)
// await page.waitForTimeout(12000)
await register(page)
const group = { name: 'Test Group Probability-voting', public: true }
const area = 'Tag imact test ' + randomString()
const poll = { phase_time: 1, title: 'Test Poll' + randomString() }
const proposal = { title: 'Test ' + randomString() }
const prediction = { title: 'Test Pred ' + randomString(), vote: 2 }
await createGroup(page, group)
await createArea(page, group, area)
await gotoGroup(page, group)
await createPoll(page, poll)
await areaVote(page, { area })
await fastForward(page, 1)
await createProposal(page, proposal)
await createProposal(page, proposal)
await fastForward(page, 1)
await predictionStatementCreate(page, proposal, prediction)
await fastForward(page, 1)
const bPage = await newWindow()
await register(bPage)
await joinGroup(bPage, group)
await goToPost(bPage, poll)
await predictionProbability(page, proposal, prediction)
await predictionProbability(bPage, proposal, { title: prediction.title, vote: 1 })
await fastForward(page, 1)
await page.waitForTimeout(400)
await page.reload()
await page
.locator(`#${idfy(proposal.title)}`)
.first()
.locator('button', { hasText: 'See More' })
.click()
expect(await page.getByText('Probability: 30%').click({ timeout: 10000 }))
})
test('Poll-Start-To-Finish', async ({ page }) => {
// Long multi-phase flow (group, poll, proposals, several fast-forwards, votes, results)
test.slow()
await register(page)
const group = { name: 'Test Poll start to finish ' + randomString(), public: false }
await createGroup(page, group)
// await createArea(page, group, 'Tag 1')
// for (let i = 0; i < 30; i++) {
await createPoll(page, { title: 'title' + randomString(), phase_time: 1 })
// await areaVote(page, { area: 'Tag 1' })
//
// await fastForward(page, 1)
const proposal = { title: 'Test Proposal' + randomString(), vote: 2 }
const proposal2 = { title: 'Test Proposal 2' + randomString(), vote: 3 }
await createProposal(page, proposal)
await createProposal(page, proposal2)
// await predictionStatementCreate(page, proposal)
//
// await fastForward(page, 1)
//
// await predictionProbability(page, proposal)
//
// await page.waitForTimeout(500)
await fastForward(page, 3)
await page.reload()
await vote(page, proposal)
await vote(page, proposal2)
await fastForward(page, 1)
await results(page)
})
test('Date-Poll', async ({ page }) => {
await register(page)
const group = { name: 'Test Group Poll' + randomString(), public: false }
const poll = { title: 'Test Group Poll', date: true }
try {
await createGroup(page, group)
} catch {
await gotoGroup(page, group)
}
await gotoGroup(page, group)
await createPoll(page, poll)
await page.locator('#weekView > button:nth-child(45)').click()
await page.locator('#weekView > button:nth-child(46)').click()
await page.locator('#weekView > button:nth-child(55)').click()
await page.locator('#weekView > button:nth-child(64)').click()
await page.getByRole('button', { name: 'Submit' }).click()
await fastForward(page, 1)
await expect(page.getByText('Results', { exact: true })).toBeVisible()
})