2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Add playwright tests (#8549)

- Add checks for invalid logins
This commit is contained in:
Oliver 2024-11-25 22:34:35 +11:00 committed by GitHub
parent ee9980e481
commit 51d981a102
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 103 additions and 54 deletions

View File

@ -107,12 +107,14 @@ export function AuthenticationForm() {
<TextInput <TextInput
required required
label={t`Username`} label={t`Username`}
aria-label='login-username'
placeholder={t`Your username`} placeholder={t`Your username`}
{...classicForm.getInputProps('username')} {...classicForm.getInputProps('username')}
/> />
<PasswordInput <PasswordInput
required required
label={t`Password`} label={t`Password`}
aria-label='login-password'
placeholder={t`Your password`} placeholder={t`Your password`}
{...classicForm.getInputProps('password')} {...classicForm.getInputProps('password')}
/> />
@ -228,12 +230,14 @@ export function RegistrationForm() {
<TextInput <TextInput
required required
label={t`Username`} label={t`Username`}
aria-label='register-username'
placeholder={t`Your username`} placeholder={t`Your username`}
{...registrationForm.getInputProps('username')} {...registrationForm.getInputProps('username')}
/> />
<TextInput <TextInput
required required
label={t`Email`} label={t`Email`}
aria-label='register-email'
description={t`This will be used for a confirmation`} description={t`This will be used for a confirmation`}
placeholder='email@example.org' placeholder='email@example.org'
{...registrationForm.getInputProps('email')} {...registrationForm.getInputProps('email')}
@ -241,12 +245,14 @@ export function RegistrationForm() {
<PasswordInput <PasswordInput
required required
label={t`Password`} label={t`Password`}
aria-label='register-password'
placeholder={t`Your password`} placeholder={t`Your password`}
{...registrationForm.getInputProps('password1')} {...registrationForm.getInputProps('password1')}
/> />
<PasswordInput <PasswordInput
required required
label={t`Password repeat`} label={t`Password repeat`}
aria-label='register-password-repeat'
placeholder={t`Repeat password`} placeholder={t`Repeat password`}
{...registrationForm.getInputProps('password2')} {...registrationForm.getInputProps('password2')}
/> />

View File

@ -1,54 +0,0 @@
import { expect, test } from './baseFixtures.js';
import { baseUrl, user } from './defaults.js';
import { doLogin, doQuickLogin } from './login.js';
test('Basic Login Test', async ({ page }) => {
await doLogin(page);
// Check that the username is provided
await page.getByText(user.username);
await expect(page).toHaveTitle(/^InvenTree/);
// Go to the dashboard
await page.goto(baseUrl);
await page.waitForURL('**/platform');
await page.getByText('InvenTree Demo Server -').waitFor();
// Check that the username is provided
await page.getByText(user.username);
await expect(page).toHaveTitle(/^InvenTree/);
// Go to the dashboard
await page.goto(baseUrl);
await page.waitForURL('**/platform');
// Logout (via menu)
await page.getByRole('button', { name: 'Ally Access' }).click();
await page.getByRole('menuitem', { name: 'Logout' }).click();
await page.waitForURL('**/platform/login');
await page.getByLabel('username');
});
test('Quick Login Test', async ({ page }) => {
await doQuickLogin(page);
// Check that the username is provided
await page.getByText(user.username);
await expect(page).toHaveTitle(/^InvenTree/);
// Go to the dashboard
await page.goto(baseUrl);
await page.waitForURL('**/platform');
await page.getByText('InvenTree Demo Server - ').waitFor();
// Logout (via URL)
await page.goto(`${baseUrl}/logout/`);
await page.waitForURL('**/platform/login');
await page.getByLabel('username');
});

View File

@ -0,0 +1,97 @@
import { expect, test } from './baseFixtures.js';
import { baseUrl, logoutUrl, user } from './defaults.js';
import { doLogin, doQuickLogin } from './login.js';
test('Login - Basic Test', async ({ page }) => {
await doLogin(page);
// Check that the username is provided
await page.getByText(user.username);
await expect(page).toHaveTitle(/^InvenTree/);
// Go to the dashboard
await page.goto(baseUrl);
await page.waitForURL('**/platform');
await page.getByText('InvenTree Demo Server -').waitFor();
// Check that the username is provided
await page.getByText(user.username);
await expect(page).toHaveTitle(/^InvenTree/);
// Go to the dashboard
await page.goto(baseUrl);
await page.waitForURL('**/platform');
// Logout (via menu)
await page.getByRole('button', { name: 'Ally Access' }).click();
await page.getByRole('menuitem', { name: 'Logout' }).click();
await page.waitForURL('**/platform/login');
await page.getByLabel('username');
});
test('Login - Quick Test', async ({ page }) => {
await doQuickLogin(page);
// Check that the username is provided
await page.getByText(user.username);
await expect(page).toHaveTitle(/^InvenTree/);
// Go to the dashboard
await page.goto(baseUrl);
await page.waitForURL('**/platform');
await page.getByText('InvenTree Demo Server - ').waitFor();
// Logout (via URL)
await page.goto(`${baseUrl}/logout/`);
await page.waitForURL('**/platform/login');
await page.getByLabel('username');
});
/**
* Test various types of login failure
*/
test('Login - Failures', async ({ page }) => {
const loginWithError = async () => {
await page.getByRole('button', { name: 'Log In' }).click();
await page.getByText('Login failed').waitFor();
await page.getByText('Check your input and try again').waitFor();
await page.locator('#login').getByRole('button').click();
};
// Navigate to the 'login' page
await page.goto(logoutUrl);
await expect(page).toHaveTitle(/^InvenTree.*$/);
await page.waitForURL('**/platform/login');
// Attempt login with invalid credentials
await page.getByLabel('login-username').fill('invalid user');
await page.getByLabel('login-password').fill('invalid password');
await loginWithError();
// Attempt login with valid (but disabled) user
await page.getByLabel('login-username').fill('ian');
await page.getByLabel('login-password').fill('inactive');
await loginWithError();
// Attempt login with no username
await page.getByLabel('login-username').fill('');
await page.getByLabel('login-password').fill('hunter2');
await loginWithError();
// Attempt login with no password
await page.getByLabel('login-username').fill('ian');
await page.getByLabel('login-password').fill('');
await loginWithError();
await page.waitForTimeout(2500);
});