Skip to content

Commit a2b1cfa

Browse files
authored
Add "Today" date range preset (default) (#6)
1 parent 03988e8 commit a2b1cfa

3 files changed

Lines changed: 49 additions & 12 deletions

File tree

package-lock.json

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sp-dashboard/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ <h1 class="title">Dashboard</h1>
264264
<div class="control-box">
265265
<label for="date-preset">Period</label>
266266
<select id="date-preset">
267-
<option value="week" selected>Past Week</option>
267+
<option value="today" selected>Today</option>
268+
<option value="week">Past Week</option>
268269
<option value="month">Past Month</option>
269270
<option value="year">Past Year</option>
270271
<option value="custom">Custom Range...</option>
@@ -511,7 +512,7 @@ <h3 class="card-title">Project Breakdown</h3>
511512
const todayObjInit = new Date();
512513
const lastWeekObjInit = new Date();
513514
lastWeekObjInit.setDate(todayObjInit.getDate() - 6);
514-
document.getElementById('date-from').value = lastWeekObjInit.toISOString().split('T')[0];
515+
document.getElementById('date-from').value = todayObjInit.toISOString().split('T')[0];
515516
document.getElementById('date-to').value = todayObjInit.toISOString().split('T')[0];
516517

517518
const presetSelect = document.getElementById('date-preset');
@@ -919,9 +920,10 @@ <h3 class="card-title">Project Breakdown</h3>
919920
metrics.projectData[pName] += taskTimeInRange;
920921
}
921922

922-
// count tasks that had activity OR were completed (in range)
923+
// count tasks that had activity OR were completed OR are due (in range)
923924
const taskCompletedInRange = task.isDone && task.doneOn && dateRange.includes(new Date(task.doneOn).toISOString().split('T')[0]);
924-
if (taskTimeInRange > 0 || taskCompletedInRange) {
925+
const taskDueInRange = task.dueDay && dateRange.includes(task.dueDay);
926+
if (taskTimeInRange > 0 || taskCompletedInRange || taskDueInRange) {
925927
metrics.totalTasks++;
926928
if (taskCompletedInRange) {
927929
metrics.totalCompleted++;

tests/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ describe('Date Range Reporter UI', () => {
214214
expect(document.getElementById('stat-tasks-total').innerText).toContain('1 total');
215215
});
216216

217+
it('should count tasks due today in totalTasks denominator even with no time logged', () => {
218+
const todayStr = new Date().toISOString().split('T')[0];
219+
const taskDueToday = {
220+
id: 't-due-no-time',
221+
parentId: null,
222+
title: 'Due Today No Time',
223+
isDone: false,
224+
dueDay: todayStr,
225+
timeSpentOnDay: {}
226+
};
227+
window.processData([taskDueToday], []);
228+
// Task is due today so it should appear in the denominator
229+
expect(document.getElementById('stat-tasks-total').innerText).toContain('1 total');
230+
// Not completed, so numerator stays 0
231+
expect(document.getElementById('stat-tasks').innerText).toBe('0');
232+
});
233+
217234
it('should deduplicate tasks that appear in both active and archived lists', () => {
218235
const now = Date.now();
219236
const doneTask = {
@@ -284,6 +301,18 @@ describe('Date Range Reporter UI', () => {
284301
expect(customContainer.classList.contains('hidden')).toBe(true);
285302
});
286303

304+
it('today preset should produce a single-day date range', () => {
305+
const presetSelect = document.getElementById('date-preset');
306+
presetSelect.value = 'today';
307+
presetSelect.dispatchEvent(new Event('change'));
308+
309+
window.processData([], []);
310+
311+
// The bar chart should contain exactly one bar column (one day)
312+
const barContainer = document.getElementById('bar-chart-container');
313+
expect(barContainer.querySelectorAll('.bar-col').length).toBe(1);
314+
});
315+
287316
it('bar and pie charts should render for overdue and late types and details show badges', () => {
288317
// prepare metrics with one overdue task and one late task
289318
const now = Date.now();

0 commit comments

Comments
 (0)