Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frontend/src/components/HomeComponents/Tasks/ReportChart.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add new overdue bar (red color)

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export const ReportChart: React.FC<ReportChartProps> = ({
name="Ongoing"
label={{ position: 'top', fill: 'white', fontSize: 12 }}
/>
<Bar
dataKey="overdue"
fill="#F33434"
name="Overdue"
label={{ position: 'top', fill: 'white', fontSize: 12 }}
/>
</BarChart>
</ResponsiveContainer>
</div>
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/HomeComponents/Tasks/ReportsView.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

counting overdue task correctly

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { ReportsViewProps } from '../../utils/types';
import { getStartOfDay } from '../../utils/utils';
import { ReportChart } from './ReportChart';
import { parseTaskwarriorDate } from '../Tasks/tasks-utils';
import { parseTaskwarriorDate, isOverdue } from '../Tasks/tasks-utils';

export const ReportsView: React.FC<ReportsViewProps> = ({ tasks }) => {
const now = new Date();
Expand All @@ -14,6 +14,7 @@ export const ReportsView: React.FC<ReportsViewProps> = ({ tasks }) => {
const startOfMonth = getStartOfDay(
new Date(now.getFullYear(), now.getMonth(), 1)
);

const countStatuses = (filterDate: Date) => {
return tasks
.filter((task) => {
Expand All @@ -31,11 +32,15 @@ export const ReportsView: React.FC<ReportsViewProps> = ({ tasks }) => {
if (task.status === 'completed') {
acc.completed += 1;
} else if (task.status === 'pending') {
acc.ongoing += 1;
if (isOverdue(task.due)) {
acc.overdue += 1;
} else {
acc.ongoing += 1;
}
}
return acc;
},
{ completed: 0, ongoing: 0 }
{ completed: 0, ongoing: 0, overdue: 0 }
);
};

Expand Down
15 changes: 1 addition & 14 deletions frontend/src/components/HomeComponents/Tasks/Tasks.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import isOverdue function from shared utility and removes duplicate code

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
sortTasksById,
getTimeSinceLastSync,
hashKey,
parseTaskwarriorDate,
isOverdue,
} from './tasks-utils';
import Pagination from './Pagination';
import { url } from '@/components/utils/URLs';
Expand Down Expand Up @@ -118,19 +118,6 @@ export const Tasks = (

// Handler for dialog open/close

const isOverdue = (due?: string) => {
if (!due) return false;

const dueDate = parseTaskwarriorDate(due);
if (!dueDate) return false;
dueDate.setHours(0, 0, 0, 0);

const today = new Date();
today.setHours(0, 0, 0, 0);

return dueDate < today;
};

const debouncedSearch = debounce((value: string) => {
setDebouncedTerm(value);
setCurrentPage(1);
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the mockData and add test for overdue bar

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jest.mock('../report-download-utils', () => ({
}));

describe('ReportChart', () => {
const mockData = [{ name: 'Today', completed: 5, ongoing: 3 }];
const mockData = [{ name: 'Today', completed: 5, ongoing: 3, overdue: 2 }];

const defaultProps = {
data: mockData,
Expand Down Expand Up @@ -87,6 +87,15 @@ describe('ReportChart', () => {
expect(ongoingBar).toHaveAttribute('data-name', 'Ongoing');
});

it('displays overdue bar with correct color', () => {
render(<ReportChart {...defaultProps} />);

const overdueBar = screen.getByTestId('bar-overdue');

expect(overdueBar).toHaveAttribute('data-fill', '#F33434');
expect(overdueBar).toHaveAttribute('data-name', 'Overdue');
});

it('renders chart axes', () => {
render(<ReportChart {...defaultProps} />);
expect(screen.getByTestId('x-axis')).toBeInTheDocument();
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update test and add new test

Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,50 @@ describe('ReportsView', () => {
expect(data[0].completed).toBe(0);
});

it('counts pending tasks with past due date as overdue', () => {
const todayDate = new Date();
const today = toTWFormat(todayDate);

const pastDate = new Date();
pastDate.setDate(pastDate.getDate() - 10);
const pastDue = toTWFormat(pastDate);

const tasks = [
createMockTask({ status: 'pending', due: pastDue }),
createMockTask({ status: 'pending', due: pastDue }),
createMockTask({ status: 'pending', due: today }),
createMockTask({ status: 'completed', end: today }),
];

render(<ReportsView tasks={tasks} />);

const monthlyData = screen.getByTestId('monthly-report-chart-data');
const data = JSON.parse(monthlyData.textContent || '[]');

expect(data[0].overdue).toBe(2);
expect(data[0].ongoing).toBe(1);
expect(data[0].completed).toBe(1);
});

it('treats task with no due date as ongoing', () => {
const today = toTWFormat(new Date());

const tasks = [
createMockTask({
status: 'pending',
entry: today,
}),
];

render(<ReportsView tasks={tasks} />);
const dailyData = screen.getByTestId('daily-report-chart-data');
const data = JSON.parse(dailyData.textContent || '[]');

expect(data[0].ongoing).toBe(1);
expect(data[0].overdue).toBe(0);
expect(data[0].completed).toBe(0);
});

it('filters tasks by date range correctly', () => {
const referenceDate = new Date('2024-01-10T12:00:00Z');

Expand Down Expand Up @@ -135,7 +179,7 @@ describe('ReportsView', () => {
jest.useRealTimers();
});

it('uses modified date when available', () => {
it('uses end date when available', () => {
const today = toTWFormat(new Date());
const tasks = [
createMockTask({
Expand Down Expand Up @@ -191,21 +235,29 @@ describe('ReportsView', () => {
});

it('handles mixed statuses correctly', () => {
const today = toTWFormat(new Date());
const todayDate = new Date();
const today = toTWFormat(todayDate);

const pastDate = new Date();
pastDate.setDate(pastDate.getDate() - 10);
const pastDue = toTWFormat(pastDate);

const tasks = [
createMockTask({ status: 'completed', end: today }),
createMockTask({ status: 'pending', due: today }),
createMockTask({ status: 'pending', due: pastDue }),
createMockTask({ status: 'deleted', end: today }),
createMockTask({ status: 'recurring', due: today }),
];

render(<ReportsView tasks={tasks} />);

const dailyData = screen.getByTestId('daily-report-chart-data');
const data = JSON.parse(dailyData.textContent || '[]');
const monthlyData = screen.getByTestId('monthly-report-chart-data');
const data = JSON.parse(monthlyData.textContent || '[]');

expect(data[0].completed).toBe(1);
expect(data[0].ongoing).toBe(1);
expect(data[0].overdue).toBe(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ exports[`ReportChart Component using Snapshot renders correctly with one data en
data-name="Ongoing"
data-testid="bar-ongoing"
/>
<div
data-fill="#F33434"
data-name="Overdue"
data-testid="bar-overdue"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -262,6 +267,11 @@ exports[`ReportChart Component using Snapshot renders correctly with several dat
data-name="Ongoing"
data-testid="bar-ongoing"
/>
<div
data-fill="#F33434"
data-name="Overdue"
data-testid="bar-overdue"
/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ exports[`ReportsView Component using Snapshot renders correctly with only one ta
<span>
ongoing: 1
</span>
<span>
overdue: 0
</span>
</div>
<div
data-stroke="#555"
Expand Down Expand Up @@ -153,6 +156,12 @@ exports[`ReportsView Component using Snapshot renders correctly with only one ta
data-name="Ongoing"
data-testid="Bar"
/>
<div
data-data-key="overdue"
data-fill="#F33434"
data-name="Overdue"
data-testid="Bar"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -267,6 +276,9 @@ exports[`ReportsView Component using Snapshot renders correctly with only one ta
<span>
ongoing: 1
</span>
<span>
overdue: 0
</span>
</div>
<div
data-stroke="#555"
Expand Down Expand Up @@ -304,6 +316,12 @@ exports[`ReportsView Component using Snapshot renders correctly with only one ta
data-name="Ongoing"
data-testid="Bar"
/>
<div
data-data-key="overdue"
data-fill="#F33434"
data-name="Overdue"
data-testid="Bar"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -418,6 +436,9 @@ exports[`ReportsView Component using Snapshot renders correctly with only one ta
<span>
ongoing: 1
</span>
<span>
overdue: 0
</span>
</div>
<div
data-stroke="#555"
Expand Down Expand Up @@ -455,6 +476,12 @@ exports[`ReportsView Component using Snapshot renders correctly with only one ta
data-name="Ongoing"
data-testid="Bar"
/>
<div
data-data-key="overdue"
data-fill="#F33434"
data-name="Overdue"
data-testid="Bar"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -578,6 +605,9 @@ exports[`ReportsView Component using Snapshot renders correctly with only severa
<span>
ongoing: 1
</span>
<span>
overdue: 0
</span>
</div>
<div
data-stroke="#555"
Expand Down Expand Up @@ -615,6 +645,12 @@ exports[`ReportsView Component using Snapshot renders correctly with only severa
data-name="Ongoing"
data-testid="Bar"
/>
<div
data-data-key="overdue"
data-fill="#F33434"
data-name="Overdue"
data-testid="Bar"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -727,7 +763,10 @@ exports[`ReportsView Component using Snapshot renders correctly with only severa
completed: 2
</span>
<span>
ongoing: 2
ongoing: 1
</span>
<span>
overdue: 1
</span>
</div>
<div
Expand Down Expand Up @@ -766,6 +805,12 @@ exports[`ReportsView Component using Snapshot renders correctly with only severa
data-name="Ongoing"
data-testid="Bar"
/>
<div
data-data-key="overdue"
data-fill="#F33434"
data-name="Overdue"
data-testid="Bar"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -878,7 +923,10 @@ exports[`ReportsView Component using Snapshot renders correctly with only severa
completed: 4
</span>
<span>
ongoing: 4
ongoing: 1
</span>
<span>
overdue: 3
</span>
</div>
<div
Expand Down Expand Up @@ -917,6 +965,12 @@ exports[`ReportsView Component using Snapshot renders correctly with only severa
data-name="Ongoing"
data-testid="Bar"
/>
<div
data-data-key="overdue"
data-fill="#F33434"
data-name="Overdue"
data-testid="Bar"
/>
</div>
</div>
</div>
Expand Down
Loading
Loading