-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeneric.ts
More file actions
114 lines (93 loc) · 4.22 KB
/
generic.ts
File metadata and controls
114 lines (93 loc) · 4.22 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
import { chromium, expect } from '@playwright/test'
import 'dotenv/config'
export const idfy = (text: string) => {
return text.trim().replace(/\s+/g, '-').toLowerCase()
}
export async function newWindow() {
const browser = await chromium.launch()
const Context = await browser.newContext()
const Page = await Context.newPage()
return Page
}
export async function login(
page: any,
{ username = process.env.MAINUSER_NAME ?? 'a', password = process.env.MAINUSER_PASS ?? 'a' } = {},
) {
await page.goto(`${process.env.LINK}/login`)
await expect(page.locator('#login-page')).toBeVisible()
await page.waitForTimeout(700)
await page.fill('input[name="username"]', username)
await page.fill('input[name="password"]', password)
await page.click('button[type="submit"]')
await expect(page).toHaveURL(`${process.env.LINK}/home`)
if (await page.getByRole('button', { name: 'Ok', exact: true }).isVisible()) {
await page.getByRole('button', { name: 'Ok', exact: true }).click()
}
}
export async function loginEnter(
page: any,
{ username = process.env.MAINUSER_NAME ?? 'a', password = process.env.MAINUSER_PASS ?? 'a' } = {},
) {
await page.goto(`${process.env.LINK}/login`)
await expect(page.locator('#login-page')).toBeVisible()
await page.waitForTimeout(700)
await page.fill('input[name="username"]', username)
await page.fill('input[name="password"]', password)
await page.getByLabel('Password').press('Enter')
await expect(page).toHaveURL(`${process.env.LINK}/home`)
}
// Tests registring a user
// Only works if PUBLIC_EMAIL_REGISTRATION=FALSE in .env in the flowback-backend repository
// TODO: Automated Email testing
export async function register(page: any) {
const randomUsername = randomString()
const randomEmail = `${randomUsername}@flowback.test`
await page.goto(`${process.env.LINK}/login`)
await expect(page.locator('#login-page')).toBeVisible()
await page.waitForTimeout(500)
await page.getByRole('button', { name: 'Register' }).click()
await page.getByLabel('Email').click()
await page.getByLabel('Email').fill('a@a.se')
await page.getByRole('button', { name: 'Send' }).click()
await expect(page.getByText('You must accept terms of')).toBeVisible()
await page.getByLabel('Yes').check()
await page.getByRole('button', { name: 'Send' }).click()
await expect(page.getByText('Email already exists.')).toBeVisible()
await page.getByLabel('Email').fill(randomEmail)
let registrationCode = ''
await page.on('response', async (response: any) => {
if (response.url().includes('register') && !response.url().includes('verify')) {
registrationCode = await response.text()
}
})
await page.getByRole('button', { name: 'Send' }).click()
await expect(page.getByText('Email Sent')).toBeVisible()
await expect(page.getByText('Mail Sent')).toBeVisible()
await page.getByLabel('Verification Code').click()
await page.getByLabel('Verification Code').fill('geageageadgea')
await page.getByLabel('Username').click()
await page.getByLabel('Username').fill(randomUsername)
await page.getByLabel('Choose a Password').click()
await page.getByLabel('Choose a Password').fill(process.env.TEST_PASS)
await page.getByRole('button', { name: 'Send' }).click()
await expect(page.getByText('Wrong verification code')).toBeVisible()
await page.getByLabel('Verification Code').click()
await page.getByLabel('Verification Code').press('Control+a')
await page.getByLabel('Verification Code').fill(registrationCode.replace('"', '').replace('"', ''))
await page.getByRole('button', { name: 'Send' }).click()
await expect(page.getByText('Success')).toBeVisible()
await expect(page).toHaveURL(`${process.env.LINK}/home`)
if (await page.getByRole('button', { name: 'Ok' }).isVisible()) {
await page.getByRole('button', { name: 'Ok' }).click()
}
return { username: randomUsername, email: randomEmail, password: process.env.TEST_PASS }
}
export async function logout(page: any) {
await page.locator("#side-header-icon").click()
await page.getByRole('button', { name: 'Log Out', exact: true }).click()
await expect(page.getByRole('img', { name: 'flowback logo' })).toBeVisible()
}
export function randomString() {
const rand = Math.random().toString(36).slice(2, 10)
return rand
}