351 lines
16 KiB
HTML
351 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 - Component Caching Test</title>
|
|
<link rel="stylesheet" href="styles.css">
|
|
<style>
|
|
.test-info {
|
|
background: rgba(0, 0, 0, 0.3);
|
|
border-radius: 8px;
|
|
padding: 1rem;
|
|
margin-bottom: 1rem;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
.test-button {
|
|
background: rgba(74, 222, 128, 0.2);
|
|
border: 1px solid rgba(74, 222, 128, 0.3);
|
|
color: #4ade80;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
margin: 0.25rem;
|
|
transition: all 0.2s ease;
|
|
}
|
|
.test-button:hover {
|
|
background: rgba(74, 222, 128, 0.3);
|
|
border-color: rgba(74, 222, 128, 0.5);
|
|
}
|
|
.test-button:active {
|
|
transform: scale(0.95);
|
|
}
|
|
.test-results {
|
|
background: rgba(0, 0, 0, 0.2);
|
|
border-radius: 8px;
|
|
padding: 1rem;
|
|
margin-top: 1rem;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
font-family: monospace;
|
|
font-size: 0.9rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="test-info">
|
|
<h3>🧪 Component Caching System Test</h3>
|
|
<p>This page tests the new component caching system to verify that components are not re-rendered on view switches.</p>
|
|
<p><strong>Note:</strong> Components now start with clean default state (collapsed cards, status tab) and don't restore previous UI state.</p>
|
|
<div>
|
|
<button class="test-button" onclick="testComponentCaching()">Test Component Caching</button>
|
|
<button class="test-button" onclick="testDefaultState()">Test Default State</button>
|
|
<button class="test-button" onclick="testPerformance()">Test Performance</button>
|
|
<button class="test-button" onclick="clearTestData()">Clear Test Data</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="main-navigation">
|
|
<div class="nav-left">
|
|
<button class="nav-tab active" data-view="cluster">🌐 Cluster</button>
|
|
<button class="nav-tab" data-view="firmware">📦 Firmware</button>
|
|
</div>
|
|
<div class="nav-right">
|
|
<div class="cluster-status">🚀 Cluster Online</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="cluster-view" class="view-content active">
|
|
<div class="cluster-section">
|
|
<div class="cluster-header">
|
|
<div class="cluster-header-left">
|
|
<div class="primary-node-info">
|
|
<span class="primary-node-label">Primary Node:</span>
|
|
<span class="primary-node-ip" id="primary-node-ip">Discovering...</span>
|
|
<button class="primary-node-refresh" id="select-random-primary-btn" title="🎲 Select random primary node">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
|
|
<path d="M1 4v6h6M23 20v-6h-6"/>
|
|
<path d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15"/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<button class="refresh-btn" id="refresh-cluster-btn">
|
|
<svg class="refresh-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
<path d="M1 4v6h6M23 20v-6h-6"/>
|
|
<path d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15"/>
|
|
</svg>
|
|
Refresh
|
|
</button>
|
|
</div>
|
|
|
|
<div id="cluster-members-container">
|
|
<div class="loading">
|
|
<div>Loading cluster members...</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="firmware-view" class="view-content">
|
|
<div class="firmware-section">
|
|
<div class="firmware-overview">
|
|
<div class="firmware-actions">
|
|
<div class="action-group">
|
|
<h3>🚀 Firmware Update</h3>
|
|
<div class="firmware-upload-compact">
|
|
<div class="compact-upload-row">
|
|
<div class="file-upload-area">
|
|
<div class="target-options">
|
|
<label class="target-option">
|
|
<input type="radio" name="target-type" value="all" checked>
|
|
<span class="radio-custom"></span>
|
|
<span class="target-label">All Nodes</span>
|
|
</label>
|
|
<label class="target-option specific-node-option">
|
|
<input type="radio" name="target-type" value="specific">
|
|
<span class="radio-custom"></span>
|
|
<span class="target-label">Specific Node</span>
|
|
<select id="specific-node-select" class="node-select">
|
|
<option value="">Select a node...</option>
|
|
</select>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="file-input-wrapper">
|
|
<input type="file" id="global-firmware-file" accept=".bin,.hex" style="display: none;">
|
|
<button class="upload-btn-compact" onclick="document.getElementById('global-firmware-file').click()">
|
|
📁 Choose File
|
|
</button>
|
|
<span class="file-info" id="file-info">No file selected</span>
|
|
</div>
|
|
</div>
|
|
|
|
<button class="deploy-btn" id="deploy-btn" disabled>
|
|
🚀 Deploy
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="firmware-nodes-list" id="firmware-nodes-list">
|
|
<!-- Nodes will be populated here -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="test-results" id="test-results">
|
|
<h4>Test Results:</h4>
|
|
<div id="test-output">Run a test to see results...</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="framework.js"></script>
|
|
<script src="api-client.js"></script>
|
|
<script src="view-models.js"></script>
|
|
<script src="components.js"></script>
|
|
<script src="app.js"></script>
|
|
|
|
<script>
|
|
// Test tracking variables
|
|
let componentCreationCount = 0;
|
|
let componentMountCount = 0;
|
|
let componentUnmountCount = 0;
|
|
let componentPauseCount = 0;
|
|
let componentResumeCount = 0;
|
|
let testStartTime = 0;
|
|
|
|
// Override console.log to track component operations
|
|
const originalLog = console.log;
|
|
console.log = function(...args) {
|
|
const message = args.join(' ');
|
|
|
|
// Track component operations
|
|
if (message.includes('Constructor called')) {
|
|
componentCreationCount++;
|
|
} else if (message.includes('Mounting...')) {
|
|
componentMountCount++;
|
|
} else if (message.includes('Unmounting...')) {
|
|
componentUnmountCount++;
|
|
} else if (message.includes('Pausing...')) {
|
|
componentPauseCount++;
|
|
} else if (message.includes('Resuming...')) {
|
|
componentResumeCount++;
|
|
}
|
|
|
|
// Call original console.log
|
|
originalLog.apply(console, args);
|
|
};
|
|
|
|
// Test functions
|
|
function testComponentCaching() {
|
|
console.log('🧪 Testing component caching system...');
|
|
resetTestCounts();
|
|
|
|
const results = document.getElementById('test-output');
|
|
results.innerHTML = 'Testing component caching...<br>';
|
|
|
|
// Test rapid view switching
|
|
const clusterTab = document.querySelector('[data-view="cluster"]');
|
|
const firmwareTab = document.querySelector('[data-view="firmware"]');
|
|
|
|
let switchCount = 0;
|
|
const maxSwitches = 10;
|
|
|
|
const rapidSwitch = setInterval(() => {
|
|
if (switchCount >= maxSwitches) {
|
|
clearInterval(rapidSwitch);
|
|
analyzeResults();
|
|
return;
|
|
}
|
|
|
|
if (switchCount % 2 === 0) {
|
|
firmwareTab.click();
|
|
results.innerHTML += `Switch ${switchCount + 1}: Cluster → Firmware<br>`;
|
|
} else {
|
|
clusterTab.click();
|
|
results.innerHTML += `Switch ${switchCount + 1}: Firmware → Cluster<br>`;
|
|
}
|
|
|
|
switchCount++;
|
|
}, 200);
|
|
}
|
|
|
|
function testDefaultState() {
|
|
console.log('🧪 Testing default state...');
|
|
resetTestCounts();
|
|
|
|
const results = document.getElementById('test-output');
|
|
results.innerHTML = 'Testing default state...<br>';
|
|
|
|
// Switch to cluster view
|
|
const clusterTab = document.querySelector('[data-view="cluster"]');
|
|
clusterTab.click();
|
|
results.innerHTML += 'Switched to Cluster View.<br>';
|
|
|
|
// Check if default state is applied (collapsed cards, status tab)
|
|
setTimeout(() => {
|
|
const memberCards = document.querySelectorAll('.member-card');
|
|
const statusTab = document.querySelector('.nav-tab.active[data-view="status"]');
|
|
|
|
if (memberCards.length > 0) {
|
|
results.innerHTML += 'Checking default state:<br>';
|
|
results.innerHTML += `- Member cards are collapsed: ${memberCards.every(card => !card.classList.contains('expanded'))}<br>`;
|
|
results.innerHTML += `- Status tab is active: ${statusTab && statusTab.classList.contains('active')}<br>`;
|
|
analyzeResults();
|
|
} else {
|
|
results.innerHTML += 'No member cards found to check default state<br>';
|
|
analyzeResults();
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
function testPerformance() {
|
|
console.log('🧪 Testing performance...');
|
|
resetTestCounts();
|
|
testStartTime = performance.now();
|
|
|
|
const results = document.getElementById('test-output');
|
|
results.innerHTML = 'Testing performance with rapid switching...<br>';
|
|
|
|
// Perform rapid view switching
|
|
const clusterTab = document.querySelector('[data-view="cluster"]');
|
|
const firmwareTab = document.querySelector('[data-view="firmware"]');
|
|
|
|
let switchCount = 0;
|
|
const maxSwitches = 20;
|
|
|
|
const performanceTest = setInterval(() => {
|
|
if (switchCount >= maxSwitches) {
|
|
clearInterval(performanceTest);
|
|
const totalTime = performance.now() - testStartTime;
|
|
results.innerHTML += `Performance test completed in ${totalTime.toFixed(2)}ms<br>`;
|
|
analyzeResults();
|
|
return;
|
|
}
|
|
|
|
if (switchCount % 2 === 0) {
|
|
firmwareTab.click();
|
|
} else {
|
|
clusterTab.click();
|
|
}
|
|
|
|
switchCount++;
|
|
}, 100);
|
|
}
|
|
|
|
function resetTestCounts() {
|
|
componentCreationCount = 0;
|
|
componentMountCount = 0;
|
|
componentUnmountCount = 0;
|
|
componentPauseCount = 0;
|
|
componentResumeCount = 0;
|
|
}
|
|
|
|
function analyzeResults() {
|
|
const results = document.getElementById('test-output');
|
|
results.innerHTML += '<br><strong>Test Analysis:</strong><br>';
|
|
results.innerHTML += `Component Creations: ${componentCreationCount}<br>`;
|
|
results.innerHTML += `Component Mounts: ${componentMountCount}<br>`;
|
|
results.innerHTML += `Component Unmounts: ${componentUnmountCount}<br>`;
|
|
results.innerHTML += `Component Pauses: ${componentPauseCount}<br>`;
|
|
results.innerHTML += `Component Resumes: ${componentResumeCount}<br><br>`;
|
|
|
|
// Analyze results
|
|
if (componentCreationCount <= 2) {
|
|
results.innerHTML += '✅ <strong>PASS:</strong> Components are properly cached (not re-created)<br>';
|
|
} else {
|
|
results.innerHTML += '❌ <strong>FAIL:</strong> Components are being re-created on view switches<br>';
|
|
}
|
|
|
|
if (componentUnmountCount === 0) {
|
|
results.innerHTML += '✅ <strong>PASS:</strong> Components are never unmounted during view switches<br>';
|
|
} else {
|
|
results.innerHTML += '❌ <strong>FAIL:</strong> Components are being unmounted during view switches<br>';
|
|
}
|
|
|
|
if (componentPauseCount > 0 && componentResumeCount > 0) {
|
|
results.innerHTML += '✅ <strong>PASS:</strong> Pause/Resume pattern is working correctly<br>';
|
|
} else {
|
|
results.innerHTML += '❌ <strong>FAIL:</strong> Pause/Resume pattern is not working<br>';
|
|
}
|
|
|
|
// New test for default state behavior
|
|
if (componentCreationCount <= 2 && componentUnmountCount === 0) {
|
|
results.innerHTML += '✅ <strong>PASS:</strong> Component caching system is working correctly<br>';
|
|
results.innerHTML += '✅ <strong>PASS:</strong> Components start with clean default state<br>';
|
|
results.innerHTML += '✅ <strong>PASS:</strong> No complex state restoration causing issues<br>';
|
|
}
|
|
}
|
|
|
|
function clearTestData() {
|
|
console.log('🧪 Clearing test data...');
|
|
localStorage.removeItem('spore_cluster_expanded_cards');
|
|
localStorage.removeItem('spore_cluster_active_tabs');
|
|
console.log('🧪 Test data cleared');
|
|
|
|
const results = document.getElementById('test-output');
|
|
results.innerHTML = 'Test data cleared. Run a test to see results...';
|
|
}
|
|
|
|
// Add test info to console
|
|
console.log('🧪 SPORE UI Component Caching Test Page Loaded');
|
|
console.log('🧪 Use the test buttons above to verify the caching system works');
|
|
console.log('🧪 Expected: Components should be created once and cached, never re-created');
|
|
console.log('🧪 Expected: Components start with clean default state (collapsed cards, status tab)');
|
|
console.log('🧪 Expected: No complex state restoration causing incorrect behavior');
|
|
</script>
|
|
</body>
|
|
</html> |