← back to Dear Bubbe Nextjs

archived/tests/test-voice-chat.js

114 lines

#!/usr/bin/env node
/**
 * Voice Chat Testing Script for Dear Bubbe
 * 
 * This script tests the voice chat functionality by:
 * 1. Opening the app in a browser
 * 2. Clicking the Talk mode button
 * 3. Verifying that Bubbe speaks first
 * 4. Testing the conversation flow
 */

const puppeteer = require('puppeteer');

async function testVoiceChat() {
  console.log('🎤 TESTING DEAR BUBBE VOICE CHAT');
  console.log('================================');
  
  let browser;
  try {
    browser = await puppeteer.launch({
      headless: false, // Show browser to see what's happening
      args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--use-fake-ui-for-media-stream', // Allow microphone access
        '--use-fake-device-for-media-stream',
        '--autoplay-policy=no-user-gesture-required' // Allow autoplay
      ]
    });
    
    const page = await browser.newPage();
    
    // Enable console logging from the page
    page.on('console', msg => {
      if (msg.text().includes('[VOICE CHAT]') || msg.text().includes('[CONVERSATION]')) {
        console.log('📄 PAGE:', msg.text());
      }
    });
    
    console.log('🌐 Opening Dear Bubbe at http://45.61.58.125:3011');
    await page.goto('http://45.61.58.125:3011', { waitUntil: 'networkidle0' });
    
    // Wait for page to load
    console.log('⏳ Waiting for page to fully load...');
    await page.waitForTimeout(3000);
    
    // Look for the Talk mode button
    console.log('🔍 Looking for Talk mode button...');
    await page.waitForSelector('button', { timeout: 10000 });
    
    // Find and click the Talk mode button
    const talkButton = await page.evaluateHandle(() => {
      const buttons = Array.from(document.querySelectorAll('button'));
      return buttons.find(btn => 
        btn.textContent.includes('Talk') || 
        btn.textContent.includes('🎤') ||
        btn.classList.contains('talk-mode')
      );
    });
    
    if (!talkButton || await talkButton.evaluate(node => !node)) {
      throw new Error('❌ Talk mode button not found');
    }
    
    console.log('✅ Found Talk mode button');
    
    // Click the talk button
    console.log('🎤 Clicking Talk mode button...');
    await talkButton.click();
    
    // Wait to see if voice chat activates
    console.log('⏳ Waiting 5 seconds to observe voice chat activation...');
    await page.waitForTimeout(5000);
    
    // Check if the full-screen voice chat mode is active
    const isVoiceChatActive = await page.evaluate(() => {
      // Look for indicators of voice chat mode
      const fullScreenIndicator = document.querySelector('.fixed.inset-0.z-50');
      const voiceIndicator = document.querySelector('[data-voice-active="true"]');
      const hasVoiceChat = document.body.textContent.includes('TALK') || 
                          document.body.textContent.includes('Listen');
      
      return !!(fullScreenIndicator || voiceIndicator || hasVoiceChat);
    });
    
    if (isVoiceChatActive) {
      console.log('✅ Voice chat mode appears to be active');
      console.log('🎯 SUCCESS: Talk mode activation completed');
      
      // Wait a bit longer to see if Bubbe starts talking
      console.log('👂 Listening for Bubbe to start talking...');
      await page.waitForTimeout(3000);
      
    } else {
      console.log('⚠️  Voice chat mode may not be fully active');
    }
    
    console.log('📝 Testing completed. Check browser window for visual confirmation.');
    console.log('🏁 Test finished - leaving browser open for manual verification');
    
    // Keep browser open for manual verification
    await page.waitForTimeout(10000);
    
  } catch (error) {
    console.error('❌ Error during testing:', error.message);
  } finally {
    if (browser) {
      await browser.close();
    }
  }
}

// Run the test
testVoiceChat();