Skip to content

Commit 857dc7c

Browse files
committed
feat: enhance logging in PomodoroTimer and add testing commands for session management
1 parent 7812924 commit 857dc7c

File tree

3 files changed

+166
-6
lines changed

3 files changed

+166
-6
lines changed

TEST_MANUAL.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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.

src/core/pomodoro-timer.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,20 +1127,38 @@ export class PomodoroTimer {
11271127

11281128
// Add state indicators
11291129
if (shouldUpdateStatus) {
1130-
console.log('📊 updateDisplay - isOvertime:', isOvertime, 'isAutoPaused:', this.isAutoPaused, 'isPaused:', this.isPaused, 'isRunning:', this.isRunning, 'justResumedFromAutoPause:', this._justResumedFromAutoPause, 'justResumedFromPause:', this._justResumedFromPause);
1130+
// Only log state changes, not every update to reduce spam
1131+
const currentState = `${isOvertime}-${this.isAutoPaused}-${this.isPaused}-${this.isRunning}`;
1132+
if (!this._lastLoggedState || this._lastLoggedState !== currentState || this._justResumedFromAutoPause || this._justResumedFromPause) {
1133+
console.log('📊 updateDisplay - isOvertime:', isOvertime, 'isAutoPaused:', this.isAutoPaused, 'isPaused:', this.isPaused, 'isRunning:', this.isRunning, 'justResumedFromAutoPause:', this._justResumedFromAutoPause, 'justResumedFromPause:', this._justResumedFromPause);
1134+
this._lastLoggedState = currentState;
1135+
}
11311136

11321137
if (isOvertime) {
11331138
statusText += ' (Overtime)';
1134-
console.log('⏰ Showing Overtime status');
1139+
if (!this._lastLoggedState || !this._lastLoggedState.startsWith('true-')) {
1140+
console.log('⏰ Showing Overtime status');
1141+
}
11351142
}
11361143
else if (this.isAutoPaused) {
11371144
statusText += ' (Auto-paused)';
1138-
console.log('💤 Showing Auto-paused status');
1145+
if (!this._lastAutoPausedLogged) {
1146+
console.log('💤 Showing Auto-paused status');
1147+
this._lastAutoPausedLogged = true;
1148+
}
11391149
} else if (this.isPaused && !this.isRunning) {
11401150
statusText += ' (Paused)';
1141-
console.log('⏸️ Showing Paused status');
1151+
if (!this._lastPausedLogged) {
1152+
console.log('⏸️ Showing Paused status');
1153+
this._lastPausedLogged = true;
1154+
}
11421155
} else {
1143-
console.log('▶️ No status suffix (timer running normally)');
1156+
// Reset paused flags when not in those states
1157+
this._lastAutoPausedLogged = false;
1158+
this._lastPausedLogged = false;
1159+
if (this._lastLoggedState && (this._lastLoggedState.includes('true') || this._justResumedFromAutoPause || this._justResumedFromPause)) {
1160+
console.log('▶️ No status suffix (timer running normally)');
1161+
}
11441162
}
11451163

11461164
// Update status text only when necessary

src/managers/session-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ export class SessionManager {
277277
}
278278

279279
async addSession(sessionData) {
280-
const dateString = this.selectedDate.toDateString();
280+
// Use current date if selectedDate is null (e.g., when called from timer)
281+
const targetDate = this.selectedDate || new Date();
282+
const dateString = targetDate.toDateString();
281283

282284
// Add to local storage
283285
if (!this.sessions[dateString]) {

0 commit comments

Comments
 (0)