![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/scripts/ |
// Browser-based Live Chat Test Script
// Run this in the browser console on a public case page
console.log('๐งช Starting Live Chat Browser Test...');
// Test configuration
const TEST_CONFIG = {
caseId: 'test-case-123',
testMessage: 'Hello from browser test!',
timeout: 10000
};
// Test results
let testResults = {
passed: 0,
failed: 0,
total: 0,
errors: []
};
// Utility functions
const log = (message, type = 'info') => {
const timestamp = new Date().toLocaleTimeString();
const styles = {
info: 'color: #0066cc',
success: 'color: #00cc00',
error: 'color: #cc0000',
warning: 'color: #cc6600'
};
console.log(`%c[${timestamp}] ${message}`, styles[type]);
};
const assert = (condition, message) => {
testResults.total++;
if (condition) {
testResults.passed++;
log(`โ
PASS: ${message}`, 'success');
} else {
testResults.failed++;
testResults.errors.push(message);
log(`โ FAIL: ${message}`, 'error');
}
};
const waitFor = (condition, timeout = 5000) => {
return new Promise((resolve, reject) => {
const startTime = Date.now();
const check = () => {
if (condition()) {
resolve(true);
} else if (Date.now() - startTime > timeout) {
reject(new Error('Timeout waiting for condition'));
} else {
setTimeout(check, 100);
}
};
check();
});
};
// Test 1: Check if LiveCaseChat component exists
const testComponentExists = () => {
log('๐งฉ Testing component existence...', 'info');
// Check if the chat button exists
const chatButton = document.querySelector('[data-testid="live-chat-button"]') ||
document.querySelector('button[class*="bg-gradient-to-r from-blue-600 to-purple-600"]');
assert(chatButton, 'Live chat button found on page');
if (chatButton) {
log('Found live chat button', 'success');
return chatButton;
}
return null;
};
// Test 2: Test WebSocket connection
const testWebSocketConnection = async () => {
log('๐ Testing WebSocket connection...', 'info');
return new Promise((resolve, reject) => {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${protocol}//${window.location.host}/_ws`;
const ws = new WebSocket(wsUrl);
let connected = false;
const timeout = setTimeout(() => {
if (!connected) {
reject(new Error('WebSocket connection timeout'));
}
}, TEST_CONFIG.timeout);
ws.onopen = () => {
log('WebSocket connected successfully', 'success');
connected = true;
clearTimeout(timeout);
ws.close();
resolve(true);
};
ws.onerror = (error) => {
log(`WebSocket error: ${error}`, 'error');
clearTimeout(timeout);
reject(error);
};
ws.onclose = () => {
log('WebSocket connection closed', 'info');
};
});
};
// Test 3: Test chat button click
const testChatButtonClick = async (chatButton) => {
log('๐ฑ๏ธ Testing chat button click...', 'info');
if (!chatButton) {
assert(false, 'No chat button to test');
return;
}
// Click the button
chatButton.click();
// Wait for chat window to appear
try {
await waitFor(() => {
const chatWindow = document.querySelector('[data-testid="live-chat-window"]') ||
document.querySelector('.fixed.bottom-6.right-6.z-50.w-96');
return chatWindow && chatWindow.style.display !== 'none';
}, 3000);
log('Chat window opened successfully', 'success');
assert(true, 'Chat window opens on button click');
} catch (error) {
log(`Chat window test failed: ${error.message}`, 'error');
assert(false, 'Chat window opens on button click');
}
};
// Test 4: Test message input
const testMessageInput = async () => {
log('โจ๏ธ Testing message input...', 'info');
try {
// Wait for chat window to be fully loaded
await waitFor(() => {
const textarea = document.querySelector('textarea[placeholder*="message"]') ||
document.querySelector('textarea[placeholder*="Type your message"]');
return textarea;
}, 3000);
const textarea = document.querySelector('textarea[placeholder*="message"]') ||
document.querySelector('textarea[placeholder*="Type your message"]');
if (textarea) {
// Test typing
textarea.value = TEST_CONFIG.testMessage;
textarea.dispatchEvent(new Event('input', { bubbles: true }));
assert(textarea.value === TEST_CONFIG.testMessage, 'Message input works');
log('Message input test passed', 'success');
return textarea;
} else {
assert(false, 'Message input field found');
}
} catch (error) {
log(`Message input test failed: ${error.message}`, 'error');
assert(false, 'Message input functionality');
}
};
// Test 5: Test send button
const testSendButton = async (textarea) => {
log('๐ค Testing send button...', 'info');
if (!textarea) {
assert(false, 'No textarea to test send functionality');
return;
}
try {
const sendButton = textarea.closest('div').querySelector('button[class*="bg-blue-600"]') ||
textarea.parentElement.querySelector('button');
if (sendButton) {
// Test if button is enabled when there's text
const isEnabled = !sendButton.disabled;
assert(isEnabled, 'Send button is enabled when message is entered');
log('Send button test passed', 'success');
} else {
assert(false, 'Send button found');
}
} catch (error) {
log(`Send button test failed: ${error.message}`, 'error');
assert(false, 'Send button functionality');
}
};
// Test 6: Test quick actions
const testQuickActions = () => {
log('โก Testing quick actions...', 'info');
try {
const quickActionButtons = document.querySelectorAll('button[class*="bg-gray-100 hover:bg-gray-200"]');
if (quickActionButtons.length > 0) {
assert(quickActionButtons.length >= 4, 'Quick action buttons present');
log(`Found ${quickActionButtons.length} quick action buttons`, 'success');
// Test clicking a quick action
const firstButton = quickActionButtons[0];
firstButton.click();
// Check if it populated the textarea
setTimeout(() => {
const textarea = document.querySelector('textarea[placeholder*="message"]') ||
document.querySelector('textarea[placeholder*="Type your message"]');
if (textarea && textarea.value.length > 0) {
assert(true, 'Quick action populates message input');
log('Quick action test passed', 'success');
} else {
assert(false, 'Quick action populates message input');
}
}, 500);
} else {
assert(false, 'Quick action buttons found');
}
} catch (error) {
log(`Quick action test failed: ${error.message}`, 'error');
assert(false, 'Quick action functionality');
}
};
// Test 7: Test chat modes
const testChatModes = () => {
log('๐ Testing chat modes...', 'info');
try {
const modeButtons = document.querySelectorAll('button[class*="px-3 py-1 text-xs rounded-full"]');
if (modeButtons.length >= 2) {
const publicButton = Array.from(modeButtons).find(btn => btn.textContent.includes('Public'));
const privateButton = Array.from(modeButtons).find(btn => btn.textContent.includes('Private'));
if (publicButton && privateButton) {
assert(true, 'Public and private mode buttons found');
// Test mode switching
privateButton.click();
setTimeout(() => {
const isPrivateActive = privateButton.classList.contains('bg-purple-100');
assert(isPrivateActive, 'Private mode can be activated');
publicButton.click();
setTimeout(() => {
const isPublicActive = publicButton.classList.contains('bg-blue-100');
assert(isPublicActive, 'Public mode can be activated');
log('Chat modes test passed', 'success');
}, 100);
}, 100);
} else {
assert(false, 'Mode buttons functional');
}
} else {
assert(false, 'Chat mode buttons found');
}
} catch (error) {
log(`Chat modes test failed: ${error.message}`, 'error');
assert(false, 'Chat mode functionality');
}
};
// Test 8: Test responsive design
const testResponsiveDesign = () => {
log('๐ฑ Testing responsive design...', 'info');
try {
const chatWindow = document.querySelector('.fixed.bottom-6.right-6.z-50.w-96');
if (chatWindow) {
const styles = window.getComputedStyle(chatWindow);
const width = styles.width;
// Check if it's responsive (should be w-96 = 24rem = 384px on desktop)
assert(width === '384px' || width.includes('rem'), 'Chat window has responsive width');
log('Responsive design test passed', 'success');
} else {
assert(false, 'Chat window found for responsive test');
}
} catch (error) {
log(`Responsive design test failed: ${error.message}`, 'error');
assert(false, 'Responsive design functionality');
}
};
// Main test runner
const runBrowserTests = async () => {
log('๐ Starting Live Chat Browser Tests...', 'info');
log('='.repeat(50), 'info');
try {
// Test 1: Component existence
const chatButton = testComponentExists();
// Test 2: WebSocket connection
await testWebSocketConnection();
// Test 3: Chat button click
await testChatButtonClick(chatButton);
// Test 4: Message input
const textarea = await testMessageInput();
// Test 5: Send button
await testSendButton(textarea);
// Test 6: Quick actions
testQuickActions();
// Test 7: Chat modes
testChatModes();
// Test 8: Responsive design
testResponsiveDesign();
} catch (error) {
log(`Test execution error: ${error.message}`, 'error');
}
// Print results
setTimeout(() => {
log('='.repeat(50), 'info');
log(`๐ Browser Test Results:`, 'info');
log(`โ
Passed: ${testResults.passed}`, 'success');
log(`โ Failed: ${testResults.failed}`, 'error');
log(`๐ Total: ${testResults.total}`, 'info');
if (testResults.errors.length > 0) {
log('โ Failed Tests:', 'error');
testResults.errors.forEach(error => {
log(` - ${error}`, 'error');
});
}
const successRate = ((testResults.passed / testResults.total) * 100).toFixed(1);
log(`๐ฏ Success Rate: ${successRate}%`, successRate >= 80 ? 'success' : 'warning');
if (testResults.failed === 0) {
log('๐ All browser tests passed! Live chat is working perfectly!', 'success');
} else {
log('โ ๏ธ Some browser tests failed. Check the errors above.', 'warning');
}
}, 2000);
};
// Auto-run tests if on a public case page
if (window.location.pathname.includes('/public/cases/')) {
log('๐ Detected public case page - running tests automatically...', 'info');
setTimeout(runBrowserTests, 2000); // Wait for page to load
} else {
log('๐ Not on a public case page. Run runBrowserTests() manually to test.', 'warning');
}
// Export for manual testing
window.runBrowserTests = runBrowserTests;
window.testResults = testResults;
console.log('๐งช Live Chat Browser Test Script Loaded!');
console.log('๐ก Run runBrowserTests() to start testing');