Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: Add comprehensive form validation UI tests

LearningCircuit9d193298766a
diff --git a/.github/workflows/critical-ui-tests.yml b/.github/workflows/critical-ui-tests.yml
index 9f01880baa..2b6e1a4a70 100644
--- a/.github/workflows/critical-ui-tests.yml
+++ b/.github/workflows/critical-ui-tests.yml
@@ -150,13 +150,29 @@ jobs:
run: |
cd tests/ui_tests
- # Critical authentication and research submission tests
+ # Critical authentication and form validation tests
echo "Running critical authentication test..."
node test_auth_flow.js || exit 1
echo "Running registration form validation test..."
node test_register_validation.js || exit 1
+ echo "Running login form validation test..."
+ node test_login_validation.js || exit 1
+
+ echo "Running registration full flow test..."
+ node test_register_full_flow.js || exit 1
+
+ echo "Running change password validation test..."
+ node test_change_password_validation.js || exit 1
+
+ echo "Running settings validation test..."
+ node test_settings_validation.js || exit 1
+
+ echo "Running research form validation test..."
+ node test_research_form_validation.js || exit 1
+
+ # Critical research submission tests
echo "Running critical research submission tests..."
node test_research_submit.js || exit 1
node test_research_simple.js || exit 1
diff --git a/src/local_deep_research/web/templates/auth/change_password.html b/src/local_deep_research/web/templates/auth/change_password.html
index ef73a52daa..8bc0d914fe 100644
--- a/src/local_deep_research/web/templates/auth/change_password.html
+++ b/src/local_deep_research/web/templates/auth/change_password.html
@@ -215,13 +215,13 @@
if (/[^a-zA-Z0-9]/.test(password)) strength++;
// Update strength bar
- strengthBar.className = 'password-strength';
+ strengthBar.className = 'ldr-password-strength';
if (strength <= 2) {
- strengthBar.classList.add('strength-weak');
+ strengthBar.classList.add('ldr-strength-weak');
} else if (strength <= 4) {
- strengthBar.classList.add('strength-medium');
+ strengthBar.classList.add('ldr-strength-medium');
} else {
- strengthBar.classList.add('strength-strong');
+ strengthBar.classList.add('ldr-strength-strong');
}
}
diff --git a/src/local_deep_research/web/templates/auth/register.html b/src/local_deep_research/web/templates/auth/register.html
index 259174cb19..691f7a4865 100644
--- a/src/local_deep_research/web/templates/auth/register.html
+++ b/src/local_deep_research/web/templates/auth/register.html
@@ -508,13 +508,13 @@
if (/[^a-zA-Z0-9]/.test(password)) strength++;
// Update strength bar
- strengthBar.className = 'password-strength';
+ strengthBar.className = 'ldr-password-strength';
if (strength <= 2) {
- strengthBar.classList.add('strength-weak');
+ strengthBar.classList.add('ldr-strength-weak');
} else if (strength <= 4) {
- strengthBar.classList.add('strength-medium');
+ strengthBar.classList.add('ldr-strength-medium');
} else {
- strengthBar.classList.add('strength-strong');
+ strengthBar.classList.add('ldr-strength-strong');
}
}
diff --git a/tests/ui_tests/test_change_password_validation.js b/tests/ui_tests/test_change_password_validation.js
new file mode 100644
index 0000000000..f756fdf6b1
--- /dev/null
+++ b/tests/ui_tests/test_change_password_validation.js
@@ -0,0 +1,337 @@
+/**
+ * Change Password Form Validation Test
+ * Tests the change password form validation including:
+ * - CSS class consistency
+ * - Required field validation
+ * - Minlength validation
+ * - Password mismatch detection
+ * - Password strength indicator
+ * CI-compatible: Works in both local and CI environments
+ */
+
+const puppeteer = require('puppeteer');
+const AuthHelper = require('./auth_helper');
+const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
+const fs = require('fs');
+const path = require('path');
+
+async function testChangePasswordValidation() {
+ const isCI = !!process.env.CI;
+ console.log(`🧪 Running change password validation test (CI mode: ${isCI})`);
+
+ // Create screenshots directory if it doesn't exist
+ const screenshotsDir = path.join(__dirname, 'screenshots');
+ if (!fs.existsSync(screenshotsDir)) {
+ fs.mkdirSync(screenshotsDir, { recursive: true });
+ }
+
+ const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
+ const page = await browser.newPage();
+ const baseUrl = 'http://127.0.0.1:5000';
+
+ // Increase default timeout in CI
+ if (isCI) {
+ page.setDefaultTimeout(60000);
+ page.setDefaultNavigationTimeout(60000);
+ }
+
+ let testsPassed = 0;
+ let testsFailed = 0;
+
+ // Create a test user for change password tests
+ const testUser = {
+ username: `chgpwd_${Date.now()}`,
+ password: 'OldPass123!'
+ };
+
+ console.log('🧪 Starting change password validation tests...\n');
+
+ try {
+ // First, register a test user so we can test change password
+ console.log('📋 Setup: Registering test user...');
+ const authHelper = new AuthHelper(page, baseUrl);
+
+ try {
+ await authHelper.register(testUser.username, testUser.password);
+ console.log('✅ Test user registered successfully\n');
+ } catch (regError) {
+ console.log(`⚠️ Could not register test user: ${regError.message}`);
+ console.log(' Skipping change password tests - requires authenticated user\n');
+ await browser.close();
+ console.log('⚠️ Test skipped - no test user available');
+ process.exit(0); // Exit successfully since we can't test without a user
+ }
+
+ // Navigate to change password page
+ console.log('📄 Navigating to change password page...');
+ await page.goto(`${baseUrl}/auth/change-password`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ // Check if we were redirected (not authenticated)
+ const currentUrl = page.url();
+ if (currentUrl.includes('/auth/login')) {
+ console.log('⚠️ Redirected to login - user not authenticated');
+ console.log(' Attempting to login...');
+ await authHelper.login(testUser.username, testUser.password);
+ await page.goto(`${baseUrl}/auth/change-password`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+ }
+
+ // Wait for the form
+ try {
+ await page.waitForSelector('input[name="current_password"]', { timeout: 10000 });
+ console.log('✅ Change password page loaded\n');
+ } catch (e) {
+ console.log('❌ Change password page not accessible');
+ console.log(` Current URL: ${page.url()}`);
+ throw new Error('Cannot access change password page');
+ }
+
+ // Test 1: Check CSS class consistency
+ console.log('📋 Test 1: CSS class consistency');
+
+ const currentPasswordInput = await page.$('input[name="current_password"]');
+ const currentPasswordClass = await page.evaluate(el => el.className, currentPasswordInput);
+
+ if (currentPasswordClass.includes('ldr-form-control')) {
+ console.log('✅ Current password input uses ldr-form-control class');
+ testsPassed++;
+ } else {
+ console.log(`❌ Current password input has incorrect class: "${currentPasswordClass}"`);
+ testsFailed++;
+ }
+
+ const newPasswordInput = await page.$('input[name="new_password"]');
+ const newPasswordClass = await page.evaluate(el => el.className, newPasswordInput);
+
+ if (newPasswordClass.includes('ldr-form-control')) {
+ console.log('✅ New password input uses ldr-form-control class');
+ testsPassed++;
+ } else {
+ console.log(`❌ New password input has incorrect class: "${newPasswordClass}"`);
+ testsFailed++;
+ }
+
+ const confirmPasswordInput = await page.$('input[name="confirm_password"]');
+ const confirmPasswordClass = await page.evaluate(el => el.className, confirmPasswordInput);
+
+ if (confirmPasswordClass.includes('ldr-form-control')) {
+ console.log('✅ Confirm password input uses ldr-form-control class');
+ testsPassed++;
+ } else {
+ console.log(`❌ Confirm password input has incorrect class: "${confirmPasswordClass}"`);
+ testsFailed++;
+ }
+
+ // Test 2: Required field validation - current password
+ console.log('\n📋 Test 2: Current password required validation');
+
+ let validity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ valueMissing: el.validity.valueMissing,
+ required: el.required
+ }), currentPasswordInput);
+
+ console.log(` Current password - required: ${validity.required}, valueMissing: ${validity.valueMissing}`);
+
+ if (validity.required && validity.valueMissing) {
+ console.log('✅ Current password is required and empty triggers valueMissing');
+ testsPassed++;
+ } else {
+ console.log('❌ Current password should be required');
+ testsFailed++;
+ }
+
+ // Test 3: New password minlength validation
+ console.log('\n📋 Test 3: New password minlength validation');
+
+ await page.type('input[name="new_password"]', 'short', { delay: 50 });
+
+ validity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ tooShort: el.validity.tooShort,
+ minLength: el.minLength
+ }), newPasswordInput);
+
+ console.log(` Value: "short" (5 chars), minLength: ${validity.minLength}, tooShort: ${validity.tooShort}`);
+
+ if (validity.tooShort) {
+ console.log('✅ New password too short correctly triggers tooShort validity');
+ testsPassed++;
+ } else {
+ console.log('❌ New password too short should trigger tooShort validity');
+ testsFailed++;
+ }
+
+ // Test 4: Password strength indicator
+ console.log('\n📋 Test 4: Password strength indicator');
+
+ // Clear and type a password
+ await page.evaluate(() => document.querySelector('input[name="new_password"]').value = '');
+ await page.type('input[name="new_password"]', 'weakpass', { delay: 50 });
+ await new Promise(resolve => setTimeout(resolve, 200));
+
+ const strengthBar = await page.$('#password-strength');
+ const strengthVisible = await page.evaluate(el => el.style.display !== 'none', strengthBar);
+ let strengthClasses = await page.evaluate(el => el.className, strengthBar);
+
+ console.log(` Weak password - visible: ${strengthVisible}, classes: "${strengthClasses}"`);
+
+ if (strengthVisible) {
+ console.log('✅ Password strength indicator is visible');
+ testsPassed++;
+ } else {
+ console.log('❌ Password strength indicator should be visible');
+ testsFailed++;
+ }
+
+ if (strengthClasses.includes('ldr-strength-weak')) {
+ console.log('✅ Weak password shows ldr-strength-weak class');
+ testsPassed++;
+ } else {
+ console.log(`❌ Expected ldr-strength-weak class, got: "${strengthClasses}"`);
+ testsFailed++;
+ }
+
+ // Test strong password
+ await page.evaluate(() => document.querySelector('input[name="new_password"]').value = '');
+ await page.type('input[name="new_password"]', 'StrongPass123!', { delay: 50 });
+ await new Promise(resolve => setTimeout(resolve, 200));
+
+ strengthClasses = await page.evaluate(el => el.className, strengthBar);
+ console.log(` Strong password - classes: "${strengthClasses}"`);
+
+ if (strengthClasses.includes('ldr-strength-strong')) {
+ console.log('✅ Strong password shows ldr-strength-strong class');
+ testsPassed++;
+ } else {
+ console.log(`❌ Expected ldr-strength-strong class, got: "${strengthClasses}"`);
+ testsFailed++;
+ }
+
+ // Test 5: Password mismatch detection
+ console.log('\n📋 Test 5: Password mismatch detection');
+
+ // Fill form with mismatched passwords
+ await page.evaluate(() => {
+ document.querySelector('input[name="current_password"]').value = '';
+ document.querySelector('input[name="new_password"]').value = '';
+ document.querySelector('input[name="confirm_password"]').value = '';
+ });
+
+ await page.type('input[name="current_password"]', testUser.password, { delay: 30 });
+ await page.type('input[name="new_password"]', 'NewPassword123!', { delay: 30 });
+ await page.type('input[name="confirm_password"]', 'DifferentPassword!', { delay: 30 });
+
+ // Set up dialog handler to catch the alert
+ let alertMessage = null;
+ page.once('dialog', async dialog => {
+ alertMessage = dialog.message();
+ await dialog.accept();
+ });
+
+ // Try to submit the form
+ await page.click('button[type="submit"]');
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
+ if (alertMessage && alertMessage.toLowerCase().includes('match')) {
+ console.log(`✅ Password mismatch shows alert: "${alertMessage}"`);
+ testsPassed++;
+ } else {
+ console.log('❌ Password mismatch should show alert about non-matching passwords');
+ console.log(` Alert received: ${alertMessage}`);
+ testsFailed++;
+ }
+
+ // Test 6: Same password detection (new = current)
+ console.log('\n📋 Test 6: New password same as current detection');
+
+ // Clear and fill with same password
+ await page.evaluate(() => {
+ document.querySelector('input[name="current_password"]').value = '';
+ document.querySelector('input[name="new_password"]').value = '';
+ document.querySelector('input[name="confirm_password"]').value = '';
+ });
+
+ await page.type('input[name="current_password"]', testUser.password, { delay: 30 });
+ await page.type('input[name="new_password"]', testUser.password, { delay: 30 });
+ await page.type('input[name="confirm_password"]', testUser.password, { delay: 30 });
+
+ // Set up dialog handler
+ alertMessage = null;
+ page.once('dialog', async dialog => {
+ alertMessage = dialog.message();
+ await dialog.accept();
+ });
+
+ // Try to submit the form
+ await page.click('button[type="submit"]');
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
+ if (alertMessage && (alertMessage.toLowerCase().includes('different') || alertMessage.toLowerCase().includes('same'))) {
+ console.log(`✅ Same password shows alert: "${alertMessage}"`);
+ testsPassed++;
+ } else {
+ // Check if server rejected it
+ const afterUrl = page.url();
+ const errorAlert = await page.$('.alert');
+ if (afterUrl.includes('/auth/change-password') && errorAlert) {
+ const errorText = await page.evaluate(el => el.textContent, errorAlert);
+ if (errorText.toLowerCase().includes('different')) {
+ console.log(`✅ Server rejected same password: "${errorText.trim().substring(0, 50)}"`);
+ testsPassed++;
+ } else {
+ console.log(`⚠️ Alert shown but unexpected message: "${errorText.trim().substring(0, 50)}"`);
+ }
+ } else {
+ console.log('⚠️ Same password validation might be server-side only');
+ // Don't fail - this might be expected behavior
+ }
+ }
+
+ // Take a screenshot of the final state
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'change_password_validation_test.png'),
+ fullPage: true
+ });
+ console.log('\n📸 Screenshot saved to screenshots/change_password_validation_test.png');
+
+ // Summary
+ console.log('\n' + '='.repeat(50));
+ console.log(`📊 Test Summary: ${testsPassed} passed, ${testsFailed} failed`);
+ console.log('='.repeat(50));
+
+ if (testsFailed > 0) {
+ throw new Error(`${testsFailed} test(s) failed`);
+ }
+
+ console.log('\n🎉 All change password validation tests passed!');
+
+ } catch (error) {
+ console.error('\n❌ Test failed:', error.message);
+
+ // Take error screenshot
+ try {
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'change_password_validation_error.png'),
+ fullPage: true
+ });
+ console.log('📸 Error screenshot saved');
+ } catch (screenshotError) {
+ console.log('⚠️ Could not take error screenshot:', screenshotError.message);
+ }
+
+ await browser.close();
+ process.exit(1);
+ }
+
+ await browser.close();
+ console.log('\n✅ Test completed successfully');
+}
+
+// Run the test
+testChangePasswordValidation().catch(console.error);
diff --git a/tests/ui_tests/test_login_validation.js b/tests/ui_tests/test_login_validation.js
new file mode 100644
index 0000000000..b088389566
--- /dev/null
+++ b/tests/ui_tests/test_login_validation.js
@@ -0,0 +1,303 @@
+/**
+ * Login Form Validation Test
+ * Tests that the login form correctly validates input and shows appropriate errors
+ * CI-compatible: Works in both local and CI environments
+ */
+
+const puppeteer = require('puppeteer');
+const AuthHelper = require('./auth_helper');
+const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
+const fs = require('fs');
+const path = require('path');
+
+async function testLoginValidation() {
+ const isCI = !!process.env.CI;
+ console.log(`🧪 Running login form validation test (CI mode: ${isCI})`);
+
+ // Create screenshots directory if it doesn't exist
+ const screenshotsDir = path.join(__dirname, 'screenshots');
+ if (!fs.existsSync(screenshotsDir)) {
+ fs.mkdirSync(screenshotsDir, { recursive: true });
+ }
+
+ const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
+ const page = await browser.newPage();
+ const baseUrl = 'http://127.0.0.1:5000';
+
+ // Increase default timeout in CI
+ if (isCI) {
+ page.setDefaultTimeout(60000);
+ page.setDefaultNavigationTimeout(60000);
+ }
+
+ let testsPassed = 0;
+ let testsFailed = 0;
+
+ // Create a test user for login tests
+ const testUser = {
+ username: `logintest_${Date.now()}`,
+ password: 'TestPass123!'
+ };
+
+ console.log('🧪 Starting login form validation tests...\n');
+
+ try {
+ // First, register a test user so we can test valid login
+ console.log('📋 Setup: Registering test user for login tests...');
+ const authHelper = new AuthHelper(page, baseUrl);
+
+ try {
+ await authHelper.register(testUser.username, testUser.password);
+ console.log('✅ Test user registered successfully');
+
+ // Logout so we can test login
+ await authHelper.logout();
+ console.log('✅ Logged out, ready to test login form\n');
+ } catch (regError) {
+ console.log(`⚠️ Could not register test user: ${regError.message}`);
+ console.log(' Continuing with validation tests only...\n');
+ }
+
+ // Navigate to login page
+ console.log('📄 Navigating to login page...');
+ await page.goto(`${baseUrl}/auth/login`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ await page.waitForSelector('input[name="username"]', { timeout: 10000 });
+ console.log('✅ Login page loaded\n');
+
+ // Test 1: Check CSS class consistency
+ console.log('📋 Test 1: CSS class consistency');
+ const usernameInput = await page.$('input[name="username"]');
+ const usernameClass = await page.evaluate(el => el.className, usernameInput);
+
+ if (usernameClass.includes('ldr-form-control')) {
+ console.log('✅ Username input uses ldr-form-control class');
+ testsPassed++;
+ } else {
+ console.log(`❌ Username input has incorrect class: "${usernameClass}"`);
+ testsFailed++;
+ }
+
+ const passwordInput = await page.$('input[name="password"]');
+ const passwordClass = await page.evaluate(el => el.className, passwordInput);
+
+ if (passwordClass.includes('ldr-form-control')) {
+ console.log('✅ Password input uses ldr-form-control class');
+ testsPassed++;
+ } else {
+ console.log(`❌ Password input has incorrect class: "${passwordClass}"`);
+ testsFailed++;
+ }
+
+ // Test 2: Empty username validation
+ console.log('\n📋 Test 2: Empty username validation');
+
+ // Clear fields first
+ await page.evaluate(() => {
+ document.querySelector('input[name="username"]').value = '';
+ document.querySelector('input[name="password"]').value = '';
+ });
+
+ // Type only password
+ await page.type('input[name="password"]', 'somepassword', { delay: 30 });
+
+ // Check username validity
+ let validity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ valueMissing: el.validity.valueMissing
+ }), usernameInput);
+
+ console.log(` Username empty - valueMissing: ${validity.valueMissing}`);
+
+ if (validity.valueMissing) {
+ console.log('✅ Empty username correctly triggers valueMissing');
+ testsPassed++;
+ } else {
+ console.log('❌ Empty username should trigger valueMissing');
+ testsFailed++;
+ }
+
+ // Test 3: Empty password validation
+ console.log('\n📋 Test 3: Empty password validation');
+
+ // Clear and type only username
+ await page.evaluate(() => {
+ document.querySelector('input[name="username"]').value = '';
+ document.querySelector('input[name="password"]').value = '';
+ });
+
+ await page.type('input[name="username"]', 'someuser', { delay: 30 });
+
+ validity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ valueMissing: el.validity.valueMissing
+ }), passwordInput);
+
+ console.log(` Password empty - valueMissing: ${validity.valueMissing}`);
+
+ if (validity.valueMissing) {
+ console.log('✅ Empty password correctly triggers valueMissing');
+ testsPassed++;
+ } else {
+ console.log('❌ Empty password should trigger valueMissing');
+ testsFailed++;
+ }
+
+ // Test 4: Invalid credentials show error
+ console.log('\n📋 Test 4: Invalid credentials error message');
+
+ // Clear and fill with invalid credentials
+ await page.evaluate(() => {
+ document.querySelector('input[name="username"]').value = '';
+ document.querySelector('input[name="password"]').value = '';
+ });
+
+ await page.type('input[name="username"]', 'nonexistent_user_12345', { delay: 30 });
+ await page.type('input[name="password"]', 'wrongpassword123', { delay: 30 });
+
+ // Submit the form
+ await Promise.all([
+ page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 30000 }).catch(() => {}),
+ page.click('button[type="submit"]')
+ ]);
+
+ // Wait a moment for the page to update
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
+ // Check for error alert
+ const errorAlert = await page.$('.alert');
+ const currentUrl = page.url();
+
+ if (errorAlert || currentUrl.includes('/auth/login')) {
+ let errorText = '';
+ if (errorAlert) {
+ errorText = await page.evaluate(el => el.textContent, errorAlert);
+ }
+ console.log(` Still on login page with alert: "${errorText.trim().substring(0, 50)}..."`);
+
+ if (errorText.toLowerCase().includes('invalid') || errorText.toLowerCase().includes('password')) {
+ console.log('✅ Invalid credentials show appropriate error message');
+ testsPassed++;
+ } else if (currentUrl.includes('/auth/login')) {
+ console.log('✅ Invalid credentials keep user on login page');
+ testsPassed++;
+ } else {
+ console.log('⚠️ Error message may not be specific enough');
+ testsPassed++; // Still pass since login was rejected
+ }
+ } else {
+ console.log('❌ Invalid credentials should show error or stay on login page');
+ testsFailed++;
+ }
+
+ // Test 5: Valid login redirects to dashboard
+ console.log('\n📋 Test 5: Valid login redirects away from login page');
+
+ // Navigate back to login page
+ await page.goto(`${baseUrl}/auth/login`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ // Clear and fill with valid credentials
+ await page.evaluate(() => {
+ document.querySelector('input[name="username"]').value = '';
+ document.querySelector('input[name="password"]').value = '';
+ });
+
+ await page.type('input[name="username"]', testUser.username, { delay: 30 });
+ await page.type('input[name="password"]', testUser.password, { delay: 30 });
+
+ // Submit the form
+ await Promise.all([
+ page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 30000 }).catch(() => {}),
+ page.click('button[type="submit"]')
+ ]);
+
+ // Wait a moment for redirect
+ await new Promise(resolve => setTimeout(resolve, 2000));
+
+ const afterLoginUrl = page.url();
+ console.log(` After login URL: ${afterLoginUrl}`);
+
+ if (!afterLoginUrl.includes('/auth/login')) {
+ console.log('✅ Valid login redirects away from login page');
+ testsPassed++;
+ } else {
+ // Check if there's an error (might be rate limited or user not created)
+ const loginError = await page.$('.alert');
+ if (loginError) {
+ const errorText = await page.evaluate(el => el.textContent, loginError);
+ console.log(`⚠️ Login failed with error: ${errorText.trim().substring(0, 50)}`);
+ }
+ console.log('⚠️ Still on login page - test user may not have been created');
+ // Don't fail - this might be expected if registration failed earlier
+ }
+
+ // Test 6: Logged in user can access protected pages
+ console.log('\n📋 Test 6: Logged in user can access protected pages');
+
+ if (!afterLoginUrl.includes('/auth/login')) {
+ // Try to access settings page
+ await page.goto(`${baseUrl}/settings/`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ const settingsUrl = page.url();
+ if (settingsUrl.includes('/settings')) {
+ console.log('✅ Logged in user can access protected settings page');
+ testsPassed++;
+ } else {
+ console.log('❌ Logged in user was redirected away from settings');
+ testsFailed++;
+ }
+ } else {
+ console.log('⚠️ Skipping protected page test - not logged in');
+ }
+
+ // Take a screenshot of the final state
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'login_validation_test.png'),
+ fullPage: true
+ });
+ console.log('\n📸 Screenshot saved to screenshots/login_validation_test.png');
+
+ // Summary
+ console.log('\n' + '='.repeat(50));
+ console.log(`📊 Test Summary: ${testsPassed} passed, ${testsFailed} failed`);
+ console.log('='.repeat(50));
+
+ if (testsFailed > 0) {
+ throw new Error(`${testsFailed} test(s) failed`);
+ }
+
+ console.log('\n🎉 All login validation tests passed!');
+
+ } catch (error) {
+ console.error('\n❌ Test failed:', error.message);
+
+ // Take error screenshot
+ try {
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'login_validation_error.png'),
+ fullPage: true
+ });
+ console.log('📸 Error screenshot saved');
+ } catch (screenshotError) {
+ console.log('⚠️ Could not take error screenshot:', screenshotError.message);
+ }
+
+ await browser.close();
+ process.exit(1);
+ }
+
+ await browser.close();
+ console.log('\n✅ Test completed successfully');
+}
+
+// Run the test
+testLoginValidation().catch(console.error);
diff --git a/tests/ui_tests/test_register_full_flow.js b/tests/ui_tests/test_register_full_flow.js
new file mode 100644
index 0000000000..0df02703f9
--- /dev/null
+++ b/tests/ui_tests/test_register_full_flow.js
@@ -0,0 +1,338 @@
+/**
+ * Registration Full Flow Validation Test
+ * Tests the complete registration process including:
+ * - Form validation (minlength, pattern, required fields)
+ * - Password strength indicator
+ * - Password mismatch detection
+ * - Successful registration flow
+ * CI-compatible: Works in both local and CI environments
+ */
+
+const puppeteer = require('puppeteer');
+const AuthHelper = require('./auth_helper');
+const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
+const fs = require('fs');
+const path = require('path');
+
+async function testRegisterFullFlow() {
+ const isCI = !!process.env.CI;
+ console.log(`🧪 Running registration full flow test (CI mode: ${isCI})`);
+
+ // Create screenshots directory if it doesn't exist
+ const screenshotsDir = path.join(__dirname, 'screenshots');
+ if (!fs.existsSync(screenshotsDir)) {
+ fs.mkdirSync(screenshotsDir, { recursive: true });
+ }
+
+ const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
+ const page = await browser.newPage();
+ const baseUrl = 'http://127.0.0.1:5000';
+
+ // Increase default timeout in CI
+ if (isCI) {
+ page.setDefaultTimeout(60000);
+ page.setDefaultNavigationTimeout(60000);
+ }
+
+ let testsPassed = 0;
+ let testsFailed = 0;
+
+ console.log('🧪 Starting registration full flow tests...\n');
+
+ try {
+ // Navigate to register page
+ console.log('📄 Navigating to registration page...');
+ await page.goto(`${baseUrl}/auth/register`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ await page.waitForSelector('input[name="username"]', { timeout: 10000 });
+ console.log('✅ Registration page loaded\n');
+
+ // Test 1: Username too short validation
+ console.log('📋 Test 1: Username too short (< 3 chars)');
+ const usernameInput = await page.$('input[name="username"]');
+
+ await page.type('input[name="username"]', 'ab', { delay: 50 });
+
+ let validity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ tooShort: el.validity.tooShort,
+ valueMissing: el.validity.valueMissing
+ }), usernameInput);
+
+ console.log(` Value: "ab" (2 chars), tooShort: ${validity.tooShort}`);
+
+ if (validity.tooShort) {
+ console.log('✅ Username too short correctly triggers tooShort validity');
+ testsPassed++;
+ } else {
+ console.log('❌ Username too short should trigger tooShort validity');
+ testsFailed++;
+ }
+
+ // Clear and test with 3 chars (should be valid)
+ await page.evaluate(() => document.querySelector('input[name="username"]').value = '');
+ await page.type('input[name="username"]', 'abc', { delay: 50 });
+
+ validity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ tooShort: el.validity.tooShort
+ }), usernameInput);
+
+ console.log(` Value: "abc" (3 chars), tooShort: ${validity.tooShort}`);
+
+ if (!validity.tooShort) {
+ console.log('✅ Username with 3 chars passes minlength check');
+ testsPassed++;
+ } else {
+ console.log('❌ Username with 3 chars should pass minlength check');
+ testsFailed++;
+ }
+
+ // Test 2: Password too short validation
+ console.log('\n📋 Test 2: Password too short (< 8 chars)');
+ const passwordInput = await page.$('input[name="password"]');
+
+ await page.type('input[name="password"]', 'short', { delay: 50 });
+
+ validity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ tooShort: el.validity.tooShort
+ }), passwordInput);
+
+ console.log(` Value: "short" (5 chars), tooShort: ${validity.tooShort}`);
+
+ if (validity.tooShort) {
+ console.log('✅ Password too short correctly triggers tooShort validity');
+ testsPassed++;
+ } else {
+ console.log('❌ Password too short should trigger tooShort validity');
+ testsFailed++;
+ }
+
+ // Test 3: Password strength indicator
+ console.log('\n📋 Test 3: Password strength indicator');
+
+ // Clear password
+ await page.evaluate(() => document.querySelector('input[name="password"]').value = '');
+
+ // Test weak password (only lowercase, < 8 chars doesn't count)
+ await page.type('input[name="password"]', 'weakpass', { delay: 50 });
+ await new Promise(resolve => setTimeout(resolve, 200));
+
+ let strengthBar = await page.$('#password-strength');
+ let strengthVisible = await page.evaluate(el => el.style.display !== 'none', strengthBar);
+ let strengthClasses = await page.evaluate(el => el.className, strengthBar);
+
+ console.log(` Weak password "weakpass" - visible: ${strengthVisible}, classes: "${strengthClasses}"`);
+
+ if (strengthVisible) {
+ console.log('✅ Password strength indicator is visible');
+ testsPassed++;
+ } else {
+ console.log('❌ Password strength indicator should be visible');
+ testsFailed++;
+ }
+
+ // Check for correct CSS class (should be ldr-strength-weak)
+ if (strengthClasses.includes('ldr-strength-weak')) {
+ console.log('✅ Weak password shows weak strength indicator (ldr-strength-weak)');
+ testsPassed++;
+ } else {
+ console.log(`❌ Expected ldr-strength-weak class, got: "${strengthClasses}"`);
+ testsFailed++;
+ }
+
+ // Test strong password
+ await page.evaluate(() => document.querySelector('input[name="password"]').value = '');
+ await page.type('input[name="password"]', 'StrongPass123!', { delay: 50 });
+ await new Promise(resolve => setTimeout(resolve, 200));
+
+ strengthClasses = await page.evaluate(el => el.className, strengthBar);
+ console.log(` Strong password "StrongPass123!" - classes: "${strengthClasses}"`);
+
+ if (strengthClasses.includes('ldr-strength-strong')) {
+ console.log('✅ Strong password shows strong strength indicator (ldr-strength-strong)');
+ testsPassed++;
+ } else {
+ console.log(`❌ Expected ldr-strength-strong class, got: "${strengthClasses}"`);
+ testsFailed++;
+ }
+
+ // Test 4: Password mismatch detection
+ console.log('\n📋 Test 4: Password mismatch detection');
+
+ // Set up form with mismatched passwords
+ await page.evaluate(() => {
+ document.querySelector('input[name="username"]').value = '';
+ document.querySelector('input[name="password"]').value = '';
+ document.querySelector('input[name="confirm_password"]').value = '';
+ });
+
+ const testUsername = `flowtest_${Date.now()}`;
+ await page.type('input[name="username"]', testUsername, { delay: 30 });
+ await page.type('input[name="password"]', 'Password123!', { delay: 30 });
+ await page.type('input[name="confirm_password"]', 'DifferentPass!', { delay: 30 });
+
+ // Check the acknowledgment checkbox
+ const acknowledgeCheckbox = await page.$('input[name="acknowledge"]');
+ const isChecked = await page.evaluate(el => el.checked, acknowledgeCheckbox);
+ if (!isChecked) {
+ await page.click('input[name="acknowledge"]');
+ }
+
+ // Set up dialog handler to catch the alert
+ let alertMessage = null;
+ page.once('dialog', async dialog => {
+ alertMessage = dialog.message();
+ await dialog.accept();
+ });
+
+ // Try to submit the form
+ await page.click('button[type="submit"]');
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
+ if (alertMessage && alertMessage.includes('match')) {
+ console.log(`✅ Password mismatch shows alert: "${alertMessage}"`);
+ testsPassed++;
+ } else {
+ console.log('❌ Password mismatch should show alert about non-matching passwords');
+ testsFailed++;
+ }
+
+ // Test 5: Acknowledgment checkbox required
+ console.log('\n📋 Test 5: Acknowledgment checkbox validation');
+
+ // Reload the page to reset form
+ await page.goto(`${baseUrl}/auth/register`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ // Fill form correctly but don't check acknowledgment
+ await page.type('input[name="username"]', `acktest_${Date.now()}`, { delay: 30 });
+ await page.type('input[name="password"]', 'ValidPass123!', { delay: 30 });
+ await page.type('input[name="confirm_password"]', 'ValidPass123!', { delay: 30 });
+
+ // Don't check the checkbox - verify it's required
+ const checkbox = await page.$('input[name="acknowledge"]');
+ const checkboxValidity = await page.evaluate(el => ({
+ valid: el.validity.valid,
+ valueMissing: el.validity.valueMissing,
+ required: el.required
+ }), checkbox);
+
+ console.log(` Checkbox required: ${checkboxValidity.required}, valueMissing: ${checkboxValidity.valueMissing}`);
+
+ if (checkboxValidity.required) {
+ console.log('✅ Acknowledgment checkbox is required');
+ testsPassed++;
+ } else {
+ console.log('❌ Acknowledgment checkbox should be required');
+ testsFailed++;
+ }
+
+ // Test 6: Full successful registration flow
+ console.log('\n📋 Test 6: Full successful registration flow');
+
+ // Reload and fill form correctly
+ await page.goto(`${baseUrl}/auth/register`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ const newUsername = `fullflow_${Date.now()}`;
+ const newPassword = 'SecurePass123!';
+
+ await page.type('input[name="username"]', newUsername, { delay: 30 });
+ await page.type('input[name="password"]', newPassword, { delay: 30 });
+ await page.type('input[name="confirm_password"]', newPassword, { delay: 30 });
+ await page.click('input[name="acknowledge"]');
+
+ // Submit and wait for navigation
+ await Promise.all([
+ page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 60000 }).catch(() => {}),
+ page.click('button[type="submit"]')
+ ]);
+
+ // Wait for any redirects
+ await new Promise(resolve => setTimeout(resolve, 3000));
+
+ const afterRegUrl = page.url();
+ console.log(` After registration URL: ${afterRegUrl}`);
+
+ if (!afterRegUrl.includes('/auth/register')) {
+ console.log('✅ Successful registration redirects away from register page');
+ testsPassed++;
+
+ // Test 7: Newly registered user can access protected pages
+ console.log('\n📋 Test 7: Newly registered user can access system');
+
+ await page.goto(`${baseUrl}/settings/`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ const settingsUrl = page.url();
+ if (settingsUrl.includes('/settings')) {
+ console.log('✅ Newly registered user can access protected pages');
+ testsPassed++;
+ } else {
+ console.log(`❌ User redirected to: ${settingsUrl}`);
+ testsFailed++;
+ }
+ } else {
+ // Check for error message
+ const errorAlert = await page.$('.alert');
+ let errorText = '';
+ if (errorAlert) {
+ errorText = await page.evaluate(el => el.textContent, errorAlert);
+ }
+ console.log(`❌ Still on register page. Error: ${errorText.trim().substring(0, 100)}`);
+ testsFailed++;
+ }
+
+ // Take a screenshot of the final state
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'register_full_flow_test.png'),
+ fullPage: true
+ });
+ console.log('\n📸 Screenshot saved to screenshots/register_full_flow_test.png');
+
+ // Summary
+ console.log('\n' + '='.repeat(50));
+ console.log(`📊 Test Summary: ${testsPassed} passed, ${testsFailed} failed`);
+ console.log('='.repeat(50));
+
+ if (testsFailed > 0) {
+ throw new Error(`${testsFailed} test(s) failed`);
+ }
+
+ console.log('\n🎉 All registration full flow tests passed!');
+
+ } catch (error) {
+ console.error('\n❌ Test failed:', error.message);
+
+ // Take error screenshot
+ try {
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'register_full_flow_error.png'),
+ fullPage: true
+ });
+ console.log('📸 Error screenshot saved');
+ } catch (screenshotError) {
+ console.log('⚠️ Could not take error screenshot:', screenshotError.message);
+ }
+
+ await browser.close();
+ process.exit(1);
+ }
+
+ await browser.close();
+ console.log('\n✅ Test completed successfully');
+}
+
+// Run the test
+testRegisterFullFlow().catch(console.error);
diff --git a/tests/ui_tests/test_research_form_validation.js b/tests/ui_tests/test_research_form_validation.js
new file mode 100644
index 0000000000..f14d14a431
--- /dev/null
+++ b/tests/ui_tests/test_research_form_validation.js
@@ -0,0 +1,245 @@
+/**
+ * Research Form Validation Test
+ * Tests that the research form correctly validates input
+ * CI-compatible: Works in both local and CI environments
+ */
+
+const puppeteer = require('puppeteer');
+const AuthHelper = require('./auth_helper');
+const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
+const fs = require('fs');
+const path = require('path');
+
+async function testResearchFormValidation() {
+ const isCI = !!process.env.CI;
+ console.log(`🧪 Running research form validation test (CI mode: ${isCI})`);
+
+ // Create screenshots directory if it doesn't exist
+ const screenshotsDir = path.join(__dirname, 'screenshots');
+ if (!fs.existsSync(screenshotsDir)) {
+ fs.mkdirSync(screenshotsDir, { recursive: true });
+ }
+
+ const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
+ const page = await browser.newPage();
+ const baseUrl = 'http://127.0.0.1:5000';
+
+ // Increase default timeout in CI
+ if (isCI) {
+ page.setDefaultTimeout(60000);
+ page.setDefaultNavigationTimeout(60000);
+ }
+
+ let testsPassed = 0;
+ let testsFailed = 0;
+
+ console.log('🧪 Starting research form validation tests...\n');
+
+ try {
+ // Register and login
+ console.log('📋 Setup: Authenticating...');
+ const authHelper = new AuthHelper(page, baseUrl);
+ const testUser = {
+ username: `research_${Date.now()}`,
+ password: 'TestPass123!'
+ };
+
+ try {
+ await authHelper.register(testUser.username, testUser.password);
+ console.log('✅ Test user registered and logged in\n');
+ } catch (regError) {
+ console.log(`⚠️ Could not register: ${regError.message}`);
+ try {
+ await authHelper.ensureAuthenticated();
+ console.log('✅ Authenticated via existing mechanism\n');
+ } catch (authError) {
+ console.log('❌ Cannot authenticate - skipping research form tests');
+ await browser.close();
+ process.exit(0);
+ }
+ }
+
+ // Navigate to home page (research form)
+ console.log('📄 Navigating to research page...');
+ await page.goto(`${baseUrl}/`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ const currentUrl = page.url();
+ if (currentUrl.includes('/auth/login')) {
+ console.log(`❌ Redirected to login - not authenticated`);
+ throw new Error('Not authenticated');
+ }
+ console.log('✅ Research page loaded\n');
+
+ // Test 1: Research form exists
+ console.log('📋 Test 1: Research form exists');
+
+ const researchForm = await page.$('#research-form, form[action*="research"], form');
+ if (researchForm) {
+ console.log('✅ Research form found');
+ testsPassed++;
+ } else {
+ console.log('❌ Research form not found');
+ testsFailed++;
+ }
+
+ // Test 2: Query input exists and is required
+ console.log('\n📋 Test 2: Query input validation');
+
+ // Look for query textarea or input
+ const queryInput = await page.$('textarea[name="query"], input[name="query"], #query, textarea#research-query');
+
+ if (queryInput) {
+ const tagName = await page.evaluate(el => el.tagName.toLowerCase(), queryInput);
+ const isRequired = await page.evaluate(el => el.required || el.hasAttribute('required'), queryInput);
+ const placeholder = await page.evaluate(el => el.placeholder, queryInput);
+
+ console.log(` Query input type: ${tagName}, required: ${isRequired}`);
+ console.log(` Placeholder: "${placeholder?.substring(0, 40)}..."`);
+
+ console.log('✅ Query input found');
+ testsPassed++;
+
+ // Test 3: Empty query validation
+ console.log('\n📋 Test 3: Empty query handling');
+
+ // Clear the query input
+ await page.evaluate(el => el.value = '', queryInput);
+
+ // Check if submit button is disabled or if form prevents submission
+ const submitBtn = await page.$('button[type="submit"], #start-research, .ldr-btn-research');
+
+ if (submitBtn) {
+ const isDisabled = await page.evaluate(el => el.disabled, submitBtn);
+ console.log(` Submit button disabled: ${isDisabled}`);
+
+ if (isDisabled) {
+ console.log('✅ Submit button disabled for empty query');
+ testsPassed++;
+ } else {
+ // Check if there's client-side validation
+ console.log('⚠️ Submit button enabled - empty query handled server-side');
+ // This is still acceptable
+ }
+ }
+ } else {
+ console.log('⚠️ Query input not found with expected selectors');
+ }
+
+ // Test 4: Check for number inputs (iterations, questions)
+ console.log('\n📋 Test 4: Numeric inputs have constraints');
+
+ const numberInputs = await page.$$('input[type="number"]');
+ console.log(` Found ${numberInputs.length} number inputs`);
+
+ for (const input of numberInputs.slice(0, 3)) {
+ const attrs = await page.evaluate(el => ({
+ name: el.name || el.id,
+ min: el.min,
+ max: el.max,
+ value: el.value
+ }), input);
+
+ if (attrs.name) {
+ console.log(` ✓ "${attrs.name}": min=${attrs.min || 'none'}, max=${attrs.max || 'none'}, value=${attrs.value}`);
+ }
+ }
+
+ if (numberInputs.length > 0) {
+ // Check that at least one has min attribute
+ let hasMinConstraint = false;
+ for (const input of numberInputs) {
+ const min = await page.evaluate(el => el.min, input);
+ if (min) {
+ hasMinConstraint = true;
+ break;
+ }
+ }
+
+ if (hasMinConstraint) {
+ console.log('✅ Number inputs have min constraints');
+ testsPassed++;
+ } else {
+ console.log('⚠️ Number inputs may lack min constraints');
+ }
+ }
+
+ // Test 5: No JavaScript errors on page
+ console.log('\n📋 Test 5: No critical JavaScript errors');
+
+ const jsErrors = [];
+ page.on('pageerror', err => jsErrors.push(err.message));
+
+ // Interact with the form to trigger any lazy-loaded JS
+ if (queryInput) {
+ await queryInput.click();
+ await page.keyboard.type('test query', { delay: 30 });
+ await new Promise(resolve => setTimeout(resolve, 500));
+ }
+
+ if (jsErrors.length === 0) {
+ console.log('✅ No JavaScript page errors');
+ testsPassed++;
+ } else {
+ console.log(`❌ ${jsErrors.length} JavaScript error(s):`);
+ jsErrors.slice(0, 2).forEach(err => console.log(` - ${err.substring(0, 80)}`));
+ testsFailed++;
+ }
+
+ // Test 6: Form structure check
+ console.log('\n📋 Test 6: Form has expected structure');
+
+ const formElements = await page.$$('select, input[type="radio"], .ldr-dropdown, .custom-dropdown');
+ console.log(` Found ${formElements.length} selection elements (dropdowns, radios)`);
+
+ if (formElements.length > 0) {
+ console.log('✅ Form has selection elements for configuration');
+ testsPassed++;
+ } else {
+ console.log('⚠️ Form may be missing configuration options');
+ }
+
+ // Take a screenshot
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'research_form_validation_test.png'),
+ fullPage: true
+ });
+ console.log('\n📸 Screenshot saved to screenshots/research_form_validation_test.png');
+
+ // Summary
+ console.log('\n' + '='.repeat(50));
+ console.log(`📊 Test Summary: ${testsPassed} passed, ${testsFailed} failed`);
+ console.log('='.repeat(50));
+
+ if (testsFailed > 0) {
+ throw new Error(`${testsFailed} test(s) failed`);
+ }
+
+ console.log('\n🎉 All research form validation tests passed!');
+
+ } catch (error) {
+ console.error('\n❌ Test failed:', error.message);
+
+ // Take error screenshot
+ try {
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'research_form_validation_error.png'),
+ fullPage: true
+ });
+ console.log('📸 Error screenshot saved');
+ } catch (screenshotError) {
+ console.log('⚠️ Could not take error screenshot:', screenshotError.message);
+ }
+
+ await browser.close();
+ process.exit(1);
+ }
+
+ await browser.close();
+ console.log('\n✅ Test completed successfully');
+}
+
+// Run the test
+testResearchFormValidation().catch(console.error);
diff --git a/tests/ui_tests/test_settings_validation.js b/tests/ui_tests/test_settings_validation.js
new file mode 100644
index 0000000000..40fb6ebf18
--- /dev/null
+++ b/tests/ui_tests/test_settings_validation.js
@@ -0,0 +1,229 @@
+/**
+ * Settings Form Validation Test
+ * Tests that settings form inputs validate correctly
+ * CI-compatible: Works in both local and CI environments
+ */
+
+const puppeteer = require('puppeteer');
+const AuthHelper = require('./auth_helper');
+const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
+const fs = require('fs');
+const path = require('path');
+
+async function testSettingsValidation() {
+ const isCI = !!process.env.CI;
+ console.log(`🧪 Running settings validation test (CI mode: ${isCI})`);
+
+ // Create screenshots directory if it doesn't exist
+ const screenshotsDir = path.join(__dirname, 'screenshots');
+ if (!fs.existsSync(screenshotsDir)) {
+ fs.mkdirSync(screenshotsDir, { recursive: true });
+ }
+
+ const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
+ const page = await browser.newPage();
+ const baseUrl = 'http://127.0.0.1:5000';
+
+ // Increase default timeout in CI
+ if (isCI) {
+ page.setDefaultTimeout(60000);
+ page.setDefaultNavigationTimeout(60000);
+ }
+
+ let testsPassed = 0;
+ let testsFailed = 0;
+
+ console.log('🧪 Starting settings validation tests...\n');
+
+ try {
+ // Register and login
+ console.log('📋 Setup: Authenticating...');
+ const authHelper = new AuthHelper(page, baseUrl);
+ const testUser = {
+ username: `settings_${Date.now()}`,
+ password: 'TestPass123!'
+ };
+
+ try {
+ await authHelper.register(testUser.username, testUser.password);
+ console.log('✅ Test user registered and logged in\n');
+ } catch (regError) {
+ console.log(`⚠️ Could not register: ${regError.message}`);
+ // Try to ensure we're authenticated somehow
+ try {
+ await authHelper.ensureAuthenticated();
+ console.log('✅ Authenticated via existing mechanism\n');
+ } catch (authError) {
+ console.log('❌ Cannot authenticate - skipping settings tests');
+ await browser.close();
+ process.exit(0);
+ }
+ }
+
+ // Navigate to settings page
+ console.log('📄 Navigating to settings page...');
+ await page.goto(`${baseUrl}/settings/`, {
+ waitUntil: 'networkidle2',
+ timeout: 30000
+ });
+
+ const currentUrl = page.url();
+ if (!currentUrl.includes('/settings')) {
+ console.log(`❌ Could not access settings page, redirected to: ${currentUrl}`);
+ throw new Error('Cannot access settings page');
+ }
+ console.log('✅ Settings page loaded\n');
+
+ // Test 1: Page loads without JavaScript errors
+ console.log('📋 Test 1: Settings page loads without JS errors');
+
+ // Check for console errors
+ const consoleErrors = [];
+ page.on('console', msg => {
+ if (msg.type() === 'error') {
+ consoleErrors.push(msg.text());
+ }
+ });
+
+ // Wait a moment for any delayed JS to run
+ await new Promise(resolve => setTimeout(resolve, 2000));
+
+ if (consoleErrors.length === 0) {
+ console.log('✅ No JavaScript console errors detected');
+ testsPassed++;
+ } else {
+ console.log(`⚠️ ${consoleErrors.length} console error(s) detected:`);
+ consoleErrors.slice(0, 3).forEach(err => console.log(` - ${err.substring(0, 80)}`));
+ // Don't fail - some console errors might be acceptable
+ }
+
+ // Test 2: Check for number inputs with validation
+ console.log('\n📋 Test 2: Number inputs have min/max attributes');
+
+ const numberInputs = await page.$$('input[type="number"]');
+ console.log(` Found ${numberInputs.length} number inputs`);
+
+ let inputsWithValidation = 0;
+ for (const input of numberInputs.slice(0, 5)) { // Check first 5
+ const attrs = await page.evaluate(el => ({
+ name: el.name || el.id,
+ min: el.min,
+ max: el.max,
+ step: el.step
+ }), input);
+
+ if (attrs.min || attrs.max) {
+ inputsWithValidation++;
+ console.log(` ✓ "${attrs.name}" has min=${attrs.min} max=${attrs.max}`);
+ }
+ }
+
+ if (inputsWithValidation > 0 || numberInputs.length === 0) {
+ console.log('✅ Number inputs have validation attributes');
+ testsPassed++;
+ } else {
+ console.log('⚠️ Number inputs may lack validation attributes');
+ }
+
+ // Test 3: Settings form exists and has inputs
+ console.log('\n📋 Test 3: Settings form structure');
+
+ const formInputs = await page.$$('input, select, textarea');
+ console.log(` Found ${formInputs.length} form inputs`);
+
+ if (formInputs.length > 0) {
+ console.log('✅ Settings page has form inputs');
+ testsPassed++;
+ } else {
+ console.log('❌ Settings page has no form inputs');
+ testsFailed++;
+ }
+
+ // Test 4: Check for checkboxes and toggles
+ console.log('\n📋 Test 4: Checkbox/toggle inputs');
+
+ const checkboxInputs = await page.$$('input[type="checkbox"]');
+ console.log(` Found ${checkboxInputs.length} checkbox inputs`);
+
+ if (checkboxInputs.length > 0) {
+ // Try to toggle a checkbox
+ try {
+ const firstCheckbox = checkboxInputs[0];
+ const initialState = await page.evaluate(el => el.checked, firstCheckbox);
+ await firstCheckbox.click();
+ await new Promise(resolve => setTimeout(resolve, 500));
+ const newState = await page.evaluate(el => el.checked, firstCheckbox);
+
+ if (initialState !== newState) {
+ console.log('✅ Checkboxes are interactive');
+ testsPassed++;
+ } else {
+ console.log('⚠️ Checkbox click did not change state');
+ }
+
+ // Toggle back
+ await firstCheckbox.click();
+ } catch (e) {
+ console.log(`⚠️ Could not test checkbox interaction: ${e.message}`);
+ }
+ } else {
+ console.log('⚠️ No checkboxes found');
+ }
+
+ // Test 5: No error alerts on page load
+ console.log('\n📋 Test 5: No error alerts on page load');
+
+ const errorAlerts = await page.$$('.alert-danger, .error-message, .alert-error');
+ if (errorAlerts.length === 0) {
+ console.log('✅ No error alerts on settings page');
+ testsPassed++;
+ } else {
+ console.log(`⚠️ Found ${errorAlerts.length} error alert(s) on page`);
+ for (const alert of errorAlerts.slice(0, 2)) {
+ const text = await page.evaluate(el => el.textContent, alert);
+ console.log(` - ${text.trim().substring(0, 60)}`);
+ }
+ }
+
+ // Take a screenshot of the settings page
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'settings_validation_test.png'),
+ fullPage: true
+ });
+ console.log('\n📸 Screenshot saved to screenshots/settings_validation_test.png');
+
+ // Summary
+ console.log('\n' + '='.repeat(50));
+ console.log(`📊 Test Summary: ${testsPassed} passed, ${testsFailed} failed`);
+ console.log('='.repeat(50));
+
+ if (testsFailed > 0) {
+ throw new Error(`${testsFailed} test(s) failed`);
+ }
+
+ console.log('\n🎉 All settings validation tests passed!');
+
+ } catch (error) {
+ console.error('\n❌ Test failed:', error.message);
+
+ // Take error screenshot
+ try {
+ await page.screenshot({
+ path: path.join(screenshotsDir, 'settings_validation_error.png'),
+ fullPage: true
+ });
+ console.log('📸 Error screenshot saved');
+ } catch (screenshotError) {
+ console.log('⚠️ Could not take error screenshot:', screenshotError.message);
+ }
+
+ await browser.close();
+ process.exit(1);
+ }
+
+ await browser.close();
+ console.log('\n✅ Test completed successfully');
+}
+
+// Run the test
+testSettingsValidation().catch(console.error);