aboutsummaryrefslogtreecommitdiff
path: root/tests/e2e/login.spec.ts
blob: f646272bb4ad9e2d10d5ba8bba8f60415fa05548 (plain)
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
import { test, expect } from '@playwright/test';
import { credentials } from './credentials.ts';

test.describe('Loggin In - HTML Web Form @auth', () => {
    test.describe('Coming from homepage', () => {
        test('should take us to the login form @smoke', async ({ page, baseURL }) => {
            await page.goto('');

            await expect(page.locator('#loginbox')).toBeVisible();

            const loginLink = page.getByRole('link', { name: 'Login für registrierte Nutzende' });
            await expect(loginLink).toBeVisible();
            await loginLink.click();

            const benutzername = page.getByLabel(/Benutzername/i);
            await expect(benutzername).toBeVisible();
            await expect(benutzername).toBeEditable();

            const passwort = page.getByLabel(/Passwort/i);
            await expect(passwort).toBeVisible();
            await expect(passwort).toBeEditable();
        });
    });

    test.describe('Unauthorized', () => {
        test('redirects to the login form @smoke', async ({ page }) => {
            await page.goto('dispatch.php/start');

            await expect(page.getByLabel(/Passwort/)).toBeVisible();
            await expect(page.locator('#avatar-menu-container')).not.toBeVisible();
        });
    });

    test.describe('HTML Form submission', () => {
        test.beforeEach(async ({ page }) => {
            await page.goto('index.php?again=yes');
        });

        test('displays error on invalid login', async ({ page }) => {
            const benutzername = page.getByLabel(/Benutzername/i);
            const passwort = page.getByLabel(/Passwort/i);
            const submit = page.getByRole('button', { name: 'Anmelden' });

            await benutzername.fill('username');
            await passwort.fill('password');
            await submit.click();
            await expect(page.locator('css=.messagebox_error')).toBeVisible();
        });

        test('redirects to start page', async ({ page, baseURL }) => {
            const benutzername = page.getByLabel(/Benutzername/i);
            const passwort = page.getByLabel(/Passwort/i);
            const submit = page.getByRole('button', { name: 'Anmelden' });

            await benutzername.fill(credentials.autor.username);
            await passwort.fill(credentials.autor.password);
            await submit.click();
            await expect(page.locator('#notification-wrapper')).toBeVisible();
            await expect(page).toHaveURL(`${baseURL}dispatch.php/start`);
        });
    });
});