|
1 | 1 | import { expect, test } from '@nuxt/test-utils/playwright' |
2 | | -import { resetDb, createAuthTestData } from '../utils/index' |
| 2 | +import { resetDb, createAuthTestData, TEST_PARENT_USER } from '../utils/index' |
| 3 | + |
| 4 | +const TIMEOUT = 10000 // 10 seconds |
3 | 5 |
|
4 | 6 | test.describe('Login page', () => { |
5 | 7 | test.beforeEach(async ({ page, goto }) => { |
| 8 | + page.setDefaultNavigationTimeout(TIMEOUT) |
| 9 | + page.setDefaultTimeout(TIMEOUT) |
6 | 10 | await resetDb() |
7 | 11 | await createAuthTestData() |
8 | 12 | }) |
9 | 13 |
|
10 | | - test('displays the login card', async ({ page, goto }) => { |
| 14 | + test('login form is shown', async ({ page, goto }) => { |
| 15 | + await goto('/', { waitUntil: 'hydration' }) |
| 16 | + await expect(page.getByTestId('username')).toBeVisible() |
| 17 | + await expect(page.getByTestId('password')).toBeVisible() |
| 18 | + await expect(page.getByTestId('login_button')).toBeVisible() |
| 19 | + }) |
| 20 | + |
| 21 | + test('login with valid user credentials', async ({ page, goto }) => { |
| 22 | + await goto('/', { waitUntil: 'hydration' }) |
| 23 | + await page.getByTestId('username').fill(TEST_PARENT_USER.username) |
| 24 | + await page.getByTestId('password').fill(TEST_PARENT_USER.password) |
| 25 | + await page.getByTestId('login_button').click() |
| 26 | + await page.waitForURL('**/dashboard') |
| 27 | + expect(page.url()).toMatch(/\/dashboard$/) |
| 28 | + }) |
| 29 | + |
| 30 | + test('login with invalid user credentials', async ({ page, goto }) => { |
11 | 31 | await goto('/', { waitUntil: 'hydration' }) |
12 | | - await expect(page.getByTestId('login_card')).toBeVisible() |
| 32 | + await page.getByTestId('username').fill(TEST_PARENT_USER.username) |
| 33 | + await page.getByTestId('password').fill('wrongpassword') |
| 34 | + await page.getByTestId('login_button').click() |
| 35 | + await page.waitForSelector('li[role="alert"]') // wait for toast to pop up |
| 36 | + expect(page.url()).toMatch(/\/login$/) |
13 | 37 | }) |
14 | 38 | }) |
0 commit comments