Skip to content

Commit cac3271

Browse files
authored
[code-infra] Further remove clock=fake from pickers (#17253)
Signed-off-by: Jose C Quintas Jr <juniorquintas@gmail.com>
1 parent 341000c commit cac3271

21 files changed

Lines changed: 1859 additions & 1587 deletions

File tree

packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.test.tsx

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as React from 'react';
22
import { spy } from 'sinon';
33
import { expect } from 'chai';
4-
import { screen, fireEvent, within, fireTouchChangedEvent } from '@mui/internal-test-utils';
4+
import {
5+
screen,
6+
fireEvent,
7+
within,
8+
fireTouchChangedEvent,
9+
waitFor,
10+
} from '@mui/internal-test-utils';
511
import {
612
adapterToUse,
713
buildPickerDragInteractions,
@@ -29,10 +35,7 @@ const dynamicShouldDisableDate = (date, position: RangePosition) => {
2935
};
3036

3137
describe('<DateRangeCalendar />', () => {
32-
const { render, clock } = createPickerRenderer({
33-
clock: 'fake',
34-
clockConfig: new Date(2018, 0, 10),
35-
});
38+
const { render } = createPickerRenderer();
3639

3740
describeConformance(<DateRangeCalendar />, () => ({
3841
classes,
@@ -44,26 +47,28 @@ describe('<DateRangeCalendar />', () => {
4447
}));
4548

4649
describe('Selection', () => {
47-
it('should select the range from the next month', () => {
50+
it('should select the range from the next month', async () => {
4851
const onChange = spy();
4952

50-
render(
53+
const { user } = render(
5154
<DateRangeCalendar
5255
onChange={onChange}
5356
defaultValue={[adapterToUse.date('2019-01-01'), null]}
5457
/>,
5558
);
5659

57-
fireEvent.click(getPickerDay('1', 'January 2019'));
60+
await user.click(getPickerDay('1', 'January 2019'));
5861

59-
// FIXME use `getByRole(role, {hidden: false})` and skip JSDOM once this suite can run in JSDOM
6062
const [visibleButton] = screen.getAllByRole('button', {
61-
hidden: true,
6263
name: 'Next month',
6364
});
64-
fireEvent.click(visibleButton);
65-
clock.runToLast();
66-
fireEvent.click(getPickerDay('19', 'March 2019'));
65+
await user.click(visibleButton);
66+
67+
await waitFor(() => {
68+
getPickerDay('19', 'March 2019');
69+
});
70+
71+
await user.click(getPickerDay('19', 'March 2019'));
6772

6873
expect(onChange.callCount).to.equal(2);
6974

@@ -450,19 +455,20 @@ describe('<DateRangeCalendar />', () => {
450455
});
451456

452457
describe('prop: disableAutoMonthSwitching', () => {
453-
it('should go to the month of the end date when changing the start date', () => {
454-
render(
458+
it('should go to the month of the end date when changing the start date', async () => {
459+
const { user } = render(
455460
<DateRangeCalendar
456461
defaultValue={[adapterToUse.date('2018-01-01'), adapterToUse.date('2018-07-01')]}
457462
/>,
458463
);
459464

460-
fireEvent.click(getPickerDay('5', 'January 2018'));
461-
clock.runToLast();
462-
expect(getPickerDay('1', 'July 2018')).not.to.equal(null);
465+
await user.click(getPickerDay('5', 'January 2018'));
466+
await waitFor(() => {
467+
expect(getPickerDay('1', 'July 2018')).not.to.equal(null);
468+
});
463469
});
464470

465-
it('should not go to the month of the end date when changing the start date and props.disableAutoMonthSwitching = true', () => {
471+
it('should not go to the month of the end date when changing the start date and props.disableAutoMonthSwitching = true', async () => {
466472
render(
467473
<DateRangeCalendar
468474
defaultValue={[adapterToUse.date('2018-01-01'), adapterToUse.date('2018-07-01')]}
@@ -471,11 +477,12 @@ describe('<DateRangeCalendar />', () => {
471477
);
472478

473479
fireEvent.click(getPickerDay('5', 'January 2018'));
474-
clock.runToLast();
475-
expect(getPickerDay('1', 'January 2018')).not.to.equal(null);
480+
await waitFor(() => {
481+
expect(getPickerDay('1', 'January 2018')).not.to.equal(null);
482+
});
476483
});
477484

478-
it('should go to the month of the start date when changing both date from the outside', () => {
485+
it('should go to the month of the start date when changing both date from the outside', async () => {
479486
const { setProps } = render(
480487
<DateRangeCalendar
481488
value={[adapterToUse.date('2018-01-01'), adapterToUse.date('2018-07-01')]}
@@ -485,12 +492,13 @@ describe('<DateRangeCalendar />', () => {
485492
setProps({
486493
value: [adapterToUse.date('2018-04-01'), adapterToUse.date('2018-04-01')],
487494
});
488-
clock.runToLast();
489-
expect(getPickerDay('1', 'April 2018')).not.to.equal(null);
495+
await waitFor(() => {
496+
expect(getPickerDay('1', 'April 2018')).not.to.equal(null);
497+
});
490498
});
491499

492500
describe('prop: currentMonthCalendarPosition', () => {
493-
it('should switch to the selected month when changing value from the outside', () => {
501+
it('should switch to the selected month when changing value from the outside', async () => {
494502
const { setProps } = render(
495503
<DateRangeCalendar
496504
value={[adapterToUse.date('2018-01-10'), adapterToUse.date('2018-01-15')]}
@@ -501,8 +509,10 @@ describe('<DateRangeCalendar />', () => {
501509
setProps({
502510
value: [adapterToUse.date('2018-02-11'), adapterToUse.date('2018-02-22')],
503511
});
504-
clock.runToLast();
505-
expect(getPickerDay('1', 'February 2018')).not.to.equal(null);
512+
513+
await waitFor(() => {
514+
expect(getPickerDay('1', 'February 2018')).not.to.equal(null);
515+
});
506516
});
507517
});
508518
});
@@ -545,6 +555,7 @@ describe('<DateRangeCalendar />', () => {
545555

546556
render(
547557
<DateRangeCalendar
558+
referenceDate={adapterToUse.date('2018-01-01')}
548559
slots={{
549560
day: React.memo(RenderCount),
550561
}}
@@ -561,6 +572,7 @@ describe('<DateRangeCalendar />', () => {
561572

562573
render(
563574
<DateRangeCalendar
575+
referenceDate={adapterToUse.date('2018-01-01')}
564576
slots={{
565577
day: React.memo(RenderCount),
566578
}}

0 commit comments

Comments
 (0)