]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/e2e/src/po/login.po.ts
Add E2E client tests for signup approval
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / login.po.ts
CommitLineData
3419e0e1 1import { go } from '../utils'
5f92c4dc
C
2
3export class LoginPage {
6d210220 4
814e9e07
C
5 constructor (private isMobileDevice: boolean) {
6
7 }
8
5bdfa604
C
9 async login (options: {
10 username: string
11 password: string
12 displayName?: string
13 url?: string
14 }) {
15 const { username, password, url = '/login', displayName = username } = options
16
814e9e07 17 await go(url)
5f92c4dc 18
814e9e07 19 await browser.execute(`window.localStorage.setItem('no_account_setup_warning_modal', 'true')`)
3419e0e1
C
20 await browser.execute(`window.localStorage.setItem('no_instance_config_warning_modal', 'true')`)
21 await browser.execute(`window.localStorage.setItem('no_welcome_modal', 'true')`)
51b66ea7 22
814e9e07
C
23 await $('input#username').setValue(username)
24 await $('input#password').setValue(password)
0b33c520 25
3419e0e1 26 await browser.pause(1000)
5f92c4dc 27
3419e0e1 28 await $('form input[type=submit]').click()
5f92c4dc 29
814e9e07 30 if (this.isMobileDevice) {
b9b3d18d
C
31 const menuToggle = $('.top-left-block span[role=button]')
32
33 await $('h2=Our content selection').waitForDisplayed()
814e9e07
C
34
35 await menuToggle.click()
814e9e07 36
5bdfa604 37 await this.ensureIsLoggedInAs(displayName)
814e9e07 38
814e9e07 39 await menuToggle.click()
b9b3d18d 40 } else {
5bdfa604 41 await this.ensureIsLoggedInAs(displayName)
814e9e07
C
42 }
43 }
44
5bdfa604
C
45 async getLoginError (username: string, password: string) {
46 await go('/login')
47
48 await $('input#username').setValue(username)
49 await $('input#password').setValue(password)
50
51 await browser.pause(1000)
52
53 await $('form input[type=submit]').click()
54
55 return $('.alert-danger').getText()
56 }
57
814e9e07 58 async loginAsRootUser () {
5bdfa604 59 return this.login({ username: 'root', password: 'test' + this.getSuffix() })
814e9e07
C
60 }
61
62 loginOnPeerTube2 () {
5bdfa604 63 return this.login({ username: 'e2e', password: process.env.PEERTUBE2_E2E_PASSWORD, url: 'https://peertube2.cpy.re/login' })
84c7cde6
C
64 }
65
6d210220 66 async logout () {
5bdfa604 67 const loggedInDropdown = $('.logged-in-more .logged-in-info')
814e9e07 68
5bdfa604
C
69 await loggedInDropdown.waitForClickable()
70 await loggedInDropdown.click()
6d210220 71
814e9e07 72 const logout = $('.dropdown-item*=Log out')
6d210220 73
814e9e07
C
74 await logout.waitForClickable()
75 await logout.click()
6d210220 76
814e9e07
C
77 await browser.waitUntil(() => {
78 return $('.login-buttons-block, my-error-page a[href="/login"]').isDisplayed()
79 })
6d210220
C
80 }
81
1db86422
C
82 async ensureIsLoggedInAs (displayName: string) {
83 await this.getLoggedInInfoElem().waitForExist()
84
85 await expect(this.getLoggedInInfoElem()).toHaveText(displayName)
86 }
87
3419e0e1
C
88 private getLoggedInInfoElem () {
89 return $('.logged-in-display-name')
5f92c4dc 90 }
6d210220
C
91
92 private getSuffix () {
93 return browser.config.baseUrl
94 ? browser.config.baseUrl.slice(-1)
95 : '1'
96 }
5f92c4dc 97}