Skip to content

Commit 4d46499

Browse files
committed
Self review cleanup
1 parent 1462ce7 commit 4d46499

File tree

9 files changed

+41
-232
lines changed

9 files changed

+41
-232
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
66

77
## Added
88
- Modernized `dcc.Tabs`
9+
- Modernized `dcc.DatePickerSingle` and `dcc.DatePickerRange`
910

1011
## Changed
1112
- `dcc.Tab` now accepts a `width` prop which can be a pixel or percentage width for an individual tab.
@@ -50,7 +51,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
5051
- [#3347](https://github.com/plotly/dash/pull/3347) Added 'api_endpoint' to `callback` to expose api endpoints at the provided path for use to be executed directly without dash.
5152
- [#3445](https://github.com/plotly/dash/pull/3445) Added API to reverse direction of slider component.
5253
- [#3460](https://github.com/plotly/dash/pull/3460) Add `/health` endpoint for server monitoring and health checks.
53-
- [#3465](https://github.com/plotly/dash/pull/3465) Plotly cloud integrations, add devtool API, placeholder plotly cloud CLI & publish button, `dash[cloud]` extra dependencies.
54+
- [#3465](https://github.com/plotly/dash/pull/3465) Plotly cloud integrations, add devtool API, placeholder plotly cloud CLI & publish button, `dash[cloud]` extra dependencies.
5455

5556
## Fixed
5657
- [#3395](https://github.com/plotly/dash/pull/3395) Fix Components added through set_props() cannot trigger related callback functions. Fix [#3316](https://github.com/plotly/dash/issues/3316)

components/dash-core-components/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Clipboard from './components/Clipboard.react';
44
import ConfirmDialog from './components/ConfirmDialog.react';
55
import ConfirmDialogProvider from './components/ConfirmDialogProvider.react';
66
import DatePickerRange from './components/DatePickerRange';
7-
// import DatePickerRange from './components/DatePickerRange.react';
87
import DatePickerSingle from './components/DatePickerSingle';
98
import Download from './components/Download.react';
109
import Dropdown from './components/Dropdown';

components/dash-core-components/tests/unit/calendar/Calendar.test.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ describe('Calendar', () => {
213213
expectedFocusedDay: '23',
214214
},
215215
{
216-
description: 'first day when selected date is not visible',
216+
description: 'selected date even when not initially visible',
217217
visibleMonth: new Date(2020, 0, 1),
218218
selectedDate: new Date(2025, 9, 17),
219-
expectedFocusedDay: '1',
219+
expectedFocusedDay: '17', // Calendar switches to October 2025
220220
},
221221
{
222222
description: 'first day when no date is selected',
@@ -227,14 +227,22 @@ describe('Calendar', () => {
227227
])(
228228
'focuses $description',
229229
({visibleMonth, selectedDate, expectedFocusedDay}) => {
230+
const ref = React.createRef<any>();
230231
render(
231232
<Calendar
233+
ref={ref}
232234
onSelectionChange={mockOnSelectionChange}
233235
initialVisibleDate={visibleMonth}
234236
selectionStart={selectedDate}
235237
/>
236238
);
237239

240+
// Imperatively focus the appropriate date
241+
const dateToFocus = selectedDate || visibleMonth;
242+
act(() => {
243+
ref.current?.focusDate(dateToFocus);
244+
});
245+
238246
const focusedElement = document.activeElement;
239247
expect(focusedElement?.tagName).toBe('TD');
240248
expect(focusedElement?.textContent).toBe(expectedFocusedDay);

components/dash-core-components/tests/unit/calendar/CalendarDay.test.tsx

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ describe('CalendarDay', () => {
1313
</tbody>
1414
</table>
1515
);
16-
const td = container.querySelector('td');
17-
if (!td) {
18-
throw new Error('td element not rendered');
19-
}
20-
return td;
16+
return container.querySelector('td')!;
2117
};
2218

2319
it('renders with correct label and inside/outside classes', () => {
@@ -26,32 +22,22 @@ describe('CalendarDay', () => {
2622
isOutside: false,
2723
showOutsideDays: true,
2824
});
29-
expect(insideDay.textContent).toBe('15');
30-
expect(
31-
insideDay.classList.contains('dash-datepicker-calendar-date-inside')
32-
).toBe(true);
33-
expect(
34-
insideDay.classList.contains(
35-
'dash-datepicker-calendar-date-outside'
36-
)
37-
).toBe(false);
25+
expect(insideDay).toHaveTextContent('15');
26+
expect(insideDay).toHaveClass('dash-datepicker-calendar-date-inside');
27+
expect(insideDay).not.toHaveClass(
28+
'dash-datepicker-calendar-date-outside'
29+
);
3830

3931
const outsideDay = renderDay({
4032
date: new Date(2024, 11, 31),
4133
isOutside: true,
4234
showOutsideDays: true,
4335
});
44-
expect(outsideDay.textContent).toBe('31');
45-
expect(
46-
outsideDay.classList.contains(
47-
'dash-datepicker-calendar-date-outside'
48-
)
49-
).toBe(true);
50-
expect(
51-
outsideDay.classList.contains(
52-
'dash-datepicker-calendar-date-inside'
53-
)
54-
).toBe(false);
36+
expect(outsideDay).toHaveTextContent('31');
37+
expect(outsideDay).toHaveClass('dash-datepicker-calendar-date-outside');
38+
expect(outsideDay).not.toHaveClass(
39+
'dash-datepicker-calendar-date-inside'
40+
);
5541
});
5642

5743
it('marks disabled day with correct attributes', () => {
@@ -62,11 +48,9 @@ describe('CalendarDay', () => {
6248
isDisabled: true,
6349
});
6450

65-
expect(
66-
td.classList.contains('dash-datepicker-calendar-date-disabled')
67-
).toBe(true);
68-
expect(td.getAttribute('aria-disabled')).toBe('true');
69-
expect(td.getAttribute('tabIndex')).toBeNull();
51+
expect(td).toHaveClass('dash-datepicker-calendar-date-disabled');
52+
expect(td).toHaveAttribute('aria-disabled', 'true');
53+
expect(td).not.toHaveAttribute('tabIndex');
7054
});
7155

7256
it('hides label for outside days when showOutsideDays is false', () => {
@@ -76,10 +60,8 @@ describe('CalendarDay', () => {
7660
showOutsideDays: false,
7761
});
7862

79-
expect(td.textContent).toBe('');
80-
expect(
81-
td.classList.contains('dash-datepicker-calendar-date-outside')
82-
).toBe(true);
63+
expect(td).toHaveTextContent('');
64+
expect(td).toHaveClass('dash-datepicker-calendar-date-outside');
8365
});
8466

8567
it('focuses element when isFocused is true', () => {

components/dash-core-components/tests/unit/calendar/CalendarDayPadding.test.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,11 @@ describe('CalendarDayPadding', () => {
1414
</table>
1515
);
1616
const td = container.querySelector('td');
17-
if (!td) {
18-
throw new Error('td element not rendered');
19-
}
2017

21-
expect(td.classList.contains('dash-datepicker-calendar-padding')).toBe(
22-
true
23-
);
24-
expect(
25-
td.classList.contains('dash-datepicker-calendar-date-inside')
26-
).toBe(false);
27-
expect(
28-
td.classList.contains('dash-datepicker-calendar-date-outside')
29-
).toBe(false);
30-
expect(td.textContent).toBe('');
18+
expect(td).toBeInTheDocument();
19+
expect(td).toHaveClass('dash-datepicker-calendar-padding');
20+
expect(td).not.toHaveClass('dash-datepicker-calendar-date-inside');
21+
expect(td).not.toHaveClass('dash-datepicker-calendar-date-outside');
22+
expect(td).toHaveTextContent('');
3123
});
3224
});

components/dash-core-components/tests/unit/calendar/CalendarMonth.test.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,9 @@ describe('CalendarMonth', () => {
102102
td => td.textContent?.trim() || ''
103103
);
104104

105-
// Behavior 1: When showOutsideDays=true, all cells should be labeled (no empty labels)
106-
// Find cells that are in the actual calendar rows (not ghost rows)
107105
const labeledCells = cellTexts.filter(text => text !== '');
108106

109-
// Behavior 2: Days before January 1 should be labeled (December days)
110-
// First 2 cells should be December days (30, 31)
111-
// January 1, 2025 is Wednesday, which is 2 days after Monday
107+
// First 2 cells should be December days (30, 31), then January 1
112108
expect(cellTexts[0]).toBe('30');
113109
expect(cellTexts[1]).toBe('31');
114110

components/dash-core-components/tests/unit/calendar/DatePickerSingle.test.tsx

Lines changed: 0 additions & 157 deletions
This file was deleted.

components/dash-core-components/tests/unit/calendar/createMonthGrid.test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,38 @@ const expectConsecutiveDatesUntilPadding = (dates: (Date | null)[]) => {
2828
describe('createMonthGrid', () => {
2929
describe('with showOutsideDays=true (default)', () => {
3030
it('creates grid with exactly 6 rows and 7 columns', () => {
31-
const grid = createMonthGrid(2025, 0, 0, true); // January 2025, Sunday first
31+
const grid = createMonthGrid(2025, 0, 0, true);
3232

33-
// Should always have exactly 6 rows (weeks) for consistent calendar height
3433
expect(grid.length).toBe(6);
35-
3634
grid.forEach(week => {
3735
expect(week.length).toBe(7);
3836
});
3937
});
4038

4139
it('has consecutive dates until padding, then all null', () => {
42-
const grid = createMonthGrid(2025, 0, 0, true); // January 2025
40+
const grid = createMonthGrid(2025, 0, 0, true);
4341
expectConsecutiveDatesUntilPadding(grid.flat());
4442
});
4543

4644
it('adjusts for different first day of week', () => {
47-
const sundayFirst = createMonthGrid(2025, 0, 0, true); // Sunday = 0
48-
const mondayFirst = createMonthGrid(2025, 0, 1, true); // Monday = 1
45+
const sundayFirst = createMonthGrid(2025, 0, 0, true);
46+
const mondayFirst = createMonthGrid(2025, 0, 1, true);
4947

50-
// Grids should have different starting dates
5148
expect(sundayFirst[0][0]).not.toBeNull();
5249
expect(mondayFirst[0][0]).not.toBeNull();
5350
expect(sundayFirst[0][0]).not.toEqual(mondayFirst[0][0]);
5451

5552
// January 2025 starts on Wednesday
56-
// Sunday-first shows: Sun, Mon, Tue (3 days from prev month)
57-
// Monday-first shows: Mon, Tue (2 days from prev month)
58-
// So Monday-first should start later
53+
// Sunday-first shows 3 days from prev month, Monday-first shows 2
5954
expect(mondayFirst[0][0]!.getTime()).toBeGreaterThan(
6055
sundayFirst[0][0]!.getTime()
6156
);
6257
});
6358

6459
it('handles months starting on different weekdays', () => {
65-
// January 2025 starts on Wednesday
66-
const jan2025 = createMonthGrid(2025, 0, 0, true); // Sunday first
60+
const jan2025 = createMonthGrid(2025, 0, 0, true); // Jan starts on Wednesday
61+
const feb2025 = createMonthGrid(2025, 1, 0, true); // Feb starts on Saturday
6762

68-
// February 2025 starts on Saturday
69-
const feb2025 = createMonthGrid(2025, 1, 0, true); // Sunday first
70-
71-
// Both should always have exactly 6 rows
7263
expect(jan2025.length).toBe(6);
7364
expect(feb2025.length).toBe(6);
7465
});

0 commit comments

Comments
 (0)