upskill-event-manager/wordpress-dev/tests/e2e/tests/registration.spec.ts
bengizmo d6211ee364 feat(testing): Implement HVAC_Test_User_Factory and update .gitignore
- Add HVAC_Test_User_Factory class with:
  * User creation with specific roles
  * Multiple role support
  * Persona management system
  * Account cleanup integration
- Create comprehensive test suite in HVAC_Test_User_Factory_Test.php
- Update testing improvement plan documentation
- Add implementation decisions to project memory bank
- Restructure .gitignore with:
  * Whitelist approach for better file management
  * Explicit backup exclusions
  * Specific bin directory inclusions

Part of the Account Management component from the testing framework improvement plan.
2025-04-14 17:41:36 -03:00

143 lines
No EOL
5.2 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { RegistrationPage } from '../page-objects/registration-page';
import * as path from 'path';
test.describe('Community Registration Page', () => {
let registrationPage: RegistrationPage;
test.beforeEach(async ({ page }) => {
registrationPage = new RegistrationPage(page);
await registrationPage.goto();
});
test('successful registration with all fields', async ({ page }) => {
const testImagePath = path.join(__dirname, '../data/test-profile.jpg');
await registrationPage.fillRegistrationForm({
username: 'newuser' + Date.now(),
email: `test${Date.now()}@example.com`,
password: 'SecurePass123!',
confirmPassword: 'SecurePass123!',
firstName: 'John',
lastName: 'Doe',
company: 'HVAC Corp',
phone: '555-0123',
country: 'United States',
state: 'NY',
profileImagePath: testImagePath
});
await registrationPage.submit();
const successMessage = await registrationPage.getSuccessMessage();
expect(successMessage).toContain('Registration successful');
});
test('validates required fields', async ({ page }) => {
await registrationPage.submit();
const errors = await registrationPage.getErrorMessages();
expect(errors).toContain('Username is required');
expect(errors).toContain('Email is required');
expect(errors).toContain('Password is required');
expect(errors).toContain('First name is required');
expect(errors).toContain('Last name is required');
});
test('validates password complexity requirements', async ({ page }) => {
await registrationPage.fillRegistrationForm({
username: 'testuser',
email: 'test@example.com',
password: 'weak',
confirmPassword: 'weak',
firstName: 'John',
lastName: 'Doe'
});
await registrationPage.submit();
const errors = await registrationPage.getErrorMessages();
expect(errors.some(e => e && e.includes('Password must be at least 8 characters'))).toBeTruthy();
});
test('validates password confirmation match', async ({ page }) => {
await registrationPage.fillRegistrationForm({
username: 'testuser',
email: 'test@example.com',
password: 'SecurePass123!',
confirmPassword: 'DifferentPass123!',
firstName: 'John',
lastName: 'Doe'
});
await registrationPage.submit();
const errors = await registrationPage.getErrorMessages();
expect(errors).toContain('Passwords do not match');
});
test('validates email format', async ({ page }) => {
await registrationPage.fillRegistrationForm({
username: 'testuser',
email: 'invalid-email',
password: 'SecurePass123!',
confirmPassword: 'SecurePass123!',
firstName: 'John',
lastName: 'Doe'
});
await registrationPage.submit();
const errors = await registrationPage.getErrorMessages();
expect(errors).toContain('Invalid email format');
});
test('country/state logic - state field appears for US', async ({ page }) => {
await registrationPage.fillRegistrationForm({
username: 'testuser',
email: 'test@example.com',
password: 'SecurePass123!',
confirmPassword: 'SecurePass123!',
firstName: 'John',
lastName: 'Doe',
country: 'United States'
});
const isStateVisible = await registrationPage.isStateSelectVisible();
expect(isStateVisible).toBeTruthy();
const stateOptions = await registrationPage.getStateOptions();
expect(stateOptions.length).toBeGreaterThan(0);
});
test('file upload validation', async ({ page }) => {
const invalidFilePath = path.join(__dirname, '../data/invalid.txt');
await registrationPage.fillRegistrationForm({
username: 'testuser',
email: 'test@example.com',
password: 'SecurePass123!',
confirmPassword: 'SecurePass123!',
firstName: 'John',
lastName: 'Doe',
profileImagePath: invalidFilePath
});
await registrationPage.submit();
const errors = await registrationPage.getErrorMessages();
expect(errors).toContain('Invalid file type. Please upload an image');
});
test('prevents XSS in registration fields', async ({ page }) => {
const xssPayload = '<script>alert("xss")</script>';
await registrationPage.fillRegistrationForm({
username: xssPayload,
email: 'test@example.com',
password: 'SecurePass123!',
confirmPassword: 'SecurePass123!',
firstName: xssPayload,
lastName: xssPayload
});
await registrationPage.submit();
const errors = await registrationPage.getErrorMessages();
expect(errors.some(e => e && e.includes('Invalid characters in'))).toBeTruthy();
});
});