Theme Persistence Testing Guide
Step-by-step testing guide for theme persistence and MongoDB integration
๐งช Theme Persistence Testing Guide
๐ฏ What Was Fixed
1. Explicit Console Logging โจ
Added console.log() statements (not just logger) to trace the complete flow:
// SimpleThemeStorageService
console.log(`๐ฏ [SimpleThemeStorage] setActiveThemeId() called!`);
console.log(`๐พ [SimpleThemeStorage] saveTheme() called!`);
console.log(`โ
Space document updated successfully!`);
2. Add vs Override Mode โจ
New functionality to control theme saving:
// Save and override existing theme (default)
await themeStorage.saveTheme(theme, { mode: 'override', setAsActive: true });
// Add as new theme (create copy if ID exists)
await themeStorage.saveTheme(theme, { mode: 'add', setAsActive: true });
3. UI Buttons โจ
- ๐พ Save & Apply (Override) - Replaces existing theme
- โ Save as New - Adds to array, generates new ID if needed
- โก Set Active - Sets existing theme as active
- โ Cancel - Cancels editing
๐งช Test Steps
Test 1: Save Theme (Override Mode) โ
Open Theme Designer: Navigate to
/space/chrome-space-1/theme-designerClick "๐พ Save & Apply (Override)"
Expected Console Logs:
๐พ [SimpleThemeStorage] saveTheme() called! - Theme: my-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()... - Update payload: { themeSystem: { activeThemeId: "theme-xxx", ... } } โ Space document updated successfully! - Theme system: { activeThemeId: "theme-xxx", ... }Check MongoDB:
- โ
Theme in
themescollection - โ
Space document has
themeSystem.activeThemeId
- โ
Theme in
Refresh Page (F5):
- โ Theme persists
- โ Console shows: "โ Loaded active theme from space document: theme-xxx"
Test 2: Save as New (Add Mode) โจ
Edit current theme colors
Click "โ Save as New"
Expected Console Logs:
๐พ [SimpleThemeStorage] saveTheme() called! - Mode: add - Theme exists, creating new one with ID: theme-xxx-1763741332000 โ ADD MODE: Creating new theme with ID: theme-xxx-1763741332000 โ Theme saved locally: theme-xxx-1763741332000 ๐ Syncing theme to MongoDB themes collection... โ Theme synced to MongoDB: theme-xxx-1763741332000 โก Setting as active theme...Check MongoDB:
- โ
TWO themes in
themescollection (old + new) - โ
Space document has
themeSystem.activeThemeIdpointing to new theme
- โ
TWO themes in
Test 3: Override Existing Theme โ
Load existing theme
Edit colors
Click "๐พ Save & Apply (Override)"
Expected Behavior:
- โ Theme is updated (same ID)
- โ
MongoDB
themescollection: theme updated (not duplicated) - โ
Space document:
themeSystem.activeThemeIdunchanged
Test 4: Persistence After Refresh โ
Save a theme
Refresh page (F5)
Expected Console Logs:
๐ [SimpleThemeStorage] Space changed to: 69067c087ebb621cd9ff8c3f - loading theme from space document โ Loaded active theme from space document: theme-xxx ๐ฏ ThemeStateManager: Active theme loaded: my-themeExpected Behavior:
- โ Theme is applied automatically
- โ NO "No active theme found in space document"
๐ Debugging
Issue: No Logs Appearing
Check:
- Open DevTools Console
- Make sure "Verbose" or "Info" level is enabled
- Look for logs starting with
๐ฏ,๐พ,โ
Issue: Space Document Not Updating
Check Backend Logs:
# In backend-api terminal
# Look for:
[SpacesController] ๐ฅ Update request received
[SpacesService] ๐จ Updating themeSystem: {...}
[SpacesService] โ
Updated space.themeSystem to: {...}
Check Network Tab:
- Look for
PUT /api/spaces/69067c087ebb621cd9ff8c3f - Request body should include
themeSystem - Response should include
themeSystemproperty
Issue: Theme Not in MongoDB
Check HTTP Sync Adapter:
// In console
console.log('[HTTP Sync] Initialized adapter for collection: themes');
// Should see:
[HTTP Sync] Auto-sync enabled for themes (interval: 3000ms)
๐ MongoDB Verification
Query Spaces Collection:
db.spaces.findOne({ _id: ObjectId("69067c087ebb621cd9ff8c3f") })
// Expected output:
{
"_id": ObjectId("69067c087ebb621cd9ff8c3f"),
"name": "Chrome Space 1",
"themeSystem": { // โ
SHOULD BE HERE!
"activeThemeId": "theme-testtheme1-1763734768627",
"updatedAt": "2025-11-21T11:00:32.867Z"
}
}
Query Themes Collection:
db.themes.find({ spaceId: "69067c087ebb621cd9ff8c3f" })
// Expected: Array of themes
[
{
"_id": "theme-xxx",
"metadata": { "name": "my-theme" },
"spaceId": "69067c087ebb621cd9ff8c3f",
"_syncedAt": "2025-11-21T11:00:33.123Z"
},
// ... more themes
]
โ Success Criteria
- [ ] Console logs show complete flow (saveTheme โ setActiveThemeId โ updateSpace)
- [ ] MongoDB
themescollection has theme document - [ ] MongoDB space document has
themeSystem.activeThemeId - [ ] Theme persists after refresh
- [ ] "Save as New" creates new theme (doesn't replace)
- [ ] "Save & Apply" overrides existing theme
- [ ] Backend logs show successful space update
๐จ If Still Not Working
1. Restart Backend API
# Terminal
nx serve backend-api
Why? MongoDB schema changed (added themeSystem)
2. Clear Browser Cache
# Chrome DevTools Console
localStorage.clear();
window.location.reload();
3. Check Backend API Logs
Look for errors in the backend terminal:
- โ
[SpacesService] โ Updated space.themeSystem - โ
[SpacesService] โ Failed to save
4. Verify HTTP Sync Adapter
// In console
console.log('[HTTP Sync] Initialized adapter for collection: themes');
If NOT present, check app.config.ts:
provideHttpMongoDBSync({
collections: [
{ name: 'themes', syncInterval: 3000, batchSize: 5 }
]
})
๐ Notes
- Themes are saved to both IndexedDB (local) and MongoDB (remote)
- Space document's
themeSystemis the source of truth for active theme - Flash persistence provides instant loading on refresh
- MongoDB sync happens in background (3-second interval for themes)
Status: ๐งช REQUIRES TESTING
Next: Save a theme and check the console logs!
Expected: Full trace from save โ sync โ space update โ success โจ