-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add 'Starting from weekday' date range #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,6 +364,33 @@ describe('Date Range Reporter UI', () => { | |
| expect(pieLegend.querySelector('.legend-item')).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('from-weekday preset with weekday picker should produce correct date range', () => { | ||
| const presetSelect = document.getElementById('date-preset'); | ||
| const weekdaySelect = document.getElementById('weekday-select'); | ||
| const barContainer = document.getElementById('bar-chart-container'); | ||
| const weekdayPickerContainer = document.getElementById('weekday-picker-container'); | ||
|
|
||
| presetSelect.value = 'from-weekday'; | ||
| presetSelect.dispatchEvent(new Event('change')); | ||
| expect(weekdayPickerContainer.classList.contains('hidden')).toBe(false); | ||
|
|
||
| // Test each weekday | ||
| const today = new Date(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test could be flaky because it relies on the current system time ( You can use const mockToday = new Date('2024-01-26T12:00:00Z'); // A Friday
vi.useFakeTimers();
vi.setSystemTime(mockToday);
// ... your test logic ...
vi.useRealTimers(); // cleanup |
||
| for (const targetDay of [0, 1, 2, 3, 4, 5, 6]) { | ||
| weekdaySelect.value = String(targetDay); | ||
| weekdaySelect.dispatchEvent(new Event('change')); | ||
| window.processData([], []); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| const daysBack = (today.getDay() - targetDay + 7) % 7; | ||
| expect(barContainer.querySelectorAll('.bar-col').length).toBe(daysBack + 1); | ||
| } | ||
|
|
||
| // Switching away hides the picker | ||
| presetSelect.value = 'today'; | ||
| presetSelect.dispatchEvent(new Event('change')); | ||
| expect(weekdayPickerContainer.classList.contains('hidden')).toBe(true); | ||
| }); | ||
|
|
||
| it('detail list columns are sortable when headers are clicked', () => { | ||
| // create two tasks with different dates | ||
| const taskA = { id:'a', parentId:null, title:'A', isDone:false, dueDay:'2026-01-01', timeSpentOnDay:{'2026-01-01':3600000} }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better performance and maintainability, it's a good practice to cache DOM element references instead of querying for them repeatedly. The
weekday-selectelement is accessed here and also when attaching an event listener (line 541). You can get the element once and store it in a variable at the top of the script block, similar to howpresetSelectandcustomContainerare handled.For example, you could add this line near line 533:
Then you would change line 541 to:
And this line would become: