|
| 1 | +# Testing Commands for Timer Sessions |
| 2 | + |
| 3 | +This document contains JavaScript console commands to test the unified session management system by adding fake timer sessions and cleaning them up afterward. |
| 4 | + |
| 5 | +## Add Fake Timer Sessions |
| 6 | + |
| 7 | +Use this command in the browser console to generate realistic fake timer sessions for testing: |
| 8 | + |
| 9 | +```javascript |
| 10 | +// Command to add fake timer sessions for testing |
| 11 | +(async function addFakeTimerSessions() { |
| 12 | + if (!window.sessionManager) { |
| 13 | + console.error('SessionManager not available'); |
| 14 | + return; |
| 15 | + } |
| 16 | + |
| 17 | + // Generate sessions for the last 7 days |
| 18 | + const sessions = []; |
| 19 | + const now = new Date(); |
| 20 | + |
| 21 | + for (let dayOffset = 0; dayOffset < 7; dayOffset++) { |
| 22 | + const date = new Date(now); |
| 23 | + date.setDate(now.getDate() - dayOffset); |
| 24 | + |
| 25 | + // Generate 2-4 random sessions per day |
| 26 | + const sessionsPerDay = Math.floor(Math.random() * 3) + 2; |
| 27 | + |
| 28 | + for (let i = 0; i < sessionsPerDay; i++) { |
| 29 | + // Random time between 9:00 and 18:00 |
| 30 | + const startHour = Math.floor(Math.random() * 9) + 9; |
| 31 | + const startMinute = Math.floor(Math.random() * 60); |
| 32 | + |
| 33 | + // Random duration between 20-30 minutes (simulates timer sessions) |
| 34 | + const duration = Math.floor(Math.random() * 11) + 20; |
| 35 | + |
| 36 | + const endTotalMinutes = startHour * 60 + startMinute + duration; |
| 37 | + const endHour = Math.floor(endTotalMinutes / 60); |
| 38 | + const endMinute = endTotalMinutes % 60; |
| 39 | + |
| 40 | + const session = { |
| 41 | + id: `timer_fake_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, |
| 42 | + session_type: 'focus', |
| 43 | + duration: duration, |
| 44 | + start_time: `${startHour.toString().padStart(2, '0')}:${startMinute.toString().padStart(2, '0')}`, |
| 45 | + end_time: `${endHour.toString().padStart(2, '0')}:${endMinute.toString().padStart(2, '0')}`, |
| 46 | + notes: `Timer session ${i + 1}`, |
| 47 | + created_at: new Date(date.getTime() + startHour * 3600000 + startMinute * 60000).toISOString() |
| 48 | + }; |
| 49 | + |
| 50 | + sessions.push({ session, date }); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + // Add all sessions |
| 55 | + for (const { session, date } of sessions) { |
| 56 | + window.sessionManager.selectedDate = date; |
| 57 | + await window.sessionManager.addSession(session); |
| 58 | + } |
| 59 | + |
| 60 | + console.log(` Added ${sessions.length} fake timer sessions!`); |
| 61 | + |
| 62 | + // Update statistics |
| 63 | + if (window.navigationManager) { |
| 64 | + await window.navigationManager.updateCalendar(); |
| 65 | + await window.navigationManager.updateFocusSummary(); |
| 66 | + await window.navigationManager.updateWeeklySessionsChart(); |
| 67 | + await window.navigationManager.updateDailyChart(); |
| 68 | + console.log('=Ê Statistics updated!'); |
| 69 | + } |
| 70 | +})(); |
| 71 | +``` |
| 72 | + |
| 73 | +## Clean Up Fake Sessions |
| 74 | + |
| 75 | +Use this command to remove all fake sessions after testing: |
| 76 | + |
| 77 | +```javascript |
| 78 | +// Remove all fake sessions |
| 79 | +(async function removeFakeSessions() { |
| 80 | + if (!window.sessionManager) { |
| 81 | + console.error('SessionManager not available'); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + const allSessions = window.sessionManager.sessions; |
| 86 | + let removedCount = 0; |
| 87 | + |
| 88 | + for (const dateKey in allSessions) { |
| 89 | + const sessions = allSessions[dateKey]; |
| 90 | + const filtered = sessions.filter(s => !s.id.includes('timer_fake_')); |
| 91 | + const removed = sessions.length - filtered.length; |
| 92 | + removedCount += removed; |
| 93 | + allSessions[dateKey] = filtered; |
| 94 | + } |
| 95 | + |
| 96 | + await window.sessionManager.saveSessionsToStorage(); |
| 97 | + console.log(`=Ñ Removed ${removedCount} fake sessions`); |
| 98 | + |
| 99 | + // Update statistics |
| 100 | + if (window.navigationManager) { |
| 101 | + await window.navigationManager.updateCalendar(); |
| 102 | + await window.navigationManager.updateFocusSummary(); |
| 103 | + await window.navigationManager.updateWeeklySessionsChart(); |
| 104 | + await window.navigationManager.updateDailyChart(); |
| 105 | + console.log('=Ê Statistics refreshed!'); |
| 106 | + } |
| 107 | +})(); |
| 108 | +``` |
| 109 | + |
| 110 | +## How to Use |
| 111 | + |
| 112 | +1. Open the browser console (F12 ’ Console tab) |
| 113 | +2. Copy and paste the first command to add fake sessions |
| 114 | +3. Navigate to the Statistics page to verify the sessions appear |
| 115 | +4. Use the second command to clean up when done testing |
| 116 | + |
| 117 | +## What the Commands Do |
| 118 | + |
| 119 | +### Add Fake Sessions Command: |
| 120 | +- Creates realistic focus sessions with 20-30 minute durations |
| 121 | +- Distributes sessions during work hours (9:00 AM - 6:00 PM) |
| 122 | +- Adds 2-4 sessions per day for the last 7 days |
| 123 | +- Uses unique IDs with "timer_fake_" prefix for easy identification |
| 124 | +- Automatically updates all charts and statistics |
| 125 | + |
| 126 | +### Clean Up Command: |
| 127 | +- Removes all sessions containing "timer_fake_" in their ID |
| 128 | +- Preserves all real sessions (both manual and actual timer sessions) |
| 129 | +- Updates storage and refreshes all statistics |
| 130 | +- Provides count of removed sessions |
| 131 | + |
| 132 | +## Expected Results |
| 133 | + |
| 134 | +After running the add command, you should see: |
| 135 | +- Calendar dots appearing on the last 7 days |
| 136 | +- Weekly statistics showing focus time and session counts |
| 137 | +- Charts populated with session data |
| 138 | +- Session history showing the fake timer sessions |
| 139 | + |
| 140 | +This helps verify that the unified session management system correctly handles timer sessions alongside manual sessions. |
0 commit comments