Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

233 lines
8.6 KiB
JavaScript

/**
* 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 { Timer, CI_TEST_USER } = require('./auth_helper');
const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
const fs = require('fs');
const path = require('path');
// NAVIGATION NOTE: Using 'domcontentloaded' instead of 'networkidle2' for page.goto()
// because networkidle2 waits for no network activity for 500ms, but WebSocket
// connections and background polling keep the network active, causing infinite hangs.
// See: test_login_validation.js and auth_helper.js for detailed explanation.
async function testSettingsValidation() {
const isCI = !!process.env.CI;
const testTimer = new Timer('test_settings_validation');
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 {
// Authenticate (CI uses pre-created user for speed)
console.log('📋 Setup: Authenticating...');
const authHelper = new AuthHelper(page, baseUrl);
try {
// Use ensureAuthenticated which tries CI user first, then falls back to registration
await authHelper.ensureAuthenticatedWithTimeout();
console.log('✅ Authenticated\n');
} catch (authError) {
console.log(`⚠️ Could not authenticate: ${authError.message}`);
console.log('❌ Cannot authenticate - skipping settings tests');
await browser.close();
testTimer.summary();
process.exit(1);
}
// Navigate to settings page
console.log('📄 Navigating to settings page...');
await page.goto(`${baseUrl}/settings/`, {
waitUntil: 'domcontentloaded',
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 (skip in CI)
if (!isCI) {
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 (skip in CI)
if (!isCI) {
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();
testTimer.summary();
process.exit(1);
}
await browser.close();
testTimer.summary();
console.log('\n✅ Test completed successfully');
}
// Run the test
testSettingsValidation().catch(console.error);