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