Test Theme Persistence
Ecosistema completo para organización y gestión de contenido con interfaces espaciales
Theme Persistence Test Script
🎯 Goal
Verify that themes are:
- ✅ Saved to global
themescollection - ✅ Space document updated with
themeSystem.activeThemeId - ✅ Theme persists after page refresh
📋 Test Steps
Step 1: Open Theme Designer
- Navigate to:
http://localhost:5701/space/chrome-space-1/theme-designer - Open Browser DevTools Console (F12)
- Clear console (Ctrl+L or Cmd+K)
Step 2: Create and Save New Theme
In Theme Editor:
- Name: "Test Persistence Theme"
- Description: "Testing space document update"
- Primary Color:
#FF6B6B(red) - Secondary Color:
#4ECDC4(teal)
Click "💾 Save & Apply (Override)"
Watch console for these messages:
💾 [SimpleThemeStorage] saveTheme() called! - Theme: Test Persistence Theme - Theme ID: theme-xxx - Mode: override - Set as active: true - Space ID: 69067c087ebb621cd9ff8c3f ✅ Theme saved locally: theme-xxx 🔄 Syncing theme to MongoDB themes collection... ✅ Theme synced to MongoDB: theme-xxx ⚡ Setting as active theme... 🎯 [SimpleThemeStorage] setActiveThemeId() called! - Theme ID: theme-xxx - Space ID: 69067c087ebb621cd9ff8c3f 🎯 Calling spaceApi.updateSpace()... - MongoDB space ID: 69067c087ebb621cd9ff8c3f - Theme ID: theme-xxx - Update payload: { themeSystem: { activeThemeId, updatedAt } } ✅ Space document updated successfully! - Theme system: { activeThemeId: "theme-xxx", updatedAt: "..." }If you DON'T see these logs, the save button is NOT working!
Step 3: Verify in MongoDB
Open MongoDB Compass
Navigate to:
GoGrabSpace>spacescollectionFind your space document (spaceSlug: "chrome-space-1")
Verify
themeSystemproperty exists:{ "_id": "69067c087ebb621cd9ff8c3f", "name": "Xxb7jayp", "spaceSlug": "chrome-space-1", "themeSystem": { "activeThemeId": "theme-xxx", "updatedAt": "2025-11-21T17:02:39.681Z" }, ... }Navigate to:
GoGrabSpace>themescollectionVerify theme document exists with matching
_id
Step 4: Test Persistence (Page Refresh)
Refresh the page (F5 or Cmd+R)
Clear console and watch for:
🌌 [SimpleThemeStorage] Space changed to: 69067c087ebb621cd9ff8c3f ✅ Loaded 3 themes for space 69067c087ebb621cd9ff8c3f 🔍 BOOTSTRAP: Found active theme ID: theme-xxx 🎯 ThemeStateManager: Active theme loaded: Test Persistence ThemeVerify the theme is applied - check if the red/teal colors are visible
🚨 Expected Issues
Issue 1: No save logs appear
Problem: Button click not triggering saveTheme()
Solution: Check theme-editor.component.ts - verify button click handler
Issue 2: Save logs appear but no space update logs
Problem: setActiveThemeId() failing or not being called
Solution: Check if setAsActive option is being passed correctly
Issue 3: Space update logs appear but MongoDB not updated
Problem: Backend not persisting themeSystem
Solution: Check backend logs for errors in spaces.service.ts
Issue 4: Theme loads on refresh but wrong theme
Problem: activeThemeId in space document doesn't match loaded theme
Solution: Space document out of sync - manually update in MongoDB
🔧 Quick Fixes
Fix 1: Manually Update Space Document
// Run in MongoDB Compass query:
db.spaces.updateOne(
{ _id: "69067c087ebb621cd9ff8c3f" },
{
$set: {
"themeSystem.activeThemeId": "theme-testtheme1-1763734768627",
"themeSystem.updatedAt": new Date().toISOString()
}
}
)
Fix 2: Verify Backend is Running
# Check if backend API is responding
curl http://localhost:3000/api/spaces/69067c087ebb621cd9ff8c3f
Fix 3: Check Backend Logs
# In backend terminal, watch for:
[SpacesService] 🎨 Updating themeSystem: {...}
[SpacesService] ✅ Updated space.themeSystem to: {...}
[SpacesService] ✅ Space saved to MongoDB: 69067c087ebb621cd9ff8c3f
✅ Success Criteria
- ✅ Console shows complete save flow (all logs present)
- ✅ MongoDB
spacescollection hasthemeSystemproperty - ✅ MongoDB
themescollection has theme document - ✅ After refresh, theme persists and is applied automatically
- ✅ Backend logs show successful space update
📝 Notes
- Theme ID format:
theme-{name}-{timestamp}(e.g.,theme-testpersistencetheme-1763744563627) - Space ID: Always use the MongoDB
_id, not the slug - Collection names:
themes(global themes library)spaces(user spaces withthemeSystemproperty)
- Sync interval: 3 seconds for themes collection
🐛 Debug Commands
Run in browser console:
// 1. Check current space
console.log('Space:', window.__themeService__.spaceService.currentSpace());
// 2. Check loaded themes
console.log('Themes:', window.__themeStateManager__._availableThemes());
// 3. Check active theme ID
window.__themeStorage__.getActiveThemeId().then(id => console.log('Active ID:', id));
// 4. Force save test theme
const testTheme = {
id: 'theme-debug-test-' + Date.now(),
name: 'Debug Test Theme',
mode: 'dark',
metadata: {
id: 'theme-debug-test-' + Date.now(),
name: 'Debug Test Theme',
description: 'Debug test',
mode: 'dark',
created: new Date().toISOString(),
updated: new Date().toISOString()
},
colors: {
primary: '#FF0000',
secondary: '#00FF00',
tertiary: '#0000FF',
background: '#ffffff',
surface: '#f5f5f5',
success: '#4CAF50',
warning: '#FF9800',
error: '#F44336',
info: '#2196F3'
},
cssVariables: {},
gradients: {}
};
window.__themeStorage__.saveTheme(testTheme, { mode: 'add', setAsActive: true })
.then(success => console.log('Save result:', success));