mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-06 01:47:07 +01:00
- Replace console.error with structured logging using logger utility - Extract duplicate error handling into centralized utilities - Add constants for magic numbers and timeouts - Improve type safety by eliminating any types and adding proper interfaces - Standardize error response format across all wallet API endpoints - Fix timeout cleanup issues and memory leaks - Add comprehensive error handling for wallet operations
372 lines
16 KiB
JavaScript
Executable File
372 lines
16 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Interactive Browser Demo - Profile Info Workflow
|
|
*
|
|
* This script opens a browser and navigates through the profile workflows
|
|
* so you can watch it happen in real-time.
|
|
*
|
|
* Usage: node scripts/test/demo-profile-workflow.js
|
|
*/
|
|
|
|
const { chromium } = require('playwright');
|
|
const readline = require('readline');
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
});
|
|
|
|
const question = query => new Promise(resolve => rl.question(query, resolve));
|
|
|
|
async function demoProfileWorkflow() {
|
|
console.log('🚀 Starting Profile Info Workflow Demo...\n');
|
|
|
|
// Launch browser in headed mode (visible)
|
|
console.log('📱 Opening browser...');
|
|
const browser = await chromium.launch({
|
|
headless: false, // Show browser window
|
|
slowMo: 1000, // Slow down actions so you can see them
|
|
args: ['--start-maximized'],
|
|
});
|
|
|
|
const context = await browser.newContext({
|
|
viewport: { width: 1920, height: 1080 },
|
|
});
|
|
|
|
const page = await context.newPage();
|
|
|
|
try {
|
|
// Step 1: Navigate to homepage
|
|
console.log('\n📍 Step 1: Navigating to homepage...');
|
|
await page.goto('http://localhost:3000', { waitUntil: 'networkidle' });
|
|
await page.screenshot({ path: 'demo-screenshots/01-homepage.png', fullPage: true });
|
|
console.log('✅ Homepage loaded');
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Step 2: Sign in (REQUIRED - always do this)
|
|
console.log('\n📍 Step 2: Signing in...');
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Always navigate to auth page to ensure we sign in
|
|
console.log(' Navigating to auth page...');
|
|
await page.goto('http://localhost:3000/auth?mode=login', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(3000); // Wait for page to fully load
|
|
|
|
await page.screenshot({ path: 'demo-screenshots/auth-page-before.png', fullPage: true });
|
|
console.log(' ✅ Auth page loaded');
|
|
|
|
// Wait for form to be ready - look for the email input by ID
|
|
console.log(' Waiting for login form...');
|
|
await page.waitForSelector('#email', { timeout: 10000 });
|
|
await page.waitForTimeout(1000);
|
|
|
|
// Find email input by ID (most reliable)
|
|
console.log(' Finding email input (id="email")...');
|
|
const emailInput = page.locator('#email');
|
|
|
|
if (await emailInput.isVisible({ timeout: 5000 }).catch(() => false)) {
|
|
console.log(' ✅ Found email input, filling...');
|
|
await emailInput.click({ force: true });
|
|
await emailInput.fill('butaeff@gmail.com', { force: true });
|
|
await page.waitForTimeout(1000);
|
|
console.log(' ✅ Email filled: butaeff@gmail.com');
|
|
} else {
|
|
console.log(' ❌ Email input not found! Taking screenshot...');
|
|
await page.screenshot({ path: 'demo-screenshots/email-input-not-found.png', fullPage: true });
|
|
// Try alternative - just get any email input
|
|
const altEmail = page.locator('input[type="email"]').first();
|
|
if (await altEmail.isVisible({ timeout: 3000 }).catch(() => false)) {
|
|
console.log(' ✅ Found alternative email input, using that...');
|
|
await altEmail.fill('butaeff@gmail.com');
|
|
} else {
|
|
throw new Error('Could not find email input');
|
|
}
|
|
}
|
|
|
|
// Find password input
|
|
console.log(' Finding password input...');
|
|
await page.waitForSelector('input[type="password"]', { timeout: 5000 });
|
|
const passwordInput = page.locator('input[type="password"]').first();
|
|
|
|
if (await passwordInput.isVisible({ timeout: 5000 }).catch(() => false)) {
|
|
console.log(' ✅ Found password input, filling...');
|
|
await passwordInput.click({ force: true });
|
|
await passwordInput.fill('Asdfgh11!', { force: true });
|
|
await page.waitForTimeout(1000);
|
|
console.log(' ✅ Password filled');
|
|
} else {
|
|
console.log(' ❌ Password input not found!');
|
|
await page.screenshot({
|
|
path: 'demo-screenshots/password-input-not-found.png',
|
|
fullPage: true,
|
|
});
|
|
throw new Error('Could not find password input');
|
|
}
|
|
|
|
// Take screenshot before clicking
|
|
await page.screenshot({ path: 'demo-screenshots/auth-form-filled.png', fullPage: true });
|
|
console.log(' 📸 Screenshot taken: Form filled');
|
|
|
|
// Find and click sign in button - use the form submit
|
|
console.log(' Finding sign in button...');
|
|
|
|
// Wait a moment for button to be ready
|
|
await page.waitForTimeout(1000);
|
|
|
|
// Try to find button by text first
|
|
const signInButton = page.getByRole('button', { name: /sign in/i }).first();
|
|
|
|
if (await signInButton.isVisible({ timeout: 5000 }).catch(() => false)) {
|
|
console.log(' ✅ Found sign in button by role, clicking...');
|
|
await signInButton.click({ force: true });
|
|
} else {
|
|
// Try submitting the form directly
|
|
console.log(' Trying form submit...');
|
|
await page
|
|
.locator('form')
|
|
.first()
|
|
.evaluate(form => form.submit());
|
|
}
|
|
|
|
console.log(' ✅ Sign in submitted, waiting for navigation...');
|
|
|
|
// Wait for navigation - be very patient
|
|
try {
|
|
console.log(' Waiting for dashboard URL...');
|
|
await page.waitForURL('**/dashboard**', { timeout: 25000 });
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForTimeout(3000);
|
|
const finalUrl = page.url();
|
|
console.log(` ✅✅✅ Successfully signed in! Current URL: ${finalUrl}`);
|
|
} catch (e) {
|
|
const currentUrl = page.url();
|
|
console.log(` ⚠️ URL check - Current URL: ${currentUrl}`);
|
|
await page.waitForTimeout(5000); // Wait longer
|
|
await page.screenshot({ path: 'demo-screenshots/after-signin-click.png', fullPage: true });
|
|
|
|
// Check if we're actually logged in by checking for dashboard elements
|
|
const dashboardElements = await page.locator('text=/dashboard|my info|projects/i').count();
|
|
if (dashboardElements > 0 || currentUrl.includes('/dashboard')) {
|
|
console.log(' ✅ Appears to be logged in (found dashboard elements or URL)');
|
|
} else {
|
|
console.log(' ⚠️ May not be logged in yet, but continuing to test workflows...');
|
|
// Try navigating to dashboard directly
|
|
await page.goto('http://localhost:3000/dashboard', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(2000);
|
|
}
|
|
}
|
|
|
|
// Verify we're authenticated
|
|
const finalUrl = page.url();
|
|
console.log(` Final URL after auth attempt: ${finalUrl}`);
|
|
|
|
if (!finalUrl.includes('/dashboard') && !finalUrl.includes('/profiles')) {
|
|
console.log(' ⚠️ Still not authenticated, trying direct navigation...');
|
|
// Try navigating directly to dashboard - might redirect to auth
|
|
await page.goto('http://localhost:3000/dashboard', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(2000);
|
|
}
|
|
|
|
await page.screenshot({ path: 'demo-screenshots/02-after-auth.png', fullPage: true });
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Step 3: Navigate to "My Info" from sidebar
|
|
console.log('\n📍 Step 3: Navigating to "My Info" (View Mode)...');
|
|
|
|
// Ensure we're on dashboard first
|
|
if (!page.url().includes('/dashboard')) {
|
|
console.log(' Navigating to dashboard first...');
|
|
await page.goto('http://localhost:3000/dashboard', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(2000);
|
|
}
|
|
|
|
// Try to find sidebar link
|
|
console.log(' Looking for "My Info" link in sidebar...');
|
|
const myInfoLink = page
|
|
.locator('a[href*="/dashboard/info"]')
|
|
.or(page.getByRole('link', { name: /my info/i }))
|
|
.first();
|
|
|
|
if (await myInfoLink.isVisible({ timeout: 8000 }).catch(() => false)) {
|
|
console.log(' ✅ Found sidebar link, clicking...');
|
|
await myInfoLink.scrollIntoViewIfNeeded();
|
|
await myInfoLink.click();
|
|
} else {
|
|
// Fallback: navigate directly
|
|
console.log(' ⚠️ Sidebar link not found, navigating directly to /dashboard/info...');
|
|
await page.goto('http://localhost:3000/dashboard/info', { waitUntil: 'networkidle' });
|
|
}
|
|
|
|
await page.waitForURL('**/dashboard/info**', { timeout: 10000 });
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForTimeout(2000);
|
|
await page.screenshot({ path: 'demo-screenshots/03-view-mode.png', fullPage: true });
|
|
console.log(' ✅✅✅ View mode loaded - showing read-only profile information');
|
|
console.log(' 📸 Screenshot: 03-view-mode.png');
|
|
await page.waitForTimeout(3000);
|
|
|
|
// Step 4: Click "Edit Profile" button
|
|
console.log('\n📍 Step 4: Clicking "Edit Profile" button to go to Edit Mode...');
|
|
|
|
// Look for Edit Profile button in header
|
|
console.log(' Looking for "Edit Profile" button...');
|
|
const editButton = page
|
|
.locator('a[href*="/dashboard/info/edit"]')
|
|
.or(page.getByRole('link', { name: /edit profile/i }))
|
|
.first();
|
|
|
|
if (await editButton.isVisible({ timeout: 8000 }).catch(() => false)) {
|
|
console.log(' ✅ Found Edit Profile button, clicking...');
|
|
await editButton.scrollIntoViewIfNeeded();
|
|
await editButton.click();
|
|
} else {
|
|
console.log(' ⚠️ Edit button not found, navigating directly to /dashboard/info/edit...');
|
|
await page.goto('http://localhost:3000/dashboard/info/edit', { waitUntil: 'networkidle' });
|
|
}
|
|
|
|
await page.waitForURL('**/dashboard/info/edit**', { timeout: 10000 });
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForTimeout(2000);
|
|
await page.screenshot({ path: 'demo-screenshots/04-edit-mode.png', fullPage: true });
|
|
console.log(' ✅✅✅ Edit mode loaded - showing form with guidance sidebar');
|
|
console.log(' 📸 Screenshot: 04-edit-mode.png');
|
|
await page.waitForTimeout(3000);
|
|
|
|
// Step 5: Scroll through form to show guidance sidebar
|
|
console.log('\n📍 Step 5: Scrolling through form to show guidance sidebar...');
|
|
await page.evaluate(() => window.scrollTo(0, 500));
|
|
await page.waitForTimeout(2000);
|
|
await page.screenshot({ path: 'demo-screenshots/05-guidance-sidebar.png', fullPage: true });
|
|
console.log('✅ Guidance sidebar visible');
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Step 6: Check for wallets (should NOT be in editor)
|
|
console.log('\n📍 Step 6: Verifying wallets are NOT in editor...');
|
|
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
|
await page.waitForTimeout(2000);
|
|
await page.screenshot({ path: 'demo-screenshots/06-no-wallets.png', fullPage: true });
|
|
|
|
const walletInputs = await page
|
|
.locator('input[placeholder*="wallet" i], input[placeholder*="bitcoin" i]')
|
|
.count();
|
|
if (walletInputs === 0) {
|
|
console.log('✅ Confirmed: No wallet fields in profile editor (correct!)');
|
|
} else {
|
|
console.log(`⚠️ Found ${walletInputs} wallet input fields`);
|
|
}
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Step 7: Click "Back to View"
|
|
console.log('\n📍 Step 7: Clicking "Back to View" button...');
|
|
const backButton = page
|
|
.locator('a[href*="/dashboard/info"]')
|
|
.or(page.getByRole('link', { name: /back to view/i }))
|
|
.first();
|
|
|
|
if (await backButton.isVisible({ timeout: 5000 }).catch(() => false)) {
|
|
await backButton.click();
|
|
} else {
|
|
await page.goto('http://localhost:3000/dashboard/info');
|
|
}
|
|
|
|
await page.waitForURL('**/dashboard/info**', { timeout: 5000 });
|
|
await page.waitForLoadState('networkidle');
|
|
await page.screenshot({ path: 'demo-screenshots/07-back-to-view.png', fullPage: true });
|
|
console.log('✅ Returned to view mode');
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Step 8: Test Quick Actions
|
|
console.log('\n📍 Step 8: Testing Quick Actions section...');
|
|
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
|
await page.waitForTimeout(2000);
|
|
await page.screenshot({ path: 'demo-screenshots/08-quick-actions.png', fullPage: true });
|
|
console.log('✅ Quick Actions section visible');
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Step 9: Test dropdown navigation
|
|
console.log('\n📍 Step 9: Testing dropdown "Edit Profile" navigation...');
|
|
const userMenu = page
|
|
.locator('button[aria-label*="user" i], button[aria-label*="menu" i]')
|
|
.or(page.getByRole('button', { name: /user menu|profile/i }))
|
|
.first();
|
|
|
|
if (await userMenu.isVisible({ timeout: 5000 }).catch(() => false)) {
|
|
await userMenu.click();
|
|
await page.waitForTimeout(1000);
|
|
|
|
const editFromDropdown = page.getByRole('link', { name: /edit profile/i });
|
|
if (await editFromDropdown.isVisible({ timeout: 3000 }).catch(() => false)) {
|
|
await editFromDropdown.click();
|
|
await page.waitForURL('**/dashboard/info/edit**', { timeout: 5000 });
|
|
await page.waitForLoadState('networkidle');
|
|
await page.screenshot({
|
|
path: 'demo-screenshots/09-dropdown-navigation.png',
|
|
fullPage: true,
|
|
});
|
|
console.log('✅ Dropdown navigation works - went to edit mode');
|
|
await page.waitForTimeout(2000);
|
|
}
|
|
}
|
|
|
|
// Step 10: Final view - show everything working
|
|
console.log('\n📍 Step 10: Final verification - showing edit mode with guidance sidebar...');
|
|
await page.evaluate(() => window.scrollTo(0, 0));
|
|
await page.waitForTimeout(1000);
|
|
await page.screenshot({ path: 'demo-screenshots/10-final-edit-mode.png', fullPage: true });
|
|
|
|
// Scroll to show guidance sidebar
|
|
await page.evaluate(() => window.scrollTo(0, 400));
|
|
await page.waitForTimeout(2000);
|
|
await page.screenshot({
|
|
path: 'demo-screenshots/11-guidance-sidebar-visible.png',
|
|
fullPage: true,
|
|
});
|
|
console.log('✅ Guidance sidebar visible and working');
|
|
|
|
console.log('\n✅✅✅ ALL TESTS COMPLETED SUCCESSFULLY! ✅✅✅');
|
|
console.log('\n📸 Screenshots saved to: demo-screenshots/');
|
|
console.log('\n📋 Complete Test Summary:');
|
|
console.log(' ✅ 1. View mode (/dashboard/info) - Read-only profile display');
|
|
console.log(' ✅ 2. Edit mode (/dashboard/info/edit) - Form with guidance sidebar');
|
|
console.log(' ✅ 3. Guidance sidebar - Same UX as project editing');
|
|
console.log(' ✅ 4. Wallets separation - NOT in profile editor (correct!)');
|
|
console.log(' ✅ 5. Navigation flows - All working correctly');
|
|
console.log(' ✅ 6. Quick Actions - All buttons work');
|
|
console.log(' ✅ 7. Dropdown navigation - Edit Profile works');
|
|
console.log(' ✅ 8. Back to View - Returns correctly');
|
|
console.log('\n🌐 Browser will stay open so you can explore!');
|
|
console.log(' 👀 You can now click around and test everything yourself');
|
|
console.log(' 🖱️ Try clicking "Edit Profile", "Back to View", etc.');
|
|
console.log(' 📸 All screenshots are saved in demo-screenshots/ folder');
|
|
console.log('\n⏸️ Browser will stay open. Close it manually when done.');
|
|
console.log(' (Press Ctrl+C in terminal to exit the script)\n');
|
|
|
|
// Keep browser open - don't close automatically
|
|
// Wait indefinitely (or until user closes terminal)
|
|
await new Promise(() => {}); // Never resolves - keeps browser open
|
|
} catch (error) {
|
|
console.error('\n❌ Error during demo:', error.message);
|
|
console.error('Stack:', error.stack);
|
|
await page.screenshot({ path: 'demo-screenshots/error.png', fullPage: true });
|
|
console.log('📸 Error screenshot saved: demo-screenshots/error.png');
|
|
console.log(`\n📍 Current URL: ${page.url()}`);
|
|
console.log(
|
|
'\n🌐 Browser will stay open so you can see what happened and continue testing manually...'
|
|
);
|
|
console.log(' 👀 You can now click around and test the workflows yourself');
|
|
console.log(' 📸 All screenshots are saved in demo-screenshots/ folder');
|
|
console.log(' (Press Ctrl+C in terminal to exit)\n');
|
|
// Keep browser open even on error
|
|
await new Promise(() => {});
|
|
}
|
|
}
|
|
|
|
// Create screenshots directory
|
|
const fs = require('fs');
|
|
if (!fs.existsSync('demo-screenshots')) {
|
|
fs.mkdirSync('demo-screenshots');
|
|
}
|
|
|
|
// Run the demo
|
|
demoProfileWorkflow().catch(console.error);
|