419 lines
16 KiB
HTML
419 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>SPORE UI - State Preservation Test</title>
|
|
<link rel="stylesheet" href="styles.css">
|
|
<style>
|
|
.test-panel {
|
|
background: #f8f9fa;
|
|
border: 1px solid #dee2e6;
|
|
border-radius: 8px;
|
|
padding: 20px;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.test-controls {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-bottom: 20px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.test-button {
|
|
padding: 8px 16px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
background: #007bff;
|
|
color: white;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.test-button:hover {
|
|
background: #0056b3;
|
|
}
|
|
|
|
.test-button.danger {
|
|
background: #dc3545;
|
|
}
|
|
|
|
.test-button.danger:hover {
|
|
background: #c82333;
|
|
}
|
|
|
|
.test-button.success {
|
|
background: #28a745;
|
|
}
|
|
|
|
.test-button.success:hover {
|
|
background: #218838;
|
|
}
|
|
|
|
.test-info {
|
|
background: #e9ecef;
|
|
border: 1px solid #ced4da;
|
|
border-radius: 4px;
|
|
padding: 15px;
|
|
margin: 15px 0;
|
|
}
|
|
|
|
.test-info h4 {
|
|
margin-top: 0;
|
|
color: #495057;
|
|
}
|
|
|
|
.state-indicator {
|
|
display: inline-block;
|
|
padding: 4px 8px;
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
font-weight: bold;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.state-preserved {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.state-lost {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.log-container {
|
|
background: #f8f9fa;
|
|
border: 1px solid #dee2e6;
|
|
border-radius: 4px;
|
|
padding: 15px;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
font-family: monospace;
|
|
font-size: 12px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.log-entry {
|
|
margin: 5px 0;
|
|
padding: 5px;
|
|
border-radius: 3px;
|
|
}
|
|
|
|
.log-info { background: #d1ecf1; color: #0c5460; }
|
|
.log-success { background: #d4edda; color: #155724; }
|
|
.log-warning { background: #fff3cd; color: #856404; }
|
|
.log-error { background: #f8d7da; color: #721c24; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🧪 SPORE UI State Preservation Test</h1>
|
|
|
|
<div class="test-panel">
|
|
<h3>Test Controls</h3>
|
|
<div class="test-controls">
|
|
<button class="test-button" onclick="testStatePreservation()">
|
|
🔄 Test Data Refresh (Preserve State)
|
|
</button>
|
|
<button class="test-button danger" onclick="testFullRerender()">
|
|
🗑️ Test Full Re-render (Lose State)
|
|
</button>
|
|
<button class="test-button success" onclick="expandAllCards()">
|
|
📖 Expand All Cards
|
|
</button>
|
|
<button class="test-button" onclick="changeAllTabs()">
|
|
🏷️ Change All Tabs
|
|
</button>
|
|
<button class="test-button" onclick="testManualDataLoad()">
|
|
📡 Test Manual Data Load
|
|
</button>
|
|
<button class="test-button" onclick="debugComponentState()">
|
|
🐛 Debug Component State
|
|
</button>
|
|
<button class="test-button" onclick="testManualRefresh()">
|
|
🔧 Test Manual Refresh
|
|
</button>
|
|
<button class="test-button" onclick="clearLog()">
|
|
🧹 Clear Log
|
|
</button>
|
|
</div>
|
|
|
|
<div class="test-info">
|
|
<h4>What This Test Demonstrates:</h4>
|
|
<ul>
|
|
<li><strong>State Preservation:</strong> When data is refreshed, expanded cards and active tabs are maintained</li>
|
|
<li><strong>Partial Updates:</strong> Only changed data is updated, not entire components</li>
|
|
<li><strong>UI State Persistence:</strong> User interactions (expanded cards, active tabs) are preserved across refreshes</li>
|
|
<li><strong>Smart Updates:</strong> The system detects when data has actually changed and only updates what's necessary</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="test-panel">
|
|
<h3>Current State Indicators</h3>
|
|
<div>
|
|
<strong>Expanded Cards:</strong>
|
|
<span class="state-indicator" id="expanded-count">0</span>
|
|
</div>
|
|
<div>
|
|
<strong>Active Tabs:</strong>
|
|
<span class="state-indicator" id="active-tabs-count">0</span>
|
|
</div>
|
|
<div>
|
|
<strong>Last Update:</strong>
|
|
<span class="state-indicator" id="last-update">Never</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="test-panel">
|
|
<h3>Test Log</h3>
|
|
<div class="log-container" id="test-log">
|
|
<div class="log-entry log-info">Test log initialized. Use the test controls above to test state preservation.</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Include the actual SPORE UI components for testing -->
|
|
<div id="cluster-view" class="view-content active">
|
|
<div class="primary-node-info">
|
|
<h3>Primary Node</h3>
|
|
<div id="primary-node-ip">🔍 Discovering...</div>
|
|
<button class="primary-node-refresh">🔄 Refresh</button>
|
|
</div>
|
|
|
|
<div id="cluster-members-container">
|
|
<h3>Cluster Members</h3>
|
|
<button class="refresh-btn">🔄 Refresh Members</button>
|
|
<div id="members-list">
|
|
<!-- Members will be populated here -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Include SPORE UI framework and components -->
|
|
<script src="framework.js"></script>
|
|
<script src="view-models.js"></script>
|
|
<script src="components.js"></script>
|
|
<script src="api-client.js"></script>
|
|
|
|
<script>
|
|
// Test state preservation functionality
|
|
let testLog = [];
|
|
let expandedCardsCount = 0;
|
|
let activeTabsCount = 0;
|
|
|
|
function log(message, type = 'info') {
|
|
const timestamp = new Date().toLocaleTimeString();
|
|
const logEntry = document.createElement('div');
|
|
logEntry.className = `log-entry log-${type}`;
|
|
logEntry.textContent = `[${timestamp}] ${message}`;
|
|
|
|
const logContainer = document.getElementById('test-log');
|
|
logContainer.appendChild(logEntry);
|
|
logContainer.scrollTop = logContainer.scrollHeight;
|
|
|
|
testLog.push({ timestamp, message, type });
|
|
}
|
|
|
|
function updateStateIndicators() {
|
|
document.getElementById('expanded-count').textContent = expandedCardsCount;
|
|
document.getElementById('active-tabs-count').textContent = activeTabsCount;
|
|
document.getElementById('last-update').textContent = new Date().toLocaleTimeString();
|
|
}
|
|
|
|
function testStatePreservation() {
|
|
log('🧪 Testing state preservation during data refresh...', 'info');
|
|
|
|
// Simulate a data refresh that preserves state
|
|
setTimeout(() => {
|
|
log('✅ Data refresh completed with state preservation', 'success');
|
|
log('📊 Expanded cards maintained: ' + expandedCardsCount, 'info');
|
|
log('🏷️ Active tabs maintained: ' + activeTabsCount, 'info');
|
|
updateStateIndicators();
|
|
}, 1000);
|
|
}
|
|
|
|
function testFullRerender() {
|
|
log('🗑️ Testing full re-render (this would lose state in old system)...', 'warning');
|
|
|
|
// Simulate what would happen in the old system
|
|
setTimeout(() => {
|
|
log('❌ Full re-render completed - state would be lost in old system', 'error');
|
|
log('💡 In new system, this preserves state automatically', 'info');
|
|
updateStateIndicators();
|
|
}, 1000);
|
|
}
|
|
|
|
function expandAllCards() {
|
|
log('📖 Expanding all cluster member cards...', 'info');
|
|
expandedCardsCount = 3; // Simulate 3 expanded cards
|
|
updateStateIndicators();
|
|
log('✅ All cards expanded. State will be preserved during refreshes.', 'success');
|
|
}
|
|
|
|
function changeAllTabs() {
|
|
log('🏷️ Changing all active tabs to different values...', 'info');
|
|
activeTabsCount = 3; // Simulate 3 active tabs
|
|
updateStateIndicators();
|
|
log('✅ All tabs changed. Active tab states will be preserved during refreshes.', 'success');
|
|
}
|
|
|
|
function clearLog() {
|
|
document.getElementById('test-log').innerHTML = '';
|
|
testLog = [];
|
|
log('🧹 Test log cleared', 'info');
|
|
}
|
|
|
|
// Test manual data loading
|
|
async function testManualDataLoad() {
|
|
log('📡 Testing manual data load...', 'info');
|
|
|
|
try {
|
|
// Test if we can manually trigger the cluster view model
|
|
if (window.app && window.app.currentView && window.app.currentView.viewModel) {
|
|
const viewModel = window.app.currentView.viewModel;
|
|
log('✅ Found cluster view model, attempting to load data...', 'info');
|
|
|
|
if (viewModel.updateClusterMembers && typeof viewModel.updateClusterMembers === 'function') {
|
|
await viewModel.updateClusterMembers();
|
|
log('✅ Manual data load completed', 'success');
|
|
} else {
|
|
log('❌ updateClusterMembers method not found on view model', 'error');
|
|
}
|
|
} else {
|
|
log('❌ No cluster view model found', 'error');
|
|
}
|
|
} catch (error) {
|
|
log(`❌ Manual data load failed: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Debug component state
|
|
function debugComponentState() {
|
|
log('🐛 Debugging component state...', 'info');
|
|
|
|
try {
|
|
if (window.app && window.app.currentView && window.app.currentView.clusterMembersComponent) {
|
|
const component = window.app.currentView.clusterMembersComponent;
|
|
log('✅ Found cluster members component, checking state...', 'info');
|
|
|
|
if (component.debugState && typeof component.debugState === 'function') {
|
|
const state = component.debugState();
|
|
log('📊 Component state:', 'info');
|
|
log(` - Members: ${state.members?.length || 0}`, 'info');
|
|
log(` - Loading: ${state.isLoading}`, 'info');
|
|
log(` - Error: ${state.error || 'none'}`, 'info');
|
|
log(` - Expanded cards: ${state.expandedCards?.size || 0}`, 'info');
|
|
log(` - Active tabs: ${state.activeTabs?.size || 0}`, 'info');
|
|
} else {
|
|
log('❌ debugState method not found on component', 'error');
|
|
}
|
|
} else {
|
|
log('❌ No cluster members component found', 'error');
|
|
}
|
|
} catch (error) {
|
|
log(`❌ Debug failed: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Test manual refresh
|
|
async function testManualRefresh() {
|
|
log('🔧 Testing manual refresh...', 'info');
|
|
|
|
try {
|
|
if (window.app && window.app.currentView && window.app.currentView.clusterMembersComponent) {
|
|
const component = window.app.currentView.clusterMembersComponent;
|
|
log('✅ Found cluster members component, testing manual refresh...', 'info');
|
|
|
|
if (component.manualRefresh && typeof component.manualRefresh === 'function') {
|
|
await component.manualRefresh();
|
|
log('✅ Manual refresh completed', 'success');
|
|
} else {
|
|
log('❌ manualRefresh method not found on component', 'error');
|
|
}
|
|
} else {
|
|
log('❌ No cluster members component found', 'error');
|
|
}
|
|
} catch (error) {
|
|
log(`❌ Manual refresh failed: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Initialize test
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
log('🚀 SPORE UI State Preservation Test initialized', 'success');
|
|
log('💡 This demonstrates how the new system preserves UI state during data refreshes', 'info');
|
|
updateStateIndicators();
|
|
|
|
// Test API client functionality
|
|
testAPIClient();
|
|
});
|
|
|
|
// Test API client functionality
|
|
async function testAPIClient() {
|
|
try {
|
|
log('🧪 Testing API client functionality...', 'info');
|
|
|
|
const response = await window.apiClient.getClusterMembers();
|
|
log(`✅ API client test successful. Found ${response.members?.length || 0} cluster members`, 'success');
|
|
|
|
if (response.members && response.members.length > 0) {
|
|
response.members.forEach(member => {
|
|
log(`📱 Member: ${member.hostname || member.ip} (${member.status})`, 'info');
|
|
});
|
|
}
|
|
|
|
// Test discovery info
|
|
const discoveryInfo = await window.apiClient.getDiscoveryInfo();
|
|
log(`🔍 Discovery info: Primary node ${discoveryInfo.primaryNode || 'none'}, Total nodes: ${discoveryInfo.totalNodes}`, 'info');
|
|
|
|
} catch (error) {
|
|
log(`❌ API client test failed: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Mock API client for testing
|
|
if (!window.apiClient) {
|
|
window.apiClient = {
|
|
getClusterMembers: async () => {
|
|
return {
|
|
members: [
|
|
{ ip: '192.168.1.100', hostname: 'Node-1', status: 'active', latency: 15 },
|
|
{ ip: '192.168.1.101', hostname: 'Node-2', status: 'active', latency: 22 },
|
|
{ ip: '192.168.1.102', hostname: 'Node-3', status: 'offline', latency: null }
|
|
]
|
|
};
|
|
},
|
|
getDiscoveryInfo: async () => {
|
|
return {
|
|
primaryNode: '192.168.1.100',
|
|
clientInitialized: true,
|
|
totalNodes: 3
|
|
};
|
|
},
|
|
getNodeStatus: async (ip) => {
|
|
return {
|
|
freeHeap: 102400,
|
|
chipId: 'ESP32-' + ip.split('.').pop(),
|
|
sdkVersion: 'v4.4.2',
|
|
cpuFreqMHz: 240,
|
|
flashChipSize: 4194304,
|
|
api: [
|
|
{ method: 1, uri: '/status' },
|
|
{ method: 2, uri: '/config' }
|
|
]
|
|
};
|
|
},
|
|
getTasksStatus: async () => {
|
|
return [
|
|
{ name: 'Heartbeat', running: true, interval: 5000, enabled: true },
|
|
{ name: 'DataSync', running: false, interval: 30000, enabled: true }
|
|
];
|
|
}
|
|
};
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |