Corp/backend/static/js/tests/chatTestsV2.html

355 lines
11 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatControllerV2 Tests - Smart Autoscroll</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding: 20px;
max-width: 1200px;
margin: 0 auto;
background: #f5f5f5;
}
header {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #333;
margin-bottom: 10px;
}
.subtitle {
color: #666;
font-size: 14px;
}
.controls {
background: white;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
display: flex;
gap: 10px;
flex-wrap: wrap;
}
button {
padding: 10px 20px;
border: none;
background: #007bff;
color: white;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background 0.2s;
}
button:hover {
background: #0056b3;
}
button.success {
background: #28a745;
}
button.success:hover {
background: #218838;
}
.test-results {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.test-results h2 {
color: #333;
margin-bottom: 15px;
font-size: 18px;
}
#test-output {
font-size: 14px;
line-height: 1.6;
}
.test-pass {
color: #28a745;
font-weight: 600;
}
.test-fail {
color: #dc3545;
font-weight: 600;
}
.console-log {
background: #1e1e1e;
color: #d4d4d4;
padding: 15px;
border-radius: 8px;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
font-size: 12px;
max-height: 400px;
overflow-y: auto;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.console-log .pass {
color: #4ec9b0;
}
.console-log .fail {
color: #f48771;
}
.console-log .test-name {
color: #dcdcaa;
font-weight: bold;
}
.stats {
display: flex;
gap: 20px;
margin-top: 15px;
}
.stat {
flex: 1;
background: #f8f9fa;
padding: 15px;
border-radius: 4px;
text-align: center;
}
.stat-label {
font-size: 12px;
color: #666;
margin-bottom: 5px;
}
.stat-value {
font-size: 24px;
font-weight: bold;
}
.stat-value.pass {
color: #28a745;
}
.stat-value.fail {
color: #dc3545;
}
.stat-value.rate {
color: #007bff;
}
/* Стили для индикатора новых сообщений */
.new-messages-indicator {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: #007bff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 25px;
cursor: pointer;
display: none;
align-items: center;
gap: 10px;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
z-index: 10000;
font-size: 14px;
font-weight: 500;
transition: all 0.3s;
}
.new-messages-indicator:hover {
background: #0056b3;
transform: translateX(-50%) scale(1.05);
}
.new-messages-indicator.show {
display: flex;
}
.new-messages-indicator .badge {
background: rgba(255,255,255,0.3);
padding: 3px 10px;
border-radius: 12px;
font-weight: bold;
min-width: 24px;
text-align: center;
}
.loading {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid #f3f3f3;
border-top: 3px solid #007bff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<header>
<h1>🧪 ChatControllerV2 - Test Suite</h1>
<p class="subtitle">Тесты умного автоскролла для рефакторированной версии V2</p>
</header>
<div class="controls">
<button onclick="runAllTests()" class="success">▶ Запустить все тесты</button>
<button onclick="clearResults()">🗑️ Очистить</button>
</div>
<div class="test-results">
<h2>📊 Результаты тестов</h2>
<div id="test-output">
<p style="color: #666;">Нажмите "Запустить все тесты" для начала</p>
</div>
<div class="stats" id="stats" style="display: none;">
<div class="stat">
<div class="stat-label">Успешно</div>
<div class="stat-value pass" id="stat-passed">0</div>
</div>
<div class="stat">
<div class="stat-label">Провалено</div>
<div class="stat-value fail" id="stat-failed">0</div>
</div>
<div class="stat">
<div class="stat-label">Процент</div>
<div class="stat-value rate" id="stat-rate">0%</div>
</div>
</div>
</div>
<div class="console-log" id="console">
<div style="color: #608b4e;">// Консоль для логов</div>
</div>
<script type="module">
import chatTestsV2 from './chatTestsV2.js';
// Перехватываем console.log для отображения в UI
const originalLog = console.log;
const originalError = console.error;
const consoleEl = document.getElementById('console');
function appendToConsole(message, type = 'log') {
const line = document.createElement('div');
if (type === 'error') {
line.innerHTML = `<span class="fail">${escapeHtml(message)}</span>`;
} else if (message.includes('✅ PASS')) {
line.innerHTML = `<span class="pass">${escapeHtml(message)}</span>`;
} else if (message.includes('❌ FAIL')) {
line.innerHTML = `<span class="fail">${escapeHtml(message)}</span>`;
} else if (message.includes('---')) {
line.innerHTML = `<span class="test-name">${escapeHtml(message)}</span>`;
} else {
line.textContent = message;
}
consoleEl.appendChild(line);
consoleEl.scrollTop = consoleEl.scrollHeight;
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = String(text);
return div.innerHTML;
}
console.log = function(...args) {
originalLog.apply(console, args);
appendToConsole(args.join(' '), 'log');
};
console.error = function(...args) {
originalError.apply(console, args);
appendToConsole(args.join(' '), 'error');
};
// Глобальные функции
window.runAllTests = async function() {
const output = document.getElementById('test-output');
output.innerHTML = '<div class="loading"></div> <span style="margin-left: 10px;">Выполнение тестов...</span>';
// Очищаем консоль
consoleEl.innerHTML = '<div style="color: #608b4e;">// Запуск тестов...</div>';
try {
const result = await chatTestsV2.runAll();
// runAll возвращает { results: [], total: { passed, failed, total, passRate } }
const { passed, failed, passRate } = result.total;
const total = passed + failed;
let html = `<h3 style="color: ${failed === 0 ? '#28a745' : '#dc3545'}; margin-bottom: 10px;">`;
html += failed === 0 ? '✅ Все тесты пройдены!' : '⚠️ Некоторые тесты провалены';
html += '</h3>';
html += '<div style="margin-top: 15px; padding: 15px; background: #f8f9fa; border-radius: 4px;">';
html += `<strong>Итого:</strong> ${passed} из ${total} тестов пройдено (${passRate}%)`;
html += '</div>';
output.innerHTML = html;
// Обновляем статистику
document.getElementById('stats').style.display = 'flex';
document.getElementById('stat-passed').textContent = passed;
document.getElementById('stat-failed').textContent = failed;
document.getElementById('stat-rate').textContent = passRate + '%';
if (failed === 0) {
document.getElementById('stat-rate').style.color = '#28a745';
}
} catch (error) {
output.innerHTML = `<div class="test-fail">❌ Ошибка выполнения тестов: ${error.message}</div>`;
console.error('Test error:', error);
}
};
window.clearResults = function() {
document.getElementById('test-output').innerHTML = '<p style="color: #666;">Нажмите "Запустить все тесты" для начала</p>';
document.getElementById('stats').style.display = 'none';
consoleEl.innerHTML = '<div style="color: #608b4e;">// Консоль для логов</div>';
};
// Автозапуск при загрузке (опционально)
// setTimeout(() => runAllTests(), 500);
console.log('✅ Test suite готов к запуску!');
</script>
</body>
</html>