- Toolbar', () => {
expect(getColumnHeadersTextContent()).to.deep.equal(['id', 'brand']);
- fireEvent.click(getByText('Columns'));
+ fireEvent.click(screen.getByText('Columns'));
fireEvent.click(screen.getByRole('tooltip').querySelector('[name="id"]')!);
expect(getColumnHeadersTextContent()).to.deep.equal(['brand']);
@@ -66,7 +66,7 @@ describe('
- Toolbar', () => {
},
];
- const { getByText, getByRole } = render(
+ render(
- Toolbar', () => {
,
);
- fireEvent.click(getByText('Columns'));
- const showHideAllCheckbox = getByRole('checkbox', { name: 'Show/Hide All' });
+ fireEvent.click(screen.getByText('Columns'));
+ const showHideAllCheckbox = screen.getByRole('checkbox', { name: 'Show/Hide All' });
fireEvent.click(showHideAllCheckbox);
expect(getColumnHeadersTextContent()).to.deep.equal(['id', 'brand']);
fireEvent.click(showHideAllCheckbox);
@@ -135,7 +135,7 @@ describe('
- Toolbar', () => {
);
};
- const { getByText } = render(
+ render(
- Toolbar', () => {
,
);
- fireEvent.click(getByText('Columns'));
+ fireEvent.click(screen.getByText('Columns'));
const searchInput = document.querySelector('input[type="text"]')!;
fireEvent.change(searchInput, { target: { value: 'test' } });
diff --git a/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.test.tsx b/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.test.tsx
index 1836534d02821..2dc85c2aa91d3 100644
--- a/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.test.tsx
+++ b/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.test.tsx
@@ -1,13 +1,7 @@
import * as React from 'react';
import { spy } from 'sinon';
import { expect } from 'chai';
-import {
- screen,
- fireEvent,
- getByRole,
- fireTouchChangedEvent,
- userEvent,
-} from '@mui/internal-test-utils';
+import { screen, fireEvent, within, fireTouchChangedEvent } from '@mui/internal-test-utils';
import {
adapterToUse,
buildPickerDragInteractions,
@@ -21,10 +15,11 @@ import {
} from '@mui/x-date-pickers-pro/DateRangeCalendar';
import { DateRangePickerDay } from '@mui/x-date-pickers-pro/DateRangePickerDay';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
import { RangePosition } from '../models';
const getPickerDay = (name: string, picker = 'January 2018') =>
- getByRole(screen.getByRole('grid', { name: picker }), 'gridcell', { name });
+ within(screen.getByRole('grid', { name: picker })).getByRole('gridcell', { name });
const dynamicShouldDisableDate = (date, position: RangePosition) => {
if (position === 'end') {
@@ -540,7 +535,7 @@ describe('
', () => {
);
const renderCountBeforeChange = RenderCount.callCount;
- userEvent.mousePress(getPickerDay('2'));
+ fireUserEvent.mousePress(getPickerDay('2'));
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(2); // 2 render * 1 day
});
@@ -555,10 +550,10 @@ describe('
', () => {
/>,
);
- userEvent.mousePress(getPickerDay('2'));
+ fireUserEvent.mousePress(getPickerDay('2'));
const renderCountBeforeChange = RenderCount.callCount;
- userEvent.mousePress(getPickerDay('4'));
+ fireUserEvent.mousePress(getPickerDay('4'));
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(6); // 2 render * 3 day
});
});
diff --git a/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.test.tsx b/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.test.tsx
index c6b3c1487e6d0..2d6094f4db182 100644
--- a/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.test.tsx
@@ -23,14 +23,14 @@ describe('
', () => {
it('should not open mobile picker dialog when clicked on input', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const { unmount } = renderWithProps({ enableAccessibleFieldDOMStructure: true });
fireEvent.click(getFieldInputRoot());
clock.runToLast();
expect(screen.queryByRole('tooltip')).not.to.equal(null);
expect(screen.queryByRole('dialog')).to.equal(null);
- v7Response.unmount();
+ unmount();
// Test with v6 input
renderWithProps({ enableAccessibleFieldDOMStructure: false });
diff --git a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/DesktopDateRangePicker.test.tsx b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/DesktopDateRangePicker.test.tsx
index 6137c60421f0b..ee452e3e68ad8 100644
--- a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/DesktopDateRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/DesktopDateRangePicker.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { screen, fireEvent, userEvent, act, getByRole } from '@mui/internal-test-utils';
+import { screen, fireEvent, act, within } from '@mui/internal-test-utils';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DesktopDateRangePicker } from '@mui/x-date-pickers-pro/DesktopDateRangePicker';
@@ -15,11 +15,12 @@ import {
getFieldSectionsContainer,
getTextbox,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
const getPickerDay = (name: string, picker = 'January 2018') =>
- getByRole(screen.getByRole('grid', { name: picker }), 'gridcell', { name });
+ within(screen.getByRole('grid', { name: picker })).getByRole('gridcell', { name });
describe('
', () => {
const { render, clock } = createPickerRenderer({
@@ -93,7 +94,7 @@ describe('
', () => {
describe('Field slot: SingleInputDateRangeField', () => {
it('should add focused class to the field when it is focused', () => {
// test v7 behavior
- const response = render(
+ const { unmount } = render(
', () => {
expect(sectionsContainer.parentElement).to.have.class('Mui-focused');
- response.unmount();
+ unmount();
// test v6 behavior
render(
);
@@ -118,7 +119,7 @@ describe('
', () => {
it('should render the input with a given `name` when `SingleInputDateRangeField` is used', () => {
// Test with v7 input
- const v7Response = render(
+ const { unmount } = render(
', () => {
);
expect(screen.getByRole
('textbox', { hidden: true }).name).to.equal('test');
- v7Response.unmount();
+ unmount();
// Test with v6 input
render();
@@ -244,13 +245,13 @@ describe('', () => {
expect(onClose.callCount).to.equal(0);
// Change the start date
- userEvent.mousePress(getPickerDay('3'));
+ fireUserEvent.mousePress(getPickerDay('3'));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0][0]).toEqualDateTime(new Date(2018, 0, 3));
expect(onChange.lastCall.args[0][1]).toEqualDateTime(defaultValue[1]);
// Change the end date
- userEvent.mousePress(getPickerDay('5'));
+ fireUserEvent.mousePress(getPickerDay('5'));
expect(onChange.callCount).to.equal(2);
expect(onChange.lastCall.args[0][0]).toEqualDateTime(new Date(2018, 0, 3));
expect(onChange.lastCall.args[0][1]).toEqualDateTime(new Date(2018, 0, 5));
@@ -287,7 +288,7 @@ describe('', () => {
expect(onClose.callCount).to.equal(0);
// Change the end date
- userEvent.mousePress(getPickerDay('3'));
+ fireUserEvent.mousePress(getPickerDay('3'));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0][0]).toEqualDateTime(defaultValue[0]);
expect(onChange.lastCall.args[0][1]).toEqualDateTime(new Date(2018, 0, 3));
@@ -318,7 +319,7 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'end' });
// Change the end date
- userEvent.mousePress(getPickerDay('3'));
+ fireUserEvent.mousePress(getPickerDay('3'));
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
@@ -346,7 +347,7 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'start' });
// Change the start date (already tested)
- userEvent.mousePress(getPickerDay('3'));
+ fireUserEvent.mousePress(getPickerDay('3'));
// Dismiss the picker
// eslint-disable-next-line material-ui/disallow-active-element-as-key-event-target -- don't care
@@ -380,12 +381,12 @@ describe('', () => {
// Dismiss the picker
const input = document.getElementById('test-id')!;
+ fireEvent.mouseDown(input);
act(() => {
- fireEvent.mouseDown(input);
input.focus();
- fireEvent.mouseUp(input);
- clock.runToLast();
});
+ fireEvent.mouseUp(input);
+ clock.runToLast();
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
@@ -417,17 +418,17 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'start' });
// Change the start date (already tested)
- userEvent.mousePress(getPickerDay('3'));
+ fireUserEvent.mousePress(getPickerDay('3'));
clock.runToLast();
// Dismiss the picker
const input = document.getElementById('test-id')!;
+ fireEvent.mouseDown(input);
act(() => {
- fireEvent.mouseDown(input);
input.focus();
- fireEvent.mouseUp(input);
});
+ fireEvent.mouseUp(input);
clock.runToLast();
@@ -453,7 +454,7 @@ describe('', () => {
);
// Dismiss the picker
- userEvent.mousePress(document.body);
+ fireUserEvent.mousePress(document.body);
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
@@ -521,7 +522,7 @@ describe('', () => {
expect(screen.getByRole('tooltip')).toBeVisible();
// Change the start date (already tested)
- userEvent.mousePress(getPickerDay('3'));
+ fireUserEvent.mousePress(getPickerDay('3'));
clock.runToLast();
act(() => {
@@ -559,7 +560,7 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'start' });
// Clear the date
- userEvent.mousePress(screen.getByText(/clear/i));
+ fireUserEvent.mousePress(screen.getByText(/clear/i));
expect(onChange.callCount).to.equal(1); // Start date change
expect(onChange.lastCall.args[0]).to.deep.equal([null, null]);
expect(onAccept.callCount).to.equal(1);
@@ -586,7 +587,7 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'start' });
// Clear the date
- userEvent.mousePress(screen.getByText(/clear/i));
+ fireUserEvent.mousePress(screen.getByText(/clear/i));
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(1);
diff --git a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/describes.DesktopDateRangePicker.test.tsx b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/describes.DesktopDateRangePicker.test.tsx
index ff1a2bf8b2c17..2639cbebef6bd 100644
--- a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/describes.DesktopDateRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/describes.DesktopDateRangePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import {
adapterToUse,
createPickerRenderer,
@@ -13,6 +13,7 @@ import {
import { DesktopDateRangePicker } from '@mui/x-date-pickers-pro/DesktopDateRangePicker';
import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({
@@ -86,7 +87,7 @@ describe(' - Describes', () => {
}
if (isOpened) {
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getAllByRole('gridcell', {
name: adapterToUse.getDate(newValue[setEndDate ? 1 : 0]).toString(),
})[0],
@@ -148,7 +149,7 @@ describe(' - Describes', () => {
}
if (isOpened) {
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getAllByRole('gridcell', {
name: adapterToUse.getDate(newValue[setEndDate ? 1 : 0]).toString(),
})[0],
diff --git a/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/DesktopDateTimeRangePicker.test.tsx b/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/DesktopDateTimeRangePicker.test.tsx
index f39f90bdb0d19..e866a51400818 100644
--- a/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/DesktopDateTimeRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/DesktopDateTimeRangePicker.test.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -8,6 +8,7 @@ import {
getFieldSectionsContainer,
expectFieldValueV7,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
import { DesktopDateTimeRangePicker } from '../DesktopDateTimeRangePicker';
describe('', () => {
@@ -23,16 +24,16 @@ describe('', () => {
openPicker({ type: 'date-time-range', variant: 'desktop', initialFocus: 'start' });
// select start date range
- userEvent.mousePress(screen.getByRole('gridcell', { name: '11' }));
- userEvent.mousePress(screen.getByRole('option', { name: '4 hours' }));
- userEvent.mousePress(screen.getByRole('option', { name: '5 minutes' }));
- userEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '11' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '4 hours' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '5 minutes' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
// select end date range on the same day
- userEvent.mousePress(screen.getByRole('gridcell', { name: '11' }));
- userEvent.mousePress(screen.getByRole('option', { name: '5 hours' }));
- userEvent.mousePress(screen.getByRole('option', { name: '10 minutes' }));
- userEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '11' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '5 hours' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '10 minutes' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
const startSectionsContainer = getFieldSectionsContainer(0);
const endSectionsContainer = getFieldSectionsContainer(1);
diff --git a/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/describes.DesktopDateTimeRangePicker.test.tsx b/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/describes.DesktopDateTimeRangePicker.test.tsx
index 25518f4a44f34..bd7c125ec4b4a 100644
--- a/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/describes.DesktopDateTimeRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/describes.DesktopDateTimeRangePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { describeConformance, screen, userEvent } from '@mui/internal-test-utils';
+import { describeConformance, screen } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -9,6 +9,7 @@ import {
describeRangeValidation,
getFieldSectionsContainer,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
import { DesktopDateTimeRangePicker } from '../DesktopDateTimeRangePicker';
describe(' - Describes', () => {
@@ -101,7 +102,7 @@ describe(' - Describes', () => {
];
}
if (isOpened) {
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('gridcell', {
name: adapterToUse.getDate(newValue[setEndDate ? 1 : 0]).toString(),
}),
@@ -112,8 +113,10 @@ describe(' - Describes', () => {
hasMeridiem ? 'hours12h' : 'hours24h',
);
const hoursNumber = adapterToUse.getHours(newValue[setEndDate ? 1 : 0]);
- userEvent.mousePress(screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }));
- userEvent.mousePress(
+ fireUserEvent.mousePress(
+ screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }),
+ );
+ fireUserEvent.mousePress(
screen.getByRole('option', {
name: `${adapterToUse.getMinutes(newValue[setEndDate ? 1 : 0])} minutes`,
}),
@@ -121,7 +124,7 @@ describe(' - Describes', () => {
if (hasMeridiem) {
// meridiem is an extra view on `DesktopDateTimeRangePicker`
// we need to click it to finish selection
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('option', { name: hoursNumber >= 12 ? 'PM' : 'AM' }),
);
}
diff --git a/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/MobileDateRangePicker.test.tsx b/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/MobileDateRangePicker.test.tsx
index e27cb9084aa31..177cf4752e9ae 100644
--- a/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/MobileDateRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/MobileDateRangePicker.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { spy } from 'sinon';
import { expect } from 'chai';
-import { screen, userEvent, fireEvent } from '@mui/internal-test-utils';
+import { screen, fireEvent } from '@mui/internal-test-utils';
import { MobileDateRangePicker } from '@mui/x-date-pickers-pro/MobileDateRangePicker';
import {
createPickerRenderer,
@@ -9,6 +9,7 @@ import {
openPicker,
getFieldSectionsContainer,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
import { DateRange } from '@mui/x-date-pickers-pro/models';
import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField';
@@ -18,7 +19,7 @@ describe('', () => {
describe('Field slot: SingleInputDateRangeField', () => {
it('should render the input with a given `name` when `SingleInputDateRangeField` is used', () => {
// Test with v7 input
- const v7Response = render(
+ const { unmount } = render(
', () => {
);
expect(screen.getByRole('textbox', { hidden: true }).name).to.equal('test');
- v7Response.unmount();
+ unmount();
// Test with v6 input
render();
@@ -84,13 +85,13 @@ describe('', () => {
expect(onClose.callCount).to.equal(0);
// Change the start date
- userEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0][0]).toEqualDateTime(new Date(2018, 0, 3));
expect(onChange.lastCall.args[0][1]).toEqualDateTime(defaultValue[1]);
// Change the end date
- userEvent.mousePress(screen.getByRole('gridcell', { name: '5' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '5' }));
expect(onChange.callCount).to.equal(2);
expect(onChange.lastCall.args[0][0]).toEqualDateTime(new Date(2018, 0, 3));
expect(onChange.lastCall.args[0][1]).toEqualDateTime(new Date(2018, 0, 5));
@@ -125,7 +126,7 @@ describe('', () => {
expect(onClose.callCount).to.equal(0);
// Change the end date
- userEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0][0]).toEqualDateTime(defaultValue[0]);
expect(onChange.lastCall.args[0][1]).toEqualDateTime(new Date(2018, 0, 3));
@@ -154,7 +155,7 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'end' });
// Change the end date
- userEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
expect(onAccept.callCount).to.equal(1);
expect(onAccept.lastCall.args[0][0]).toEqualDateTime(defaultValue[0]);
@@ -185,10 +186,10 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
// Change the start date (already tested)
- userEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
// Cancel the modifications
- userEvent.mousePress(screen.getByText(/cancel/i));
+ fireUserEvent.mousePress(screen.getByText(/cancel/i));
expect(onChange.callCount).to.equal(2); // Start date change + reset
expect(onChange.lastCall.args[0][0]).toEqualDateTime(defaultValue[0]);
expect(onChange.lastCall.args[0][1]).toEqualDateTime(defaultValue[1]);
@@ -218,10 +219,10 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
// Change the start date (already tested)
- userEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
// Accept the modifications
- userEvent.mousePress(screen.getByText(/ok/i));
+ fireUserEvent.mousePress(screen.getByText(/ok/i));
expect(onChange.callCount).to.equal(1); // Start date change
expect(onAccept.callCount).to.equal(1);
expect(onAccept.lastCall.args[0][0]).toEqualDateTime(new Date(2018, 0, 3));
@@ -252,7 +253,7 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
// Clear the date
- userEvent.mousePress(screen.getByText(/clear/i));
+ fireUserEvent.mousePress(screen.getByText(/clear/i));
expect(onChange.callCount).to.equal(1); // Start date change
expect(onChange.lastCall.args[0]).to.deep.equal([null, null]);
expect(onAccept.callCount).to.equal(1);
@@ -279,7 +280,7 @@ describe('', () => {
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
// Clear the date
- userEvent.mousePress(screen.getByText(/clear/i));
+ fireUserEvent.mousePress(screen.getByText(/clear/i));
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(1);
diff --git a/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/describes.MobileDateRangePicker.test.tsx b/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/describes.MobileDateRangePicker.test.tsx
index eea31d3a3659e..7503ccadc73ef 100644
--- a/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/describes.MobileDateRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/describes.MobileDateRangePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { screen, userEvent, fireDiscreteEvent } from '@mui/internal-test-utils';
+import { screen, fireDiscreteEvent } from '@mui/internal-test-utils';
import { MobileDateRangePicker } from '@mui/x-date-pickers-pro/MobileDateRangePicker';
import {
adapterToUse,
@@ -12,6 +12,7 @@ import {
getFieldSectionsContainer,
} from 'test/utils/pickers';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({
@@ -86,7 +87,7 @@ describe(' - Describes', () => {
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
}
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getAllByRole('gridcell', {
name: adapterToUse.getDate(newValue[setEndDate ? 1 : 0]).toString(),
})[0],
diff --git a/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/tests/describes.MobileDateTimeRangePicker.test.tsx b/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/tests/describes.MobileDateTimeRangePicker.test.tsx
index 4aadcac52f6d7..1422ba7bb2332 100644
--- a/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/tests/describes.MobileDateTimeRangePicker.test.tsx
+++ b/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/tests/describes.MobileDateTimeRangePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { describeConformance, fireEvent, screen, userEvent } from '@mui/internal-test-utils';
+import { describeConformance, fireEvent, screen } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -10,6 +10,7 @@ import {
getFieldSectionsContainer,
openPicker,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
import { MobileDateTimeRangePicker } from '../MobileDateTimeRangePicker';
describe(' - Describes', () => {
@@ -108,12 +109,12 @@ describe(' - Describes', () => {
// if we want to set the end date, we firstly need to switch to end date "range position"
if (setEndDate) {
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('button', { name: adapterToUse.format(value[1], 'shortDate') }),
);
}
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('gridcell', {
name: adapterToUse.getDate(newValue[setEndDate ? 1 : 0]).toString(),
}),
@@ -124,8 +125,10 @@ describe(' - Describes', () => {
hasMeridiem ? 'hours12h' : 'hours24h',
);
const hoursNumber = adapterToUse.getHours(newValue[setEndDate ? 1 : 0]);
- userEvent.mousePress(screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }));
- userEvent.mousePress(
+ fireUserEvent.mousePress(
+ screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }),
+ );
+ fireUserEvent.mousePress(
screen.getByRole('option', {
name: `${adapterToUse.getMinutes(newValue[setEndDate ? 1 : 0])} minutes`,
}),
@@ -133,7 +136,9 @@ describe(' - Describes', () => {
if (hasMeridiem) {
// meridiem is an extra view on `MobileDateTimeRangePicker`
// we need to click it to finish selection
- userEvent.mousePress(screen.getByRole('option', { name: hoursNumber >= 12 ? 'PM' : 'AM' }));
+ fireUserEvent.mousePress(
+ screen.getByRole('option', { name: hoursNumber >= 12 ? 'PM' : 'AM' }),
+ );
}
// Close the picker
if (!isOpened) {
@@ -142,7 +147,7 @@ describe(' - Describes', () => {
clock.runToLast();
} else {
// return to the start date view in case we'd like to repeat the selection process
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('button', { name: adapterToUse.format(newValue[0], 'shortDate') }),
);
}
diff --git a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/editing.SingleInputDateRangeField.test.tsx b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/editing.SingleInputDateRangeField.test.tsx
index 33b138e7262da..b392a9d809845 100644
--- a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/editing.SingleInputDateRangeField.test.tsx
+++ b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/editing.SingleInputDateRangeField.test.tsx
@@ -13,31 +13,31 @@ describe(' - Editing', () => {
describeAdapters(`key: Delete`, SingleInputDateRangeField, ({ adapter, renderWithProps }) => {
it('should clear all the sections when all sections are selected and all sections are completed', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- fireEvent.keyDown(v7Response.getSectionsContainer(), { key: 'Delete' });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
+ fireEvent.keyDown(view.getSectionsContainer(), { key: 'Delete' });
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
@@ -48,33 +48,33 @@ describe(' - Editing', () => {
it('should clear all the sections when all sections are selected and not all sections are completed', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
- fireEvent.input(v7Response.getActiveSection(0), { target: { innerHTML: 'j' } });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January YYYY – MMMM YYYY');
+ fireEvent.input(view.getActiveSection(0), { target: { innerHTML: 'j' } });
+ expectFieldValueV7(view.getSectionsContainer(), 'January YYYY – MMMM YYYY');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- fireEvent.keyDown(v7Response.getSectionsContainer(), { key: 'Delete' });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
+ fireEvent.keyDown(view.getSectionsContainer(), { key: 'Delete' });
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
fireEvent.change(input, {
@@ -93,33 +93,33 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- fireEvent.keyDown(v7Response.getSectionsContainer(), { key: 'Delete' });
+ fireEvent.keyDown(view.getSectionsContainer(), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(0);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
onChange: onChangeV6,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
@@ -132,52 +132,52 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Start date
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(1);
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowRight' });
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(1);
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'ArrowRight' });
- fireEvent.keyDown(v7Response.getActiveSection(2), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(2), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(2);
expect(onChangeV7.lastCall.firstArg[0]).to.equal(null);
expect(onChangeV7.lastCall.firstArg[1]).toEqualDateTime(adapter.addYears(adapter.date(), 1));
// End date
- fireEvent.keyDown(v7Response.getActiveSection(2), { key: 'ArrowRight' });
- fireEvent.keyDown(v7Response.getActiveSection(3), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(2), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(3), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(3);
- fireEvent.keyDown(v7Response.getActiveSection(3), { key: 'ArrowRight' });
- fireEvent.keyDown(v7Response.getActiveSection(4), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(3), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(4), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(3);
- fireEvent.keyDown(v7Response.getActiveSection(4), { key: 'ArrowRight' });
- fireEvent.keyDown(v7Response.getActiveSection(5), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(4), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(5), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(4);
expect(onChangeV7.lastCall.firstArg[0]).to.equal(null);
expect(onChangeV7.lastCall.firstArg[1]).to.equal(null);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
onChange: onChangeV6,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Start date
fireEvent.keyDown(input, { key: 'Delete' });
@@ -209,27 +209,27 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(1);
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'Delete' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(1);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
@@ -237,7 +237,7 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.keyDown(input, { key: 'Delete' });
expect(onChangeV6.callCount).to.equal(1);
@@ -253,31 +253,31 @@ describe(' - Editing', () => {
({ adapter, renderWithProps }) => {
it('should clear all the sections when all sections are selected and all sections are completed (Backspace)', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- v7Response.pressKey(null, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
+ view.pressKey(null, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
@@ -288,33 +288,33 @@ describe(' - Editing', () => {
it('should clear all the sections when all sections are selected and not all sections are completed (Backspace)', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
- fireEvent.input(v7Response.getActiveSection(0), { target: { innerHTML: 'j' } });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January YYYY – MMMM YYYY');
+ fireEvent.input(view.getActiveSection(0), { target: { innerHTML: 'j' } });
+ expectFieldValueV7(view.getSectionsContainer(), 'January YYYY – MMMM YYYY');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- v7Response.pressKey(null, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
+ view.pressKey(null, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY – MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
fireEvent.change(input, {
@@ -333,33 +333,33 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- v7Response.pressKey(null, '');
+ view.pressKey(null, '');
expect(onChangeV7.callCount).to.equal(0);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
onChange: onChangeV6,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
@@ -372,22 +372,22 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Start date
- v7Response.pressKey(0, '');
+ view.pressKey(0, '');
expect(onChangeV7.callCount).to.equal(1);
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowRight' });
- v7Response.pressKey(1, '');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowRight' });
+ view.pressKey(1, '');
expect(onChangeV7.callCount).to.equal(1);
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'ArrowRight' });
- v7Response.pressKey(2, '');
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'ArrowRight' });
+ view.pressKey(2, '');
expect(onChangeV7.callCount).to.equal(2);
expect(onChangeV7.lastCall.firstArg[0]).to.equal(null);
expect(onChangeV7.lastCall.firstArg[1]).toEqualDateTime(
@@ -395,31 +395,31 @@ describe(' - Editing', () => {
);
// End date
- fireEvent.keyDown(v7Response.getActiveSection(2), { key: 'ArrowRight' });
- v7Response.pressKey(3, '');
+ fireEvent.keyDown(view.getActiveSection(2), { key: 'ArrowRight' });
+ view.pressKey(3, '');
expect(onChangeV7.callCount).to.equal(3);
- fireEvent.keyDown(v7Response.getActiveSection(3), { key: 'ArrowRight' });
- v7Response.pressKey(4, '');
+ fireEvent.keyDown(view.getActiveSection(3), { key: 'ArrowRight' });
+ view.pressKey(4, '');
expect(onChangeV7.callCount).to.equal(3);
- fireEvent.keyDown(v7Response.getActiveSection(4), { key: 'ArrowRight' });
- v7Response.pressKey(5, '');
+ fireEvent.keyDown(view.getActiveSection(4), { key: 'ArrowRight' });
+ view.pressKey(5, '');
expect(onChangeV7.callCount).to.equal(4);
expect(onChangeV7.lastCall.firstArg[0]).to.equal(null);
expect(onChangeV7.lastCall.firstArg[1]).to.equal(null);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
onChange: onChangeV6,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Start date
fireEvent.change(input, { target: { value: '/15/2022 – 06/15/2023' } });
@@ -453,27 +453,27 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- v7Response.pressKey(0, '');
+ view.pressKey(0, '');
expect(onChangeV7.callCount).to.equal(1);
- v7Response.pressKey(0, '');
+ view.pressKey(0, '');
expect(onChangeV7.callCount).to.equal(1);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: [adapter.date(), adapter.addYears(adapter.date(), 1)],
@@ -481,7 +481,7 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: ' 2022 – June 2023' } });
expect(onChangeV6.callCount).to.equal(1);
diff --git a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/selection.SingleInputDateRangeField.test.tsx b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/selection.SingleInputDateRangeField.test.tsx
index 26f9fe2ceedd8..ce9852d7fd25d 100644
--- a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/selection.SingleInputDateRangeField.test.tsx
+++ b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/selection.SingleInputDateRangeField.test.tsx
@@ -22,14 +22,14 @@ describe(' - Selection', () => {
describe('Focus', () => {
it('should select 1st section (v7) / all sections (v6) on mount focus (`autoFocus = true`)', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
autoFocus: true,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY – MM/DD/YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY – MM/DD/YYYY');
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
renderWithProps({ autoFocus: true, enableAccessibleFieldDOMStructure: false });
@@ -57,89 +57,89 @@ describe(' - Selection', () => {
describe('Click', () => {
it('should select the clicked selection when the input is already focused', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: [null, adapterToUse.date('2022-02-24')],
});
// Start date
- v7Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v7Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
// End date
- v7Response.selectSection('month', 'last');
+ view.selectSection('month', 'last');
expect(getCleanedSelectedContent()).to.equal('02');
- v7Response.selectSection('day', 'last');
+ view.selectSection('day', 'last');
expect(getCleanedSelectedContent()).to.equal('24');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
value: [null, adapterToUse.date('2022-02-24')],
});
// Start date
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v6Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
// End date
- v6Response.selectSection('month', 'last');
+ view.selectSection('month', 'last');
expect(getCleanedSelectedContent()).to.equal('02');
- v6Response.selectSection('day', 'last');
+ view.selectSection('day', 'last');
expect(getCleanedSelectedContent()).to.equal('24');
});
it('should not change the selection when clicking on the only already selected section', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: [null, adapterToUse.date('2022-02-24')],
});
// Start date
- v7Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v7Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
// End date
- v7Response.selectSection('day', 'last');
+ view.selectSection('day', 'last');
expect(getCleanedSelectedContent()).to.equal('24');
- v7Response.selectSection('day', 'last');
+ view.selectSection('day', 'last');
expect(getCleanedSelectedContent()).to.equal('24');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
value: [null, adapterToUse.date('2022-02-24')],
});
// Start date
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
// End date
- v6Response.selectSection('day', 'last');
+ view.selectSection('day', 'last');
expect(getCleanedSelectedContent()).to.equal('24');
- v6Response.selectSection('day', 'last');
+ view.selectSection('day', 'last');
expect(getCleanedSelectedContent()).to.equal('24');
});
});
@@ -147,33 +147,33 @@ describe(' - Selection', () => {
describe('key: ArrowRight', () => {
it('should allow to move from left to right with ArrowRight', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('DD');
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
- fireEvent.keyDown(v7Response.getActiveSection(2), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(2), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('MM');
- fireEvent.keyDown(v7Response.getActiveSection(3), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(3), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('DD');
- fireEvent.keyDown(v7Response.getActiveSection(4), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(4), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
fireEvent.keyDown(input, { key: 'ArrowRight' });
@@ -194,20 +194,20 @@ describe(' - Selection', () => {
it('should stay on the current section when the last section is selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('year', 'last');
+ view.selectSection('year', 'last');
expect(getCleanedSelectedContent()).to.equal('YYYY');
- fireEvent.keyDown(v7Response.getActiveSection(5), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(5), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('year', 'last');
+ view.selectSection('year', 'last');
expect(getCleanedSelectedContent()).to.equal('YYYY');
fireEvent.keyDown(input, { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
@@ -217,32 +217,32 @@ describe(' - Selection', () => {
describe('key: ArrowLeft', () => {
it('should allow to move from right to left with ArrowLeft', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('year', 'last');
+ view.selectSection('year', 'last');
expect(getCleanedSelectedContent()).to.equal('YYYY');
- fireEvent.keyDown(v7Response.getActiveSection(5), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(5), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('DD');
- fireEvent.keyDown(v7Response.getActiveSection(4), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(4), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
- fireEvent.keyDown(v7Response.getActiveSection(3), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(3), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
- fireEvent.keyDown(v7Response.getActiveSection(2), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(2), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('DD');
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('year', 'last');
+ view.selectSection('year', 'last');
expect(getCleanedSelectedContent()).to.equal('YYYY');
fireEvent.keyDown(input, { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('DD');
@@ -262,20 +262,20 @@ describe(' - Selection', () => {
it('should stay on the current section when the first section is selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
fireEvent.keyDown(input, { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
diff --git a/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx b/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx
index 6f8301a14602e..3f51bd19e5d0d 100644
--- a/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx
+++ b/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx
@@ -117,21 +117,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx b/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx
index b88d9390fced8..03caf784f4f13 100644
--- a/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx
+++ b/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx
@@ -78,21 +78,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.test.tsx b/packages/x-date-pickers/src/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.test.tsx
index 4a35a3d2558a6..f97f309af0fd3 100644
--- a/packages/x-date-pickers/src/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.test.tsx
+++ b/packages/x-date-pickers/src/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.test.tsx
@@ -64,21 +64,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx b/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx
index dda1f5c56ab9b..9095ecc60cc63 100644
--- a/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx
+++ b/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx
@@ -148,21 +148,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx b/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx
index 8c68148e8620b..372dbfab75f60 100644
--- a/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx
+++ b/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx
@@ -107,21 +107,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
@@ -166,25 +163,22 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: 'DD',
});
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
format: 'DD',
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx b/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx
index 895710889ae51..fa684d96e8608 100644
--- a/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx
+++ b/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx
@@ -161,21 +161,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx b/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx
index de006376e2827..bd86f319abe60 100644
--- a/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx
+++ b/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx
@@ -75,21 +75,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx b/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx
index 1d326ff9e3257..9a30e357c05d0 100644
--- a/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx
+++ b/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx
@@ -82,21 +82,18 @@ describe('', () => {
});
it('should have correct placeholder', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- expectFieldValueV7(
- v7Response.getSectionsContainer(),
- localizedTexts[localeKey].placeholder,
- );
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].placeholder);
});
it('should have well formatted value', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(testDate),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value);
+ expectFieldValueV7(view.getSectionsContainer(), localizedTexts[localeKey].value);
});
});
});
diff --git a/packages/x-date-pickers/src/DateCalendar/tests/DateCalendar.test.tsx b/packages/x-date-pickers/src/DateCalendar/tests/DateCalendar.test.tsx
index fb52644ced5bb..8cfd7af3ad1e5 100644
--- a/packages/x-date-pickers/src/DateCalendar/tests/DateCalendar.test.tsx
+++ b/packages/x-date-pickers/src/DateCalendar/tests/DateCalendar.test.tsx
@@ -1,10 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { fireEvent, userEvent, screen } from '@mui/internal-test-utils';
+import { fireEvent, screen } from '@mui/internal-test-utils';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';
import { PickersDay } from '@mui/x-date-pickers/PickersDay';
import { createPickerRenderer, adapterToUse } from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
@@ -136,20 +137,20 @@ describe('', () => {
const defaultDate = adapterToUse.date('2019-01-02T11:12:13.550Z');
render();
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('button', { name: 'calendar view is open, switch to year view' }),
);
- userEvent.mousePress(screen.getByRole('radio', { name: '2020' }));
+ fireUserEvent.mousePress(screen.getByRole('radio', { name: '2020' }));
// Finish the transition to the day view
clock.runToLast();
- userEvent.mousePress(screen.getByRole('gridcell', { name: '1' }));
- userEvent.mousePress(
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '1' }));
+ fireUserEvent.mousePress(
screen.getByRole('button', { name: 'calendar view is open, switch to year view' }),
);
// select the current year with a date in the past to trigger "findClosestEnabledDate"
- userEvent.mousePress(screen.getByRole('radio', { name: '2019' }));
+ fireUserEvent.mousePress(screen.getByRole('radio', { name: '2019' }));
expect(onChange.lastCall.firstArg).toEqualDateTime(defaultDate);
});
@@ -195,7 +196,7 @@ describe('', () => {
// should make the reference day firstly focusable
expect(screen.getByRole('gridcell', { name: '17' })).to.have.attribute('tabindex', '0');
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.firstArg).toEqualDateTime(new Date(2022, 3, 2, 12, 30));
});
@@ -212,7 +213,7 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.firstArg).toEqualDateTime(new Date(2019, 0, 2, 12, 20));
});
@@ -229,7 +230,7 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.firstArg).toEqualDateTime(new Date(2019, 0, 2, 12, 20));
});
@@ -245,7 +246,7 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.firstArg).toEqualDateTime(
adapterToUse.date('2018-01-02T11:11:11.111'),
@@ -620,7 +621,7 @@ describe('', () => {
);
const renderCountBeforeChange = RenderCount.callCount;
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(2); // 2 render * 1 day
});
@@ -637,7 +638,7 @@ describe('', () => {
);
const renderCountBeforeChange = RenderCount.callCount;
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(4); // 2 render * 2 days
});
});
diff --git a/packages/x-date-pickers/src/DateCalendar/tests/describes.DateCalendar.test.tsx b/packages/x-date-pickers/src/DateCalendar/tests/describes.DateCalendar.test.tsx
index 7a807f651b179..d3ab8212f0d77 100644
--- a/packages/x-date-pickers/src/DateCalendar/tests/describes.DateCalendar.test.tsx
+++ b/packages/x-date-pickers/src/DateCalendar/tests/describes.DateCalendar.test.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import { DateCalendar, dateCalendarClasses as classes } from '@mui/x-date-pickers/DateCalendar';
import { pickersDayClasses } from '@mui/x-date-pickers/PickersDay';
import {
@@ -10,6 +10,7 @@ import {
describeValue,
} from 'test/utils/pickers';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -47,7 +48,7 @@ describe(' - Describes', () => {
},
setNewValue: (value) => {
const newValue = adapterToUse.addDays(value, 1);
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('gridcell', { name: adapterToUse.getDate(newValue).toString() }),
);
diff --git a/packages/x-date-pickers/src/DateCalendar/tests/timezone.DateCalendar.test.tsx b/packages/x-date-pickers/src/DateCalendar/tests/timezone.DateCalendar.test.tsx
index 59249ab7660bc..795a3bf042afa 100644
--- a/packages/x-date-pickers/src/DateCalendar/tests/timezone.DateCalendar.test.tsx
+++ b/packages/x-date-pickers/src/DateCalendar/tests/timezone.DateCalendar.test.tsx
@@ -1,8 +1,9 @@
import * as React from 'react';
import { spy } from 'sinon';
import { expect } from 'chai';
-import { userEvent, screen } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import { describeAdapters } from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';
const TIMEZONE_TO_TEST = ['UTC', 'system', 'America/New_York'];
@@ -17,7 +18,7 @@ describe(' - Timezone', () => {
const onChange = spy();
render();
- userEvent.mousePress(screen.getByRole('gridcell', { name: '25' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '25' }));
const expectedDate = adapter.setDate(adapter.date(undefined, 'default'), 25);
// Check the `onChange` value (uses default timezone, e.g: UTC, see TZ env variable)
@@ -34,7 +35,7 @@ describe(' - Timezone', () => {
it('should use timezone prop for onChange when no value is provided', () => {
const onChange = spy();
render();
- userEvent.mousePress(screen.getByRole('gridcell', { name: '25' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '25' }));
const expectedDate = adapter.setDate(
adapter.startOfDay(adapter.date(undefined, timezone)),
25,
@@ -52,7 +53,7 @@ describe(' - Timezone', () => {
render();
- userEvent.mousePress(screen.getByRole('gridcell', { name: '25' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '25' }));
const expectedDate = adapter.setDate(value, 25);
// Check the `onChange` value (uses timezone prop)
diff --git a/packages/x-date-pickers/src/DateField/tests/editing.DateField.test.tsx b/packages/x-date-pickers/src/DateField/tests/editing.DateField.test.tsx
index 7c6ac2b0a0bc8..b5140fdffb725 100644
--- a/packages/x-date-pickers/src/DateField/tests/editing.DateField.test.tsx
+++ b/packages/x-date-pickers/src/DateField/tests/editing.DateField.test.tsx
@@ -1,13 +1,14 @@
import { expect } from 'chai';
import { spy } from 'sinon';
import { DateField } from '@mui/x-date-pickers/DateField';
-import { act, userEvent, fireEvent } from '@mui/internal-test-utils';
+import { act, fireEvent } from '@mui/internal-test-utils';
import {
expectFieldValueV7,
getTextbox,
describeAdapters,
expectFieldValueV6,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Editing', () => {
describeAdapters('key: ArrowDown', DateField, ({ adapter, testFieldKeyPress }) => {
@@ -213,30 +214,30 @@ describe(' - Editing', () => {
describeAdapters('key: Delete', DateField, ({ adapter, testFieldKeyPress, renderWithProps }) => {
it('should clear the selected section when only this section is completed', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
- v7Response.pressKey(0, 'j');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January YYYY');
+ view.pressKey(0, 'j');
+ expectFieldValueV7(view.getSectionsContainer(), 'January YYYY');
- userEvent.keyPress(v7Response.getActiveSection(0), { key: 'Delete' });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY');
+ fireUserEvent.keyPress(view.getActiveSection(0), { key: 'Delete' });
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
fireEvent.change(input, {
@@ -244,7 +245,7 @@ describe(' - Editing', () => {
}); // press "j"
expectFieldValueV6(input, 'January YYYY');
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expectFieldValueV6(input, 'MMMM YYYY');
});
@@ -259,68 +260,68 @@ describe(' - Editing', () => {
it('should clear all the sections when all sections are selected and all sections are completed', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- userEvent.keyPress(v7Response.getSectionsContainer(), { key: 'Delete' });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY');
+ fireUserEvent.keyPress(view.getSectionsContainer(), { key: 'Delete' });
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expectFieldValueV6(input, 'MMMM YYYY');
});
it('should clear all the sections when all sections are selected and not all sections are completed', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
- v7Response.pressKey(0, 'j');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January YYYY');
+ view.pressKey(0, 'j');
+ expectFieldValueV7(view.getSectionsContainer(), 'January YYYY');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- userEvent.keyPress(v7Response.getSectionsContainer(), { key: 'Delete' });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY');
+ fireUserEvent.keyPress(view.getSectionsContainer(), { key: 'Delete' });
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Set a value for the "month" section
fireEvent.change(input, {
@@ -329,45 +330,45 @@ describe(' - Editing', () => {
expectFieldValueV6(input, 'January YYYY');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expectFieldValueV6(input, 'MMMM YYYY');
});
it('should not keep query after typing again on a cleared section', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: adapter.formats.year,
});
- v7Response.selectSection('year');
+ view.selectSection('year');
- v7Response.pressKey(0, '2');
- expectFieldValueV7(v7Response.getSectionsContainer(), '0002');
+ view.pressKey(0, '2');
+ expectFieldValueV7(view.getSectionsContainer(), '0002');
- userEvent.keyPress(v7Response.getActiveSection(0), { key: 'Delete' });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'YYYY');
+ fireUserEvent.keyPress(view.getActiveSection(0), { key: 'Delete' });
+ expectFieldValueV7(view.getSectionsContainer(), 'YYYY');
- v7Response.pressKey(0, '2');
- expectFieldValueV7(v7Response.getSectionsContainer(), '0002');
+ view.pressKey(0, '2');
+ expectFieldValueV7(view.getSectionsContainer(), '0002');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: adapter.formats.year,
});
const input = getTextbox();
- v6Response.selectSection('year');
+ view.selectSection('year');
fireEvent.change(input, { target: { value: '2' } }); // press "2"
expectFieldValueV6(input, '0002');
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expectFieldValueV6(input, 'YYYY');
fireEvent.change(input, { target: { value: '2' } }); // press "2"
@@ -388,38 +389,38 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- userEvent.keyPress(v7Response.getSectionsContainer(), { key: 'Delete' });
+ fireUserEvent.keyPress(view.getSectionsContainer(), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(0);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
onChange: onChangeV6,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expect(onChangeV6.callCount).to.equal(0);
});
@@ -427,32 +428,32 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- userEvent.keyPress(v7Response.getActiveSection(0), { key: 'Delete' });
+ fireUserEvent.keyPress(view.getActiveSection(0), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(1);
expect(onChangeV7.lastCall.args[1].validationError).to.equal('invalidDate');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowRight' });
- userEvent.keyPress(v7Response.getActiveSection(1), { key: 'Delete' });
+ fireUserEvent.keyPress(view.getActiveSection(1), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(2);
expect(onChangeV7.lastCall.firstArg).to.equal(null);
expect(onChangeV7.lastCall.args[1].validationError).to.equal(null);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
@@ -460,15 +461,15 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expect(onChangeV6.callCount).to.equal(1);
expect(onChangeV6.lastCall.args[1].validationError).to.equal('invalidDate');
- userEvent.keyPress(input, { key: 'ArrowRight' });
+ fireUserEvent.keyPress(input, { key: 'ArrowRight' });
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expect(onChangeV6.callCount).to.equal(2);
expect(onChangeV6.lastCall.firstArg).to.equal(null);
expect(onChangeV6.lastCall.args[1].validationError).to.equal(null);
@@ -478,27 +479,27 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- userEvent.keyPress(v7Response.getActiveSection(0), { key: 'Delete' });
+ fireUserEvent.keyPress(view.getActiveSection(0), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(1);
- userEvent.keyPress(v7Response.getActiveSection(0), { key: 'Delete' });
+ fireUserEvent.keyPress(view.getActiveSection(0), { key: 'Delete' });
expect(onChangeV7.callCount).to.equal(1);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
@@ -506,12 +507,12 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expect(onChangeV6.callCount).to.equal(1);
- userEvent.keyPress(input, { key: 'Delete' });
+ fireUserEvent.keyPress(input, { key: 'Delete' });
expect(onChangeV6.callCount).to.equal(1);
});
});
@@ -748,7 +749,7 @@ describe(' - Editing', () => {
it('should not allow key editing on disabled field', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
disabled: true,
@@ -766,30 +767,30 @@ describe(' - Editing', () => {
'ArrowRight',
];
- v7Response.selectSection('month');
+ view.selectSection('month');
keys.forEach((key) => {
- v7Response.pressKey(0, key);
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ view.pressKey(0, key);
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
expect(onChangeV7.callCount).to.equal(0);
});
// digit key press
- userEvent.keyPress(v7Response.getActiveSection(0), { key: '2' });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ fireUserEvent.keyPress(view.getActiveSection(0), { key: '2' });
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
disabled: true,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// v6 doesn't allow focusing on sections when disabled
keys.forEach((key) => {
@@ -964,44 +965,44 @@ describe(' - Editing', () => {
it('should allow to type the date 29th of February for leap years', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: adapter.formats.keyboardDate,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- v7Response.pressKey(0, '2');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/DD/YYYY');
+ view.pressKey(0, '2');
+ expectFieldValueV7(view.getSectionsContainer(), '02/DD/YYYY');
- v7Response.pressKey(1, '2');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/02/YYYY');
+ view.pressKey(1, '2');
+ expectFieldValueV7(view.getSectionsContainer(), '02/02/YYYY');
- v7Response.pressKey(1, '9');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/29/YYYY');
+ view.pressKey(1, '9');
+ expectFieldValueV7(view.getSectionsContainer(), '02/29/YYYY');
- v7Response.pressKey(2, '1');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/29/0001');
+ view.pressKey(2, '1');
+ expectFieldValueV7(view.getSectionsContainer(), '02/29/0001');
- v7Response.pressKey(2, '9');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/29/0019');
+ view.pressKey(2, '9');
+ expectFieldValueV7(view.getSectionsContainer(), '02/29/0019');
- v7Response.pressKey(2, '8');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/29/0198');
+ view.pressKey(2, '8');
+ expectFieldValueV7(view.getSectionsContainer(), '02/29/0198');
- v7Response.pressKey(2, '8');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/29/1988');
+ view.pressKey(2, '8');
+ expectFieldValueV7(view.getSectionsContainer(), '02/29/1988');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: adapter.formats.keyboardDate,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: '2/DD/YYYY' } });
expectFieldValueV6(input, '02/DD/YYYY');
@@ -1136,28 +1137,28 @@ describe(' - Editing', () => {
({ adapter, renderWithProps, testFieldChange }) => {
it('should clear the selected section when only this section is completed (Backspace)', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
- v7Response.pressKey(0, 'j');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January YYYY');
+ view.selectSection('month');
+ view.pressKey(0, 'j');
+ expectFieldValueV7(view.getSectionsContainer(), 'January YYYY');
- v7Response.pressKey(0, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY');
+ view.pressKey(0, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: 'j YYYY' } });
expectFieldValueV6(input, 'January YYYY');
@@ -1167,28 +1168,28 @@ describe(' - Editing', () => {
it('should clear the selected section when all sections are completed (Backspace)', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- v7Response.pressKey(0, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM 2022');
+ view.pressKey(0, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM 2022');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: ' 2022' } });
expectFieldValueV6(input, 'MMMM 2022');
@@ -1196,31 +1197,31 @@ describe(' - Editing', () => {
it('should clear all the sections when all sections are selected and all sections are completed (Backspace)', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- v7Response.pressKey(null, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY');
+ view.pressKey(null, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
@@ -1231,31 +1232,31 @@ describe(' - Editing', () => {
it('should clear all the sections when all sections are selected and not all sections are completed (Backspace)', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
});
- v7Response.selectSection('month');
- v7Response.pressKey(0, 'j');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January YYYY');
+ view.selectSection('month');
+ view.pressKey(0, 'j');
+ expectFieldValueV7(view.getSectionsContainer(), 'January YYYY');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- v7Response.pressKey(null, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM YYYY');
+ view.pressKey(null, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: 'j YYYY' } });
expectFieldValueV6(input, 'January YYYY');
@@ -1302,30 +1303,30 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
- v7Response.pressKey(0, '');
+ view.selectSection('month');
+ view.pressKey(0, '');
expect(onChangeV7.callCount).to.equal(1);
expect(onChangeV7.lastCall.args[1].validationError).to.equal('invalidDate');
- v7Response.selectSection('year');
- v7Response.pressKey(1, '');
+ view.selectSection('year');
+ view.pressKey(1, '');
expect(onChangeV7.callCount).to.equal(2);
expect(onChangeV7.lastCall.firstArg).to.equal(null);
expect(onChangeV7.lastCall.args[1].validationError).to.equal(null);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `${adapter.formats.month} ${adapter.formats.year}`,
defaultValue: adapter.date(),
@@ -1333,12 +1334,12 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: ' 2022' } });
expect(onChangeV6.callCount).to.equal(1);
expect(onChangeV6.lastCall.args[1].validationError).to.equal('invalidDate');
- userEvent.keyPress(input, { key: 'ArrowRight' });
+ fireUserEvent.keyPress(input, { key: 'ArrowRight' });
fireEvent.change(input, { target: { value: 'MMMM ' } });
expect(onChangeV6.callCount).to.equal(2);
@@ -1367,90 +1368,92 @@ describe(' - Editing', () => {
describeAdapters('Pasting', DateField, ({ adapter, renderWithProps }) => {
const firePasteEventV7 = (element: HTMLElement, pastedValue: string) => {
- act(() => {
- const clipboardEvent = new window.Event('paste', {
- bubbles: true,
- cancelable: true,
- composed: true,
- });
+ const clipboardEvent = new window.Event('paste', {
+ bubbles: true,
+ cancelable: true,
+ composed: true,
+ });
- // @ts-ignore
- clipboardEvent.clipboardData = {
- getData: () => pastedValue,
- };
+ // @ts-ignore
+ clipboardEvent.clipboardData = {
+ getData: () => pastedValue,
+ };
+ let canContinue = true;
+ act(() => {
// canContinue is `false` if default have been prevented
- const canContinue = element.dispatchEvent(clipboardEvent);
- if (!canContinue) {
- return;
- }
-
- fireEvent.input(element, { target: { textContent: pastedValue } });
+ canContinue = element.dispatchEvent(clipboardEvent);
});
+ if (!canContinue) {
+ return;
+ }
+
+ fireEvent.input(element, { target: { textContent: pastedValue } });
};
const firePasteEventV6 = (input: HTMLInputElement, pastedValue?: string, rawValue?: string) => {
- act(() => {
- const clipboardEvent = new window.Event('paste', {
- bubbles: true,
- cancelable: true,
- composed: true,
- });
+ const clipboardEvent = new window.Event('paste', {
+ bubbles: true,
+ cancelable: true,
+ composed: true,
+ });
- // @ts-ignore
- clipboardEvent.clipboardData = {
- getData: () => pastedValue ?? rawValue ?? '',
- };
+ // @ts-ignore
+ clipboardEvent.clipboardData = {
+ getData: () => pastedValue ?? rawValue ?? '',
+ };
+ let canContinue = true;
+ act(() => {
// canContinue is `false` if default have been prevented
- const canContinue = input.dispatchEvent(clipboardEvent);
- if (!canContinue) {
- return;
- }
-
- if (!pastedValue) {
- return;
- }
-
- const prevValue = input.value;
- const nextValue = `${prevValue.slice(
- 0,
- input.selectionStart || 0,
- )}${pastedValue}${prevValue.slice(input.selectionEnd || 0)}`;
- fireEvent.change(input, { target: { value: nextValue } });
+ canContinue = input.dispatchEvent(clipboardEvent);
});
+ if (!canContinue) {
+ return;
+ }
+
+ if (!pastedValue) {
+ return;
+ }
+
+ const prevValue = input.value;
+ const nextValue = `${prevValue.slice(
+ 0,
+ input.selectionStart || 0,
+ )}${pastedValue}${prevValue.slice(input.selectionEnd || 0)}`;
+ fireEvent.change(input, { target: { value: nextValue } });
};
it('should set the date when all sections are selected, the pasted value is valid and a value is provided', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date(),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- firePasteEventV7(v7Response.getSectionsContainer(), '09/16/2022');
+ firePasteEventV7(view.getSectionsContainer(), '09/16/2022');
expect(onChangeV7.callCount).to.equal(1);
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2022, 8, 16));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: adapter.date(),
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
firePasteEventV6(input, '09/16/2022');
@@ -1461,32 +1464,32 @@ describe(' - Editing', () => {
it('should set the date when all sections are selected, the pasted value is valid and no value is provided', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- firePasteEventV7(v7Response.getSectionsContainer(), '09/16/2022');
+ firePasteEventV7(view.getSectionsContainer(), '09/16/2022');
expect(onChangeV7.callCount).to.equal(1);
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2022, 8, 16));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
firePasteEventV6(input, '09/16/2022');
@@ -1497,30 +1500,30 @@ describe(' - Editing', () => {
it('should not set the date when all sections are selected and the pasted value is not valid', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- firePasteEventV7(v7Response.getSectionsContainer(), 'Some invalid content');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
- v7Response.unmount();
+ firePasteEventV7(view.getSectionsContainer(), 'Some invalid content');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
firePasteEventV6(input, 'Some invalid content');
expectFieldValueV6(input, 'MM/DD/YYYY');
@@ -1531,35 +1534,35 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
format: `${startChar}Escaped${endChar} ${adapter.formats.year}`,
});
- v7Response.selectSection('year');
+ view.selectSection('year');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- firePasteEventV7(v7Response.getSectionsContainer(), `Escaped 2014`);
+ firePasteEventV7(view.getSectionsContainer(), `Escaped 2014`);
expect(onChangeV7.callCount).to.equal(1);
expect(adapter.getYear(onChangeV7.lastCall.firstArg)).to.equal(2014);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
onChange: onChangeV6,
format: `${startChar}Escaped${endChar} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('year');
+ view.selectSection('year');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
firePasteEventV6(input, `Escaped 2014`);
expect(onChangeV6.callCount).to.equal(1);
@@ -1570,36 +1573,36 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
readOnly: true,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- firePasteEventV7(v7Response.getSectionsContainer(), '09/16/2022');
+ firePasteEventV7(view.getSectionsContainer(), '09/16/2022');
expect(onChangeV7.callCount).to.equal(0);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
onChange: onChangeV6,
readOnly: true,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
firePasteEventV6(input, '09/16/2022');
expect(onChangeV6.callCount).to.equal(0);
@@ -1609,31 +1612,31 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
- firePasteEventV7(v7Response.getActiveSection(0), '12');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
+ firePasteEventV7(view.getActiveSection(0), '12');
expect(onChangeV7.callCount).to.equal(1);
- expectFieldValueV7(v7Response.getSectionsContainer(), '12/DD/YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), '12/DD/YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
expectFieldValueV6(input, 'MM/DD/YYYY');
firePasteEventV6(input, '12');
@@ -1646,33 +1649,33 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2018-01-13'),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- expectFieldValueV7(v7Response.getSectionsContainer(), '01/13/2018');
- firePasteEventV7(v7Response.getActiveSection(0), '12');
- expectFieldValueV7(v7Response.getSectionsContainer(), '12/13/2018');
+ expectFieldValueV7(view.getSectionsContainer(), '01/13/2018');
+ firePasteEventV7(view.getActiveSection(0), '12');
+ expectFieldValueV7(view.getSectionsContainer(), '12/13/2018');
expect(onChangeV7.callCount).to.equal(1);
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2018, 11, 13));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: adapter.date('2018-01-13'),
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
expectFieldValueV6(input, '01/13/2018');
firePasteEventV6(input, '12');
@@ -1685,32 +1688,32 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2018-01-13'),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- expectFieldValueV7(v7Response.getSectionsContainer(), '01/13/2018');
- firePasteEventV7(v7Response.getActiveSection(0), 'Jun');
- expectFieldValueV7(v7Response.getSectionsContainer(), '01/13/2018');
+ expectFieldValueV7(view.getSectionsContainer(), '01/13/2018');
+ firePasteEventV7(view.getActiveSection(0), 'Jun');
+ expectFieldValueV7(view.getSectionsContainer(), '01/13/2018');
expect(onChangeV7.callCount).to.equal(0);
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: adapter.date('2018-01-13'),
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
expectFieldValueV6(input, '01/13/2018');
firePasteEventV6(input, 'Jun');
@@ -1720,37 +1723,37 @@ describe(' - Editing', () => {
it('should reset sections internal state when pasting', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2018-12-05'),
});
- v7Response.selectSection('day');
+ view.selectSection('day');
- v7Response.pressKey(1, '2');
- expectFieldValueV7(v7Response.getSectionsContainer(), '12/02/2018');
+ view.pressKey(1, '2');
+ expectFieldValueV7(view.getSectionsContainer(), '12/02/2018');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'a', ctrlKey: true });
- firePasteEventV7(v7Response.getSectionsContainer(), '09/16/2022');
- expectFieldValueV7(v7Response.getSectionsContainer(), '09/16/2022');
+ firePasteEventV7(view.getSectionsContainer(), '09/16/2022');
+ expectFieldValueV7(view.getSectionsContainer(), '09/16/2022');
- v7Response.selectSection('day');
+ view.selectSection('day');
- v7Response.pressKey(1, '2'); // Press 2
- expectFieldValueV7(v7Response.getSectionsContainer(), '09/02/2022'); // If internal state is not reset it would be 22 instead of 02
+ view.pressKey(1, '2'); // Press 2
+ expectFieldValueV7(view.getSectionsContainer(), '09/02/2022'); // If internal state is not reset it would be 22 instead of 02
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: adapter.date('2018-12-05'),
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('day');
+ view.selectSection('day');
fireEvent.change(input, { target: { value: '12/2/2018' } }); // Press 2
expectFieldValueV6(input, '12/02/2018');
@@ -1763,32 +1766,32 @@ describe(' - Editing', () => {
});
it('should allow pasting a section', () => {
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2018-12-05'),
});
- v7Response.selectSection('month');
+ view.selectSection('month');
- v7Response.pressKey(0, '1'); // Press 1
- expectFieldValueV7(v7Response.getSectionsContainer(), '01/05/2018');
+ view.pressKey(0, '1'); // Press 1
+ expectFieldValueV7(view.getSectionsContainer(), '01/05/2018');
- firePasteEventV7(v7Response.getActiveSection(0), '05');
- expectFieldValueV7(v7Response.getSectionsContainer(), '05/05/2018');
+ firePasteEventV7(view.getActiveSection(0), '05');
+ expectFieldValueV7(view.getSectionsContainer(), '05/05/2018');
- v7Response.selectSection('month'); // move back to month section
- v7Response.pressKey(0, '2'); // check that the search query has been cleared after pasting
- expectFieldValueV7(v7Response.getSectionsContainer(), '02/05/2018'); // If internal state is not reset it would be 12 instead of 02
+ view.selectSection('month'); // move back to month section
+ view.pressKey(0, '2'); // check that the search query has been cleared after pasting
+ expectFieldValueV7(view.getSectionsContainer(), '02/05/2018'); // If internal state is not reset it would be 12 instead of 02
- v7Response.unmount();
+ view.unmount();
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: adapter.date('2018-12-05'),
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: '1/05/2018' } }); // initiate search query on month section
expectFieldValueV6(input, '01/05/2018');
@@ -1796,7 +1799,7 @@ describe(' - Editing', () => {
firePasteEventV6(input, undefined, '05');
expectFieldValueV6(input, '05/05/2018');
- v6Response.selectSection('month'); // move back to month section
+ view.selectSection('month'); // move back to month section
fireEvent.change(input, { target: { value: '2/05/2018' } }); // check that the search query has been cleared after pasting
expectFieldValueV6(input, '02/05/2018'); // If internal state is not reset it would be 12 instead of 02
});
@@ -1804,32 +1807,32 @@ describe(' - Editing', () => {
it('should not allow pasting on disabled field', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
disabled: true,
});
- v7Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
- firePasteEventV7(v7Response.getSectionsContainer(), '09/16/2022');
+ firePasteEventV7(view.getSectionsContainer(), '09/16/2022');
expect(onChangeV7.callCount).to.equal(0);
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
disabled: true,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
firePasteEventV6(input, '9');
// v6 doesn't allow focusing on sections when disabled
@@ -1846,27 +1849,27 @@ describe(' - Editing', () => {
it('should not loose time information when a value is provided', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
});
- v7Response.selectSection('year');
- fireEvent.keyDown(v7Response.getActiveSection(2), { key: 'ArrowDown' });
+ view.selectSection('year');
+ fireEvent.keyDown(view.getActiveSection(2), { key: 'ArrowDown' });
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2009, 3, 3, 3, 3, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('year');
- userEvent.keyPress(input, { key: 'ArrowDown' });
+ view.selectSection('year');
+ fireUserEvent.keyPress(input, { key: 'ArrowDown' });
expect(onChangeV6.lastCall.firstArg).toEqualDateTime(new Date(2009, 3, 3, 3, 3, 3));
});
@@ -1874,51 +1877,51 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
- v7Response.pressKey(null, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
- v7Response.selectSection('month');
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
+ view.pressKey(null, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
+ view.selectSection('month');
- v7Response.pressKey(0, '1');
- expectFieldValueV7(v7Response.getSectionsContainer(), '01/DD/YYYY');
+ view.pressKey(0, '1');
+ expectFieldValueV7(view.getSectionsContainer(), '01/DD/YYYY');
- v7Response.pressKey(0, '1');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/DD/YYYY');
+ view.pressKey(0, '1');
+ expectFieldValueV7(view.getSectionsContainer(), '11/DD/YYYY');
- v7Response.pressKey(1, '2');
- v7Response.pressKey(1, '5');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/25/YYYY');
+ view.pressKey(1, '2');
+ view.pressKey(1, '5');
+ expectFieldValueV7(view.getSectionsContainer(), '11/25/YYYY');
- v7Response.pressKey(2, '2');
- v7Response.pressKey(2, '0');
- v7Response.pressKey(2, '0');
- v7Response.pressKey(2, '9');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/25/2009');
+ view.pressKey(2, '2');
+ view.pressKey(2, '0');
+ view.pressKey(2, '0');
+ view.pressKey(2, '9');
+ expectFieldValueV7(view.getSectionsContainer(), '11/25/2009');
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2009, 10, 25, 3, 3, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ view.selectSection('month');
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
fireEvent.change(input, { target: { value: '' } });
- userEvent.keyPress(input, { key: 'ArrowLeft' });
+ fireUserEvent.keyPress(input, { key: 'ArrowLeft' });
fireEvent.change(input, { target: { value: '1/DD/YYYY' } }); // Press "1"
expectFieldValueV6(input, '01/DD/YYYY');
@@ -1942,24 +1945,24 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: adapter.formats.year,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
});
- v7Response.selectSection('year');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowDown' });
+ view.selectSection('year');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowDown' });
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2009, 3, 3, 3, 3, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: adapter.formats.year,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV6,
@@ -1967,8 +1970,8 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('year');
- userEvent.keyPress(input, { key: 'ArrowDown' });
+ view.selectSection('year');
+ fireUserEvent.keyPress(input, { key: 'ArrowDown' });
expect(onChangeV6.lastCall.firstArg).toEqualDateTime(new Date(2009, 3, 3, 3, 3, 3));
});
@@ -1977,32 +1980,32 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: adapter.formats.month,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
});
- v7Response.selectSection('month');
- userEvent.keyPress(v7Response.getActiveSection(0), { key: 'ArrowDown' });
+ view.selectSection('month');
+ fireUserEvent.keyPress(view.getActiveSection(0), { key: 'ArrowDown' });
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2010, 2, 3, 3, 3, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
format: adapter.formats.month,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV6,
enableAccessibleFieldDOMStructure: false,
});
- v6Response.selectSection('month');
+ view.selectSection('month');
const input = getTextbox();
- userEvent.keyPress(input, { key: 'ArrowDown' });
+ fireUserEvent.keyPress(input, { key: 'ArrowDown' });
expect(onChangeV6.lastCall.firstArg).toEqualDateTime(new Date(2010, 2, 3, 3, 3, 3));
});
},
@@ -2015,16 +2018,16 @@ describe(' - Editing', () => {
it('should set the date when the change value is valid and no value is provided', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange: onChangeV7,
});
- fireEvent.change(v7Response.getHiddenInput(), { target: { value: '09/16/2022' } });
+ fireEvent.change(view.getHiddenInput(), { target: { value: '09/16/2022' } });
expect(onChangeV7.callCount).to.equal(1);
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2022, 8, 16));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
@@ -2043,18 +2046,18 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
});
- fireEvent.change(v7Response.getHiddenInput(), { target: { value: '09/16/2022' } });
+ fireEvent.change(view.getHiddenInput(), { target: { value: '09/16/2022' } });
expect(onChangeV7.callCount).to.equal(1);
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2022, 8, 16, 3, 3, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
@@ -2098,7 +2101,7 @@ describe(' - Editing', () => {
});
it('should support digit editing', () => {
- const v6Response = renderWithProps({
+ const view = renderWithProps({
defaultValue: adapter.date('2022-11-23'),
enableAccessibleFieldDOMStructure: false,
});
@@ -2106,53 +2109,45 @@ describe(' - Editing', () => {
const input = getTextbox();
const initialValueStr = input.value;
- v6Response.selectSection('day');
+ view.selectSection('day');
- act(() => {
- // Remove the selected section
- fireEvent.change(input, { target: { value: initialValueStr.replace('23', '') } });
+ // Remove the selected section
+ fireEvent.change(input, { target: { value: initialValueStr.replace('23', '') } });
- // Set the key pressed in the selected section
- fireEvent.change(input, { target: { value: initialValueStr.replace('23', '2') } });
- });
+ // Set the key pressed in the selected section
+ fireEvent.change(input, { target: { value: initialValueStr.replace('23', '2') } });
- act(() => {
- // Remove the selected section
- fireEvent.change(input, { target: { value: initialValueStr.replace('23', '') } });
+ // Remove the selected section
+ fireEvent.change(input, { target: { value: initialValueStr.replace('23', '') } });
- // Set the key pressed in the selected section
- fireEvent.change(input, { target: { value: initialValueStr.replace('23', '1') } });
- });
+ // Set the key pressed in the selected section
+ fireEvent.change(input, { target: { value: initialValueStr.replace('23', '1') } });
expectFieldValueV6(input, '11/01/2022');
});
it('should support letter editing', () => {
// Test with v6 input
- const v6Response = renderWithProps({
+ const view = renderWithProps({
defaultValue: adapter.date('2022-01-16'),
format: `${adapter.formats.month} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
- act(() => {
- // Remove the selected section
- fireEvent.change(input, { target: { value: ' 2022' } });
+ // Remove the selected section
+ fireEvent.change(input, { target: { value: ' 2022' } });
- // Set the key pressed in the selected section
- fireEvent.change(input, { target: { value: 'J 2022' } });
- });
+ // Set the key pressed in the selected section
+ fireEvent.change(input, { target: { value: 'J 2022' } });
- act(() => {
- // Remove the selected section
- fireEvent.change(input, { target: { value: ' 2022' } });
+ // Remove the selected section
+ fireEvent.change(input, { target: { value: ' 2022' } });
- // Set the key pressed in the selected section
- fireEvent.change(input, { target: { value: 'a 2022' } });
- });
+ // Set the key pressed in the selected section
+ fireEvent.change(input, { target: { value: 'a 2022' } });
expectFieldValueV6(input, 'April 2022');
});
@@ -2162,76 +2157,76 @@ describe(' - Editing', () => {
describeAdapters('Editing from the outside', DateField, ({ adapter, renderWithProps, clock }) => {
it('should be able to reset the value from the outside', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date('2022-11-23'),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/23/2022');
+ expectFieldValueV7(view.getSectionsContainer(), '11/23/2022');
- v7Response.setProps({ value: null });
+ view.setProps({ value: null });
- v7Response.selectSection('month');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ view.selectSection('month');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
value: adapter.date('2022-11-23'),
enableAccessibleFieldDOMStructure: false,
});
const input = getTextbox();
expectFieldValueV6(input, '11/23/2022');
- v6Response.setProps({ value: null });
+ view.setProps({ value: null });
- v6Response.selectSection('month');
+ view.selectSection('month');
expectFieldValueV6(input, 'MM/DD/YYYY');
});
it('should reset the input query state on an unfocused field', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true, value: null });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true, value: null });
- v7Response.selectSection('month');
+ view.selectSection('month');
- v7Response.pressKey(0, '1');
- expectFieldValueV7(v7Response.getSectionsContainer(), '01/DD/YYYY');
+ view.pressKey(0, '1');
+ expectFieldValueV7(view.getSectionsContainer(), '01/DD/YYYY');
- v7Response.pressKey(0, '1');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/DD/YYYY');
+ view.pressKey(0, '1');
+ expectFieldValueV7(view.getSectionsContainer(), '11/DD/YYYY');
- v7Response.pressKey(1, '2');
- v7Response.pressKey(1, '5');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/25/YYYY');
+ view.pressKey(1, '2');
+ view.pressKey(1, '5');
+ expectFieldValueV7(view.getSectionsContainer(), '11/25/YYYY');
- v7Response.pressKey(2, '2');
- v7Response.pressKey(2, '0');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/25/0020');
+ view.pressKey(2, '2');
+ view.pressKey(2, '0');
+ expectFieldValueV7(view.getSectionsContainer(), '11/25/0020');
act(() => {
- v7Response.getSectionsContainer().blur();
+ view.getSectionsContainer().blur();
});
clock.runToLast();
- v7Response.setProps({ value: adapter.date('2022-11-23') });
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/23/2022');
+ view.setProps({ value: adapter.date('2022-11-23') });
+ expectFieldValueV7(view.getSectionsContainer(), '11/23/2022');
- v7Response.selectSection('year');
+ view.selectSection('year');
- v7Response.pressKey(2, '2');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/23/0002');
- v7Response.pressKey(2, '1');
- expectFieldValueV7(v7Response.getSectionsContainer(), '11/23/0021');
+ view.pressKey(2, '2');
+ expectFieldValueV7(view.getSectionsContainer(), '11/23/0002');
+ view.pressKey(2, '1');
+ expectFieldValueV7(view.getSectionsContainer(), '11/23/0021');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false, value: null });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false, value: null });
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.change(input, { target: { value: '1/DD/YYYY' } }); // Press "1"
expectFieldValueV6(input, '01/DD/YYYY');
@@ -2251,15 +2246,15 @@ describe(' - Editing', () => {
input.blur();
});
- v6Response.setProps({ value: adapter.date('2022-11-23') });
+ view.setProps({ value: adapter.date('2022-11-23') });
expectFieldValueV6(input, '11/23/2022');
+ fireEvent.mouseDown(input);
+ fireEvent.mouseUp(input);
act(() => {
- fireEvent.mouseDown(input);
- fireEvent.mouseUp(input);
input.setSelectionRange(6, 9);
- fireEvent.click(input);
});
+ fireEvent.click(input);
fireEvent.change(input, { target: { value: '11/23/2' } }); // Press "2"
expectFieldValueV6(input, '11/23/0002');
@@ -2271,26 +2266,26 @@ describe(' - Editing', () => {
describeAdapters('Select all', DateField, ({ renderWithProps }) => {
it('should edit the 1st section when all sections are selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('month');
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
// When all sections are selected, the value only contains the key pressed
- v7Response.pressKey(null, '9');
+ view.pressKey(null, '9');
- expectFieldValueV7(v7Response.getSectionsContainer(), '09/DD/YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), '09/DD/YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
- v6Response.selectSection('month');
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view.selectSection('month');
const input = getTextbox();
// Select all sections
- userEvent.keyPress(input, { key: 'a', ctrlKey: true });
+ fireUserEvent.keyPress(input, { key: 'a', ctrlKey: true });
// When all sections are selected, the value only contains the key pressed
fireEvent.change(input, { target: { value: '9' } });
diff --git a/packages/x-date-pickers/src/DateField/tests/format.DateField.test.tsx b/packages/x-date-pickers/src/DateField/tests/format.DateField.test.tsx
index f680275405ce3..67c0df9d5edcf 100644
--- a/packages/x-date-pickers/src/DateField/tests/format.DateField.test.tsx
+++ b/packages/x-date-pickers/src/DateField/tests/format.DateField.test.tsx
@@ -12,20 +12,20 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const { start: startChar, end: endChar } = adapter.escapedCharacters;
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
// For Day.js: "[Escaped] YYYY"
format: `${startChar}Escaped${endChar} ${adapter.formats.year}`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'Escaped YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'Escaped YYYY');
- v7Response.setProps({ value: adapter.date('2019-01-01') });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'Escaped 2019');
+ view.setProps({ value: adapter.date('2019-01-01') });
+ expectFieldValueV7(view.getSectionsContainer(), 'Escaped 2019');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
// For Day.js: "[Escaped] YYYY"
format: `${startChar}Escaped${endChar} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
@@ -33,7 +33,7 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const input = getTextbox();
expectFieldPlaceholderV6(input, 'Escaped YYYY');
- v6Response.setProps({ value: adapter.date('2019-01-01') });
+ view.setProps({ value: adapter.date('2019-01-01') });
expectFieldValueV6(input, 'Escaped 2019');
});
@@ -41,21 +41,21 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const { start: startChar, end: endChar } = adapter.escapedCharacters;
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
// For Day.js: "MMMM [Escaped] YYYY"
format: `${adapter.formats.month} ${startChar}Escaped${endChar} ${adapter.formats.year}`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM Escaped YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM Escaped YYYY');
- v7Response.setProps({ value: adapter.date('2019-01-01') });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January Escaped 2019');
+ view.setProps({ value: adapter.date('2019-01-01') });
+ expectFieldValueV7(view.getSectionsContainer(), 'January Escaped 2019');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
// For Day.js: "MMMM [Escaped] YYYY"
format: `${adapter.formats.month} ${startChar}Escaped${endChar} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
@@ -64,7 +64,7 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const input = getTextbox();
expectFieldPlaceholderV6(input, 'MMMM Escaped YYYY');
- v6Response.setProps({ value: adapter.date('2019-01-01') });
+ view.setProps({ value: adapter.date('2019-01-01') });
expectFieldValueV6(input, 'January Escaped 2019');
});
@@ -77,21 +77,21 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
}
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
// For Day.js: "MMMM [Escaped[] YYYY"
format: `${adapter.formats.month} ${startChar}Escaped ${startChar}${endChar} ${adapter.formats.year}`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM Escaped [ YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM Escaped [ YYYY');
- v7Response.setProps({ value: adapter.date('2019-01-01') });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'January Escaped [ 2019');
+ view.setProps({ value: adapter.date('2019-01-01') });
+ expectFieldValueV7(view.getSectionsContainer(), 'January Escaped [ 2019');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
// For Day.js: "MMMM [Escaped[] YYYY"
format: `${adapter.formats.month} ${startChar}Escaped ${startChar}${endChar} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
@@ -100,7 +100,7 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const input = getTextbox();
expectFieldPlaceholderV6(input, 'MMMM Escaped [ YYYY');
- v6Response.setProps({ value: adapter.date('2019-01-01') });
+ view.setProps({ value: adapter.date('2019-01-01') });
expectFieldValueV6(input, 'January Escaped [ 2019');
});
@@ -108,21 +108,21 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const { start: startChar, end: endChar } = adapter.escapedCharacters;
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
// For Day.js: "[Escaped] MMMM [Escaped] YYYY"
format: `${startChar}Escaped${endChar} ${adapter.formats.month} ${startChar}Escaped${endChar} ${adapter.formats.year}`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'Escaped MMMM Escaped YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'Escaped MMMM Escaped YYYY');
- v7Response.setProps({ value: adapter.date('2019-01-01') });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'Escaped January Escaped 2019');
+ view.setProps({ value: adapter.date('2019-01-01') });
+ expectFieldValueV7(view.getSectionsContainer(), 'Escaped January Escaped 2019');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
// For Day.js: "[Escaped] MMMM [Escaped] YYYY"
format: `${startChar}Escaped${endChar} ${adapter.formats.month} ${startChar}Escaped${endChar} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
@@ -131,7 +131,7 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const input = getTextbox();
expectFieldPlaceholderV6(input, 'Escaped MMMM Escaped YYYY');
- v6Response.setProps({ value: adapter.date('2019-01-01') });
+ view.setProps({ value: adapter.date('2019-01-01') });
expectFieldValueV6(input, 'Escaped January Escaped 2019');
});
@@ -139,15 +139,15 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const { start: startChar, end: endChar } = adapter.escapedCharacters;
// Test with v7 input
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
// For Day.js: "[Escaped] [Escaped]"
format: `${startChar}Escaped${endChar} ${startChar}Escaped${endChar}`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'Escaped Escaped');
+ expectFieldValueV7(view.getSectionsContainer(), 'Escaped Escaped');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
renderWithProps({
@@ -161,30 +161,30 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
});
it('should support format without separators', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `${adapter.formats.dayOfMonth}${adapter.formats.monthShort}`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'DDMMMM');
+ expectFieldValueV7(view.getSectionsContainer(), 'DDMMMM');
});
it('should add spaces around `/` when `formatDensity = "spacious"`', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
formatDensity: `spacious`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM / DD / YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM / DD / YYYY');
- v7Response.setProps({ value: adapter.date('2019-01-01') });
- expectFieldValueV7(v7Response.getSectionsContainer(), '01 / 01 / 2019');
+ view.setProps({ value: adapter.date('2019-01-01') });
+ expectFieldValueV7(view.getSectionsContainer(), '01 / 01 / 2019');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
formatDensity: `spacious`,
enableAccessibleFieldDOMStructure: false,
});
@@ -192,27 +192,27 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const input = getTextbox();
expectFieldPlaceholderV6(input, 'MM / DD / YYYY');
- v6Response.setProps({ value: adapter.date('2019-01-01') });
+ view.setProps({ value: adapter.date('2019-01-01') });
expectFieldValueV6(input, '01 / 01 / 2019');
});
it('should add spaces around `.` when `formatDensity = "spacious"`', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
formatDensity: `spacious`,
format: adapter.expandFormat(adapter.formats.keyboardDate).replace(/\//g, '.'),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM . DD . YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM . DD . YYYY');
- v7Response.setProps({ value: adapter.date('2019-01-01') });
- expectFieldValueV7(v7Response.getSectionsContainer(), '01 . 01 . 2019');
+ view.setProps({ value: adapter.date('2019-01-01') });
+ expectFieldValueV7(view.getSectionsContainer(), '01 . 01 . 2019');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
formatDensity: `spacious`,
format: adapter.expandFormat(adapter.formats.keyboardDate).replace(/\//g, '.'),
enableAccessibleFieldDOMStructure: false,
@@ -221,27 +221,27 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const input = getTextbox();
expectFieldPlaceholderV6(input, 'MM . DD . YYYY');
- v6Response.setProps({ value: adapter.date('2019-01-01') });
+ view.setProps({ value: adapter.date('2019-01-01') });
expectFieldValueV6(input, '01 . 01 . 2019');
});
it('should add spaces around `-` when `formatDensity = "spacious"`', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
formatDensity: `spacious`,
format: adapter.expandFormat(adapter.formats.keyboardDate).replace(/\//g, '-'),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM - DD - YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM - DD - YYYY');
- v7Response.setProps({ value: adapter.date('2019-01-01') });
- expectFieldValueV7(v7Response.getSectionsContainer(), '01 - 01 - 2019');
+ view.setProps({ value: adapter.date('2019-01-01') });
+ expectFieldValueV7(view.getSectionsContainer(), '01 - 01 - 2019');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
formatDensity: `spacious`,
format: adapter.expandFormat(adapter.formats.keyboardDate).replace(/\//g, '-'),
enableAccessibleFieldDOMStructure: false,
@@ -250,7 +250,7 @@ describeAdapters(' - Format', DateField, ({ adapter, renderWithProp
const input = getTextbox();
expectFieldPlaceholderV6(input, 'MM - DD - YYYY');
- v6Response.setProps({ value: adapter.date('2019-01-01') });
+ view.setProps({ value: adapter.date('2019-01-01') });
expectFieldValueV6(input, '01 - 01 - 2019');
});
});
diff --git a/packages/x-date-pickers/src/DateField/tests/selection.DateField.test.tsx b/packages/x-date-pickers/src/DateField/tests/selection.DateField.test.tsx
index 4036ee7beaf68..e0b6a0114dd10 100644
--- a/packages/x-date-pickers/src/DateField/tests/selection.DateField.test.tsx
+++ b/packages/x-date-pickers/src/DateField/tests/selection.DateField.test.tsx
@@ -18,13 +18,13 @@ describe(' - Selection', () => {
describe('Focus', () => {
it('should select 1st section (v7) / all sections (v6) on mount focus (`autoFocus = true`)', () => {
// Text with v7 input
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
autoFocus: true,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Text with v6 input
renderWithProps({ enableAccessibleFieldDOMStructure: false, autoFocus: true });
@@ -35,14 +35,14 @@ describe(' - Selection', () => {
it('should select 1st section (v7) / all sections (v6) (`autoFocus = true`) with start separator', () => {
// Text with v7 input
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
autoFocus: true,
format: `- ${adapterToUse.formats.year}`,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), '- YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), '- YYYY');
expect(getCleanedSelectedContent()).to.equal('YYYY');
- v7Response.unmount();
+ view.unmount();
// Text with v6 input
renderWithProps({
@@ -109,10 +109,10 @@ describe(' - Selection', () => {
it('should select day on desktop (v6 only)', () => {
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('day');
+ view.selectSection('day');
expectFieldValueV6(input, 'MM/DD/YYYY');
expect(getCleanedSelectedContent()).to.equal('DD');
@@ -122,45 +122,45 @@ describe(' - Selection', () => {
describe('Click', () => {
it('should select the clicked selection when the input is already focused', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v7Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v6Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
});
it('should not change the selection when clicking on the only already selected section', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
- v7Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v7Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
});
});
@@ -168,40 +168,40 @@ describe(' - Selection', () => {
describe('key: Ctrl + A', () => {
it('should select all sections', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
expect(getCleanedSelectedContent()).to.equal('MM/DD/YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
expect(getCleanedSelectedContent()).to.equal('MM/DD/YYYY');
});
it('should select all sections with start separator', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: `- ${adapterToUse.formats.year}`,
});
- v7Response.selectSection('year');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ view.selectSection('year');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
expect(getCleanedSelectedContent()).to.equal('- YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: `- ${adapterToUse.formats.year}`,
});
const input = getTextbox();
- v6Response.selectSection('year');
+ view.selectSection('year');
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
expect(getCleanedSelectedContent()).to.equal('- YYYY');
});
@@ -210,17 +210,17 @@ describe(' - Selection', () => {
describe('key: ArrowRight', () => {
it('should move selection to the next section when one section is selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('day');
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
fireEvent.keyDown(input, { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
@@ -228,17 +228,17 @@ describe(' - Selection', () => {
it('should stay on the current section when the last section is selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('year');
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('year');
expect(getCleanedSelectedContent()).to.equal('YYYY');
- fireEvent.keyDown(v7Response.getActiveSection(2), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(2), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('year');
+ view.selectSection('year');
expect(getCleanedSelectedContent()).to.equal('YYYY');
fireEvent.keyDown(input, { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
@@ -246,22 +246,22 @@ describe(' - Selection', () => {
it('should select the last section when all the sections are selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('month');
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
expect(getCleanedSelectedContent()).to.equal('MM/DD/YYYY');
- fireEvent.keyDown(v7Response.getSectionsContainer(), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getSectionsContainer(), { key: 'ArrowRight' });
expect(getCleanedSelectedContent()).to.equal('YYYY');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
@@ -275,17 +275,17 @@ describe(' - Selection', () => {
describe('key: ArrowLeft', () => {
it('should move selection to the previous section when one section is selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('day');
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('day');
+ view.selectSection('day');
expect(getCleanedSelectedContent()).to.equal('DD');
fireEvent.keyDown(input, { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
@@ -293,17 +293,17 @@ describe(' - Selection', () => {
it('should stay on the current section when the first section is selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('month');
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
expect(getCleanedSelectedContent()).to.equal('MM');
fireEvent.keyDown(input, { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
@@ -311,22 +311,22 @@ describe(' - Selection', () => {
it('should select the first section when all the sections are selected', () => {
// Test with v7 input
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
- v7Response.selectSection('month');
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ view.selectSection('month');
// Select all sections
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
expect(getCleanedSelectedContent()).to.equal('MM/DD/YYYY');
- fireEvent.keyDown(v7Response.getSectionsContainer(), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getSectionsContainer(), { key: 'ArrowLeft' });
expect(getCleanedSelectedContent()).to.equal('MM');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({ enableAccessibleFieldDOMStructure: false });
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false });
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
// Select all sections
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
diff --git a/packages/x-date-pickers/src/DateTimeField/tests/editing.DateTimeField.test.tsx b/packages/x-date-pickers/src/DateTimeField/tests/editing.DateTimeField.test.tsx
index cd0885e18eef0..2abe7bd407d27 100644
--- a/packages/x-date-pickers/src/DateTimeField/tests/editing.DateTimeField.test.tsx
+++ b/packages/x-date-pickers/src/DateTimeField/tests/editing.DateTimeField.test.tsx
@@ -26,15 +26,15 @@ describe(' - Editing', () => {
const onChange = spy();
const referenceDate = adapterToUse.date('2012-05-03T14:30:00');
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
referenceDate,
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// All sections not present should equal the one from the referenceDate, and the month should equal January (because it's an ArrowUp on an empty month).
expect(onChange.lastCall.firstArg).toEqualDateTime(adapterToUse.setMonth(referenceDate, 0));
@@ -45,7 +45,7 @@ describe(' - Editing', () => {
const value = adapterToUse.date('2018-11-03T22:15:00');
const referenceDate = adapterToUse.date('2012-05-03T14:30:00');
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
referenceDate,
@@ -53,8 +53,8 @@ describe(' - Editing', () => {
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// Should equal the initial `value` prop with one less month.
expect(onChange.lastCall.firstArg).toEqualDateTime(adapterToUse.setMonth(value, 11));
@@ -65,7 +65,7 @@ describe(' - Editing', () => {
const defaultValue = adapterToUse.date('2018-11-03T22:15:00');
const referenceDate = adapterToUse.date('2012-05-03T14:30:00');
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
referenceDate,
@@ -73,8 +73,8 @@ describe(' - Editing', () => {
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// Should equal the initial `defaultValue` prop with one less month.
expect(onChange.lastCall.firstArg).toEqualDateTime(adapterToUse.setMonth(defaultValue, 11));
@@ -84,14 +84,14 @@ describe(' - Editing', () => {
it('should only keep year when granularity = month', () => {
const onChange = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
expect(onChange.lastCall.firstArg).toEqualDateTime('2012-01-01');
});
@@ -99,14 +99,14 @@ describe(' - Editing', () => {
it('should only keep year and month when granularity = day', () => {
const onChange = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
format: adapterToUse.formats.dayOfMonth,
});
- v7Response.selectSection('day');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('day');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
expect(onChange.lastCall.firstArg).toEqualDateTime('2012-05-01');
});
@@ -114,20 +114,20 @@ describe(' - Editing', () => {
it('should only keep up to the hours when granularity = minutes', () => {
const onChange = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
format: adapterToUse.formats.fullTime24h,
});
- v7Response.selectSection('hours');
+ view.selectSection('hours');
// Set hours
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// Set minutes
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowRight' });
- fireEvent.keyDown(v7Response.getActiveSection(1), { key: 'ArrowUp' });
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(1), { key: 'ArrowUp' });
expect(onChange.lastCall.firstArg).toEqualDateTime('2012-05-03T00:00:00.000Z');
});
@@ -138,15 +138,15 @@ describe(' - Editing', () => {
const onChange = spy();
const minDate = adapterToUse.date('2030-05-05T18:30:00');
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
minDate,
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// Respect the granularity and the minDate
expect(onChange.lastCall.firstArg).toEqualDateTime('2030-01-01T00:00');
@@ -156,15 +156,15 @@ describe(' - Editing', () => {
const onChange = spy();
const minDate = adapterToUse.date('2007-05-05T18:30:00');
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
minDate,
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// Respect the granularity but not the minDate
expect(onChange.lastCall.firstArg).toEqualDateTime('2012-01-01T00:00');
@@ -174,15 +174,15 @@ describe(' - Editing', () => {
const onChange = spy();
const maxDate = adapterToUse.date('2007-05-05T18:30:00');
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
maxDate,
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// Respect the granularity and the minDate
expect(onChange.lastCall.firstArg).toEqualDateTime('2007-01-01T00:00');
@@ -192,15 +192,15 @@ describe(' - Editing', () => {
const onChange = spy();
const maxDate = adapterToUse.date('2030-05-05T18:30:00');
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
maxDate,
format: adapterToUse.formats.month,
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowUp' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowUp' });
// Respect the granularity but not the maxDate
expect(onChange.lastCall.firstArg).toEqualDateTime('2012-01-01T00:00');
@@ -209,17 +209,17 @@ describe(' - Editing', () => {
});
it('should correctly update `value` when both `format` and `value` are changed', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: null,
format: 'P',
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
- v7Response.setProps({
+ view.setProps({
format: 'Pp',
value: adapterToUse.date('2012-05-03T14:30:00'),
});
- expectFieldValueV7(v7Response.getSectionsContainer(), '05/03/2012, 02:30 PM');
+ expectFieldValueV7(view.getSectionsContainer(), '05/03/2012, 02:30 PM');
});
});
diff --git a/packages/x-date-pickers/src/DateTimeField/tests/timezone.DateTimeField.test.tsx b/packages/x-date-pickers/src/DateTimeField/tests/timezone.DateTimeField.test.tsx
index 1cc3a46e79727..9ff18ca2bf5e7 100644
--- a/packages/x-date-pickers/src/DateTimeField/tests/timezone.DateTimeField.test.tsx
+++ b/packages/x-date-pickers/src/DateTimeField/tests/timezone.DateTimeField.test.tsx
@@ -46,16 +46,16 @@ describe(' - Timezone', () => {
it('should use default timezone for rendering and onChange when no value and no timezone prop are provided', () => {
const onChange = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
format,
});
- const expectedDate = fillEmptyValue(v7Response, 'default');
+ const expectedDate = fillEmptyValue(view, 'default');
// Check the rendered value (uses default timezone, e.g: UTC, see TZ env variable)
- expectFieldValueV7(v7Response.getSectionsContainer(), '12/31/2022 23');
+ expectFieldValueV7(view.getSectionsContainer(), '12/31/2022 23');
// Check the `onChange` value (uses default timezone, e.g: UTC, see TZ env variable)
const actualDate = onChange.lastCall.firstArg;
@@ -70,16 +70,16 @@ describe(' - Timezone', () => {
describe(`Timezone: ${timezone}`, () => {
it('should use timezone prop for onChange and rendering when no value is provided', () => {
const onChange = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
onChange,
format,
timezone,
});
- const expectedDate = fillEmptyValue(v7Response, timezone);
+ const expectedDate = fillEmptyValue(view, timezone);
// Check the rendered value (uses timezone prop)
- expectFieldValueV7(v7Response.getSectionsContainer(), '12/31/2022 23');
+ expectFieldValueV7(view.getSectionsContainer(), '12/31/2022 23');
// Check the `onChange` value (uses timezone prop)
const actualDate = onChange.lastCall.firstArg;
@@ -89,7 +89,7 @@ describe(' - Timezone', () => {
it('should use timezone prop for rendering and value timezone for onChange when a value is provided', () => {
const onChange = spy();
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: adapter.date(undefined, timezone),
onChange,
@@ -97,11 +97,11 @@ describe(' - Timezone', () => {
timezone: 'America/Chicago',
});
- v7Response.selectSection('month');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowDown' });
+ view.selectSection('month');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowDown' });
// Check the rendered value (uses America/Chicago timezone)
- expectFieldValueV7(v7Response.getSectionsContainer(), '05/14/2022 19');
+ expectFieldValueV7(view.getSectionsContainer(), '05/14/2022 19');
// Check the `onChange` value (uses timezone prop)
const expectedDate = adapter.addMonths(adapter.date(undefined, timezone), -1);
@@ -125,16 +125,16 @@ describe(' - Timezone', () => {
});
it('should update the field when time zone changes (timestamp remains the same)', () => {
- const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true });
+ const view = renderWithProps({ enableAccessibleFieldDOMStructure: true });
const date = adapter.date('2020-06-18T14:30:10.000Z').setZone('UTC');
- v7Response.setProps({ value: date });
+ view.setProps({ value: date });
- expectFieldValueV7(v7Response.getSectionsContainer(), '06/18/2020 02:30 PM');
+ expectFieldValueV7(view.getSectionsContainer(), '06/18/2020 02:30 PM');
- v7Response.setProps({ value: date.setZone('America/Los_Angeles') });
+ view.setProps({ value: date.setZone('America/Los_Angeles') });
- expectFieldValueV7(v7Response.getSectionsContainer(), '06/18/2020 07:30 AM');
+ expectFieldValueV7(view.getSectionsContainer(), '06/18/2020 07:30 AM');
});
});
});
diff --git a/packages/x-date-pickers/src/DesktopDatePicker/tests/DesktopDatePicker.test.tsx b/packages/x-date-pickers/src/DesktopDatePicker/tests/DesktopDatePicker.test.tsx
index b3ed68ab68516..4078e7548eb3a 100644
--- a/packages/x-date-pickers/src/DesktopDatePicker/tests/DesktopDatePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopDatePicker/tests/DesktopDatePicker.test.tsx
@@ -3,9 +3,10 @@ import { expect } from 'chai';
import { spy } from 'sinon';
import { TransitionProps } from '@mui/material/transitions';
import { inputBaseClasses } from '@mui/material/InputBase';
-import { fireEvent, screen, userEvent } from '@mui/internal-test-utils';
+import { fireEvent, screen } from '@mui/internal-test-utils';
import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
import { createPickerRenderer, adapterToUse, openPicker } from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
@@ -46,7 +47,7 @@ describe('', () => {
expect(handleViewChange.callCount).to.equal(1);
// Dismiss the picker
- userEvent.keyPress(document.activeElement!, { key: 'Escape' });
+ fireUserEvent.keyPress(document.activeElement!, { key: 'Escape' });
openPicker({ type: 'date', variant: 'desktop' });
expect(handleViewChange.callCount).to.equal(2);
@@ -71,7 +72,7 @@ describe('', () => {
expect(handleViewChange.callCount).to.equal(1);
// Dismiss the picker
- userEvent.keyPress(document.activeElement!, { key: 'Escape' });
+ fireUserEvent.keyPress(document.activeElement!, { key: 'Escape' });
openPicker({ type: 'date', variant: 'desktop' });
expect(handleViewChange.callCount).to.equal(2);
@@ -88,7 +89,7 @@ describe('', () => {
expect(screen.getByRole('radio', { checked: true, name: '2018' })).not.to.equal(null);
// Dismiss the picker
- userEvent.keyPress(document.activeElement!, { key: 'Escape' });
+ fireUserEvent.keyPress(document.activeElement!, { key: 'Escape' });
setProps({ views: ['month', 'year'] });
openPicker({ type: 'date', variant: 'desktop' });
// wait for all pending changes to be flushed
@@ -125,7 +126,7 @@ describe('', () => {
expect(screen.getByRole('radio', { checked: true, name: 'January' })).not.to.equal(null);
// Dismiss the picker
- userEvent.keyPress(document.activeElement!, { key: 'Escape' });
+ fireUserEvent.keyPress(document.activeElement!, { key: 'Escape' });
setProps({ view: 'year' });
openPicker({ type: 'date', variant: 'desktop' });
// wait for all pending changes to be flushed
@@ -220,7 +221,7 @@ describe('', () => {
render();
- userEvent.mousePress(screen.getByLabelText(/Choose date/));
+ fireUserEvent.mousePress(screen.getByLabelText(/Choose date/));
expect(onOpen.callCount).to.equal(1);
expect(screen.queryByRole('dialog')).toBeVisible();
@@ -244,14 +245,14 @@ describe('', () => {
openPicker({ type: 'date', variant: 'desktop' });
// Select year
- userEvent.mousePress(screen.getByRole('radio', { name: '2025' }));
+ fireUserEvent.mousePress(screen.getByRole('radio', { name: '2025' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2025, 0, 1));
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
// Change the date (same value)
- userEvent.mousePress(screen.getByRole('gridcell', { name: '1' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '1' }));
expect(onChange.callCount).to.equal(1); // Don't call onChange again since the value did not change
expect(onAccept.callCount).to.equal(1);
expect(onAccept.lastCall.args[0]).toEqualDateTime(new Date(2025, 0, 1));
diff --git a/packages/x-date-pickers/src/DesktopDatePicker/tests/describes.DesktopDatePicker.test.tsx b/packages/x-date-pickers/src/DesktopDatePicker/tests/describes.DesktopDatePicker.test.tsx
index 0357d40ba542d..782794ba18ebb 100644
--- a/packages/x-date-pickers/src/DesktopDatePicker/tests/describes.DesktopDatePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopDatePicker/tests/describes.DesktopDatePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -11,6 +11,7 @@ import {
} from 'test/utils/pickers';
import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -62,7 +63,7 @@ describe(' - Describes', () => {
const newValue = applySameValue ? value : adapterToUse.addDays(value, 1);
if (isOpened) {
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('gridcell', { name: adapterToUse.getDate(newValue).toString() }),
);
} else {
diff --git a/packages/x-date-pickers/src/DesktopDatePicker/tests/field.DesktopDatePicker.test.tsx b/packages/x-date-pickers/src/DesktopDatePicker/tests/field.DesktopDatePicker.test.tsx
index 808dce9bbcf9d..4ef2b7327fab4 100644
--- a/packages/x-date-pickers/src/DesktopDatePicker/tests/field.DesktopDatePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopDatePicker/tests/field.DesktopDatePicker.test.tsx
@@ -25,7 +25,7 @@ describe(' - Field', () => {
it('should be able to reset a single section', () => {
// Test with v7 input
- const v7Response = renderWithProps(
+ let view = renderWithProps(
{
enableAccessibleFieldDOMStructure: true as const,
format: `${adapterToUse.formats.month} ${adapterToUse.formats.dayOfMonth}`,
@@ -33,22 +33,22 @@ describe(' - Field', () => {
{ componentFamily: 'picker' },
);
- v7Response.selectSection('month');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM DD');
+ view.selectSection('month');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM DD');
- v7Response.pressKey(0, 'N');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'November DD');
+ view.pressKey(0, 'N');
+ expectFieldValueV7(view.getSectionsContainer(), 'November DD');
- v7Response.pressKey(1, '4');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'November 04');
+ view.pressKey(1, '4');
+ expectFieldValueV7(view.getSectionsContainer(), 'November 04');
- v7Response.pressKey(1, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'November DD');
+ view.pressKey(1, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'November DD');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
+ view = renderWithProps(
{
enableAccessibleFieldDOMStructure: false as const,
format: `${adapterToUse.formats.month} ${adapterToUse.formats.dayOfMonth}`,
@@ -57,7 +57,7 @@ describe(' - Field', () => {
);
const input = getTextbox();
- v6Response.selectSection('month');
+ view.selectSection('month');
expectFieldPlaceholderV6(input, 'MMMM DD');
fireEvent.change(input, { target: { value: 'N DD' } }); // Press "N"
@@ -73,21 +73,21 @@ describe(' - Field', () => {
it('should adapt the default field format based on the props of the picker', () => {
const testFormat = (props: DesktopDatePickerProps, expectedFormat: string) => {
// Test with v7 input
- const v7Response = renderWithProps(
+ let view = renderWithProps(
{ ...props, enableAccessibleFieldDOMStructure: true as const },
{ componentFamily: 'picker' },
);
- expectFieldValueV7(v7Response.getSectionsContainer(), expectedFormat);
- v7Response.unmount();
+ expectFieldValueV7(view.getSectionsContainer(), expectedFormat);
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
+ view = renderWithProps(
{ ...props, enableAccessibleFieldDOMStructure: false as const },
{ componentFamily: 'picker' },
);
const input = getTextbox();
expectFieldPlaceholderV6(input, expectedFormat);
- v6Response.unmount();
+ view.unmount();
};
testFormat({ views: ['year'] }, 'YYYY');
@@ -171,7 +171,7 @@ describe(' - Field', () => {
describeAdapters('Timezone', DesktopDatePicker, ({ adapter, renderWithProps }) => {
it('should clear the selected section when all sections are completed when using timezones', () => {
- const v7Response = renderWithProps(
+ const view = renderWithProps(
{
enableAccessibleFieldDOMStructure: true as const,
value: adapter.date()!,
@@ -181,11 +181,11 @@ describe(' - Field', () => {
{ componentFamily: 'picker' },
);
- expectFieldValueV7(v7Response.getSectionsContainer(), 'June 2022');
- v7Response.selectSection('month');
+ expectFieldValueV7(view.getSectionsContainer(), 'June 2022');
+ view.selectSection('month');
- v7Response.pressKey(0, '');
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MMMM 2022');
+ view.pressKey(0, '');
+ expectFieldValueV7(view.getSectionsContainer(), 'MMMM 2022');
});
});
});
diff --git a/packages/x-date-pickers/src/DesktopDateTimePicker/tests/DesktopDateTimePicker.test.tsx b/packages/x-date-pickers/src/DesktopDateTimePicker/tests/DesktopDateTimePicker.test.tsx
index ade01ebb4a700..fbaa727814752 100644
--- a/packages/x-date-pickers/src/DesktopDateTimePicker/tests/DesktopDateTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopDateTimePicker/tests/DesktopDateTimePicker.test.tsx
@@ -1,9 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import { DesktopDateTimePicker } from '@mui/x-date-pickers/DesktopDateTimePicker';
import { adapterToUse, createPickerRenderer, openPicker } from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe('', () => {
const { render } = createPickerRenderer({
@@ -17,7 +18,7 @@ describe('', () => {
render();
- userEvent.mousePress(screen.getByLabelText(/Choose date/));
+ fireUserEvent.mousePress(screen.getByLabelText(/Choose date/));
expect(onOpen.callCount).to.equal(1);
expect(screen.queryByRole('dialog')).toBeVisible();
@@ -41,23 +42,23 @@ describe('', () => {
openPicker({ type: 'date-time', variant: 'desktop' });
// Select year
- userEvent.mousePress(screen.getByRole('radio', { name: '2025' }));
+ fireUserEvent.mousePress(screen.getByRole('radio', { name: '2025' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2025, 0, 1, 11, 55));
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
// Change the date (same value)
- userEvent.mousePress(screen.getByRole('gridcell', { name: '1' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '1' }));
expect(onChange.callCount).to.equal(1); // Don't call onChange again since the value did not change
// Change the hours (same value)
- userEvent.mousePress(screen.getByRole('option', { name: '11 hours' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '11 hours' }));
expect(onChange.callCount).to.equal(1); // Don't call onChange again since the value did not change
// Change the minutes (same value)
- userEvent.mousePress(screen.getByRole('option', { name: '55 minutes' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '55 minutes' }));
expect(onChange.callCount).to.equal(1); // Don't call onChange again since the value did not change
// Change the meridiem (same value)
- userEvent.mousePress(screen.getByRole('option', { name: 'AM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: 'AM' }));
expect(onChange.callCount).to.equal(1); // Don't call onChange again since the value did not change
expect(onAccept.callCount).to.equal(1);
expect(onClose.callCount).to.equal(1);
@@ -81,26 +82,26 @@ describe('', () => {
openPicker({ type: 'date-time', variant: 'desktop' });
// Change the date multiple times to check that picker doesn't close after cycling through all views internally
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
- userEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
- userEvent.mousePress(screen.getByRole('gridcell', { name: '4' }));
- userEvent.mousePress(screen.getByRole('gridcell', { name: '5' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '3' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '4' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '5' }));
expect(onChange.callCount).to.equal(4);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
// Change the hours
- userEvent.mousePress(screen.getByRole('option', { name: '10 hours' }));
- userEvent.mousePress(screen.getByRole('option', { name: '9 hours' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '10 hours' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '9 hours' }));
expect(onChange.callCount).to.equal(6);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
// Change the minutes
- userEvent.mousePress(screen.getByRole('option', { name: '50 minutes' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '50 minutes' }));
expect(onChange.callCount).to.equal(7);
// Change the meridiem
- userEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
expect(onChange.callCount).to.equal(8);
expect(onAccept.callCount).to.equal(1);
expect(onClose.callCount).to.equal(1);
@@ -118,10 +119,10 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByLabelText(/Choose date/));
+ fireUserEvent.mousePress(screen.getByLabelText(/Choose date/));
- userEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
- userEvent.mousePress(screen.getByRole('option', { name: '03:00 AM' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '2' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '03:00 AM' }));
expect(onChange.callCount).to.equal(2);
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2018, 0, 2, 3, 0, 0));
@@ -139,9 +140,9 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByLabelText(/Choose date/));
+ fireUserEvent.mousePress(screen.getByLabelText(/Choose date/));
- userEvent.mousePress(screen.getByRole('option', { name: '03:00 AM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '03:00 AM' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2018, 0, 1, 3, 0, 0));
diff --git a/packages/x-date-pickers/src/DesktopDateTimePicker/tests/describes.DesktopDateTimePicker.test.tsx b/packages/x-date-pickers/src/DesktopDateTimePicker/tests/describes.DesktopDateTimePicker.test.tsx
index 04ba5bf600064..dc66bec63c589 100644
--- a/packages/x-date-pickers/src/DesktopDateTimePicker/tests/describes.DesktopDateTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopDateTimePicker/tests/describes.DesktopDateTimePicker.test.tsx
@@ -1,4 +1,4 @@
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -12,6 +12,7 @@ import { DesktopDateTimePicker } from '@mui/x-date-pickers/DesktopDateTimePicker
import { expect } from 'chai';
import * as React from 'react';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -84,20 +85,22 @@ describe(' - Describes', () => {
: adapterToUse.addMinutes(adapterToUse.addHours(adapterToUse.addDays(value, 1), 1), 5);
if (isOpened) {
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('gridcell', { name: adapterToUse.getDate(newValue).toString() }),
);
const hasMeridiem = adapterToUse.is12HourCycleInCurrentLocale();
const hours = adapterToUse.format(newValue, hasMeridiem ? 'hours12h' : 'hours24h');
const hoursNumber = adapterToUse.getHours(newValue);
- userEvent.mousePress(screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }));
- userEvent.mousePress(
+ fireUserEvent.mousePress(
+ screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }),
+ );
+ fireUserEvent.mousePress(
screen.getByRole('option', { name: `${adapterToUse.getMinutes(newValue)} minutes` }),
);
if (hasMeridiem) {
// meridiem is an extra view on `DesktopDateTimePicker`
// we need to click it to finish selection
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('option', { name: hoursNumber >= 12 ? 'PM' : 'AM' }),
);
}
diff --git a/packages/x-date-pickers/src/DesktopDateTimePicker/tests/field.DesktopDateTimePicker.test.tsx b/packages/x-date-pickers/src/DesktopDateTimePicker/tests/field.DesktopDateTimePicker.test.tsx
index 3a951470e5f32..54877db6fa120 100644
--- a/packages/x-date-pickers/src/DesktopDateTimePicker/tests/field.DesktopDateTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopDateTimePicker/tests/field.DesktopDateTimePicker.test.tsx
@@ -19,35 +19,35 @@ describe(' - Field', () => {
});
it('should pass the ampm prop to the field', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true as const,
ampm: true,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY hh:mm aa');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY hh:mm aa');
- v7Response.setProps({ ampm: false });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY hh:mm');
+ view.setProps({ ampm: false });
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY hh:mm');
});
it('should adapt the default field format based on the props of the picker', () => {
const testFormat = (props: DesktopDateTimePickerProps, expectedFormat: string) => {
// Test with v7 input
- const v7Response = renderWithProps(
+ let view = renderWithProps(
{ ...props, enableAccessibleFieldDOMStructure: true as const },
{ componentFamily: 'picker' },
);
- expectFieldValueV7(v7Response.getSectionsContainer(), expectedFormat);
- v7Response.unmount();
+ expectFieldValueV7(view.getSectionsContainer(), expectedFormat);
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
+ view = renderWithProps(
{ ...props, enableAccessibleFieldDOMStructure: false as const },
{ componentFamily: 'picker' },
);
const input = getTextbox();
expectFieldPlaceholderV6(input, expectedFormat);
- v6Response.unmount();
+ view.unmount();
};
testFormat({ views: ['day', 'hours', 'minutes'], ampm: false }, 'DD hh:mm');
diff --git a/packages/x-date-pickers/src/DesktopTimePicker/tests/DesktopTimePicker.test.tsx b/packages/x-date-pickers/src/DesktopTimePicker/tests/DesktopTimePicker.test.tsx
index b520cad777277..b60fa37d20fb8 100644
--- a/packages/x-date-pickers/src/DesktopTimePicker/tests/DesktopTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopTimePicker/tests/DesktopTimePicker.test.tsx
@@ -1,9 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import { DesktopTimePicker } from '@mui/x-date-pickers/DesktopTimePicker';
import { createPickerRenderer, openPicker } from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe('', () => {
const { render } = createPickerRenderer({
@@ -76,7 +77,7 @@ describe('', () => {
openPicker({ type: 'time', variant: 'desktop' });
- userEvent.mousePress(screen.getByRole('option', { name: '09:00 AM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '09:00 AM' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2018, 0, 1, 9, 0));
expect(onAccept.callCount).to.equal(1);
@@ -93,17 +94,17 @@ describe('', () => {
openPicker({ type: 'time', variant: 'desktop' });
- userEvent.mousePress(screen.getByRole('option', { name: '2 hours' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '2 hours' }));
expect(onChange.callCount).to.equal(1);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
- userEvent.mousePress(screen.getByRole('option', { name: '15 minutes' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '15 minutes' }));
expect(onChange.callCount).to.equal(2);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
- userEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
expect(onChange.callCount).to.equal(3);
expect(onAccept.callCount).to.equal(1);
expect(onAccept.lastCall.args[0]).toEqualDateTime(new Date(2018, 0, 1, 14, 15));
@@ -119,22 +120,22 @@ describe('', () => {
openPicker({ type: 'time', variant: 'desktop' });
- userEvent.mousePress(screen.getByRole('option', { name: '15 minutes' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '15 minutes' }));
expect(onChange.callCount).to.equal(1);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
- userEvent.mousePress(screen.getByRole('option', { name: '2 hours' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '2 hours' }));
expect(onChange.callCount).to.equal(2);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
- userEvent.mousePress(screen.getByRole('option', { name: '25 minutes' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '25 minutes' }));
expect(onChange.callCount).to.equal(3);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
- userEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
expect(onChange.callCount).to.equal(4);
expect(onAccept.callCount).to.equal(1);
expect(onAccept.lastCall.args[0]).toEqualDateTime(new Date(2018, 0, 1, 14, 25));
@@ -150,7 +151,7 @@ describe('', () => {
openPicker({ type: 'time', variant: 'desktop' });
- userEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: 'PM' }));
expect(onChange.callCount).to.equal(1);
expect(onAccept.callCount).to.equal(1);
expect(onAccept.lastCall.args[0]).toEqualDateTime(new Date(2018, 0, 1, 12, 0));
diff --git a/packages/x-date-pickers/src/DesktopTimePicker/tests/describes.DesktopTimePicker.test.tsx b/packages/x-date-pickers/src/DesktopTimePicker/tests/describes.DesktopTimePicker.test.tsx
index 3b6e6eb288681..2fe4730f6fd18 100644
--- a/packages/x-date-pickers/src/DesktopTimePicker/tests/describes.DesktopTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopTimePicker/tests/describes.DesktopTimePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -12,6 +12,7 @@ import {
} from 'test/utils/pickers';
import { DesktopTimePicker } from '@mui/x-date-pickers/DesktopTimePicker';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -76,14 +77,16 @@ describe(' - Describes', () => {
const hasMeridiem = adapterToUse.is12HourCycleInCurrentLocale();
const hours = adapterToUse.format(newValue, hasMeridiem ? 'hours12h' : 'hours24h');
const hoursNumber = adapterToUse.getHours(newValue);
- userEvent.mousePress(screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }));
- userEvent.mousePress(
+ fireUserEvent.mousePress(
+ screen.getByRole('option', { name: `${parseInt(hours, 10)} hours` }),
+ );
+ fireUserEvent.mousePress(
screen.getByRole('option', { name: `${adapterToUse.getMinutes(newValue)} minutes` }),
);
if (hasMeridiem) {
// meridiem is an extra view on `DesktopTimePicker`
// we need to click it to finish selection
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('option', { name: hoursNumber >= 12 ? 'PM' : 'AM' }),
);
}
diff --git a/packages/x-date-pickers/src/DesktopTimePicker/tests/field.DesktopTimePicker.test.tsx b/packages/x-date-pickers/src/DesktopTimePicker/tests/field.DesktopTimePicker.test.tsx
index 10d1848a5fe3c..88c95f9815039 100644
--- a/packages/x-date-pickers/src/DesktopTimePicker/tests/field.DesktopTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/DesktopTimePicker/tests/field.DesktopTimePicker.test.tsx
@@ -16,35 +16,35 @@ describe(' - Field', () => {
});
it('should pass the ampm prop to the field', () => {
- const v7Response = renderWithProps(
+ const view = renderWithProps(
{ enableAccessibleFieldDOMStructure: true as const, ampm: true },
{ componentFamily: 'picker' },
);
- expectFieldValueV7(v7Response.getSectionsContainer(), 'hh:mm aa');
+ expectFieldValueV7(view.getSectionsContainer(), 'hh:mm aa');
- v7Response.setProps({ ampm: false });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'hh:mm');
+ view.setProps({ ampm: false });
+ expectFieldValueV7(view.getSectionsContainer(), 'hh:mm');
});
it('should adapt the default field format based on the props of the picker', () => {
const testFormat = (props: DesktopTimePickerProps, expectedFormat: string) => {
// Test with v7 input
- const v7Response = renderWithProps(
+ let view = renderWithProps(
{ ...props, enableAccessibleFieldDOMStructure: true as const },
{ componentFamily: 'picker' },
);
- expectFieldValueV7(v7Response.getSectionsContainer(), expectedFormat);
- v7Response.unmount();
+ expectFieldValueV7(view.getSectionsContainer(), expectedFormat);
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
+ view = renderWithProps(
{ ...props, enableAccessibleFieldDOMStructure: false as const },
{ componentFamily: 'picker' },
);
const input = getTextbox();
expectFieldPlaceholderV6(input, expectedFormat);
- v6Response.unmount();
+ view.unmount();
};
testFormat({ views: ['hours'], ampm: false }, 'hh');
diff --git a/packages/x-date-pickers/src/DigitalClock/tests/DigitalClock.test.tsx b/packages/x-date-pickers/src/DigitalClock/tests/DigitalClock.test.tsx
index 4f6617cc90c67..96fb9bd96fa67 100644
--- a/packages/x-date-pickers/src/DigitalClock/tests/DigitalClock.test.tsx
+++ b/packages/x-date-pickers/src/DigitalClock/tests/DigitalClock.test.tsx
@@ -93,16 +93,15 @@ describe('', () => {
});
it('forwards list class to MenuList', () => {
- const { getByRole } = render();
+ render();
- const list = getByRole('listbox');
- expect(list).to.have.class('foo');
+ expect(screen.getByRole('listbox')).to.have.class('foo');
});
it('forwards item class to clock item', () => {
- const { getAllByRole } = render();
+ render();
- const options = getAllByRole('option');
+ const options = screen.getAllByRole('option');
expect(options[0]).to.have.class('bar');
});
});
diff --git a/packages/x-date-pickers/src/DigitalClock/tests/timezone.DigitalClock.test.tsx b/packages/x-date-pickers/src/DigitalClock/tests/timezone.DigitalClock.test.tsx
index 9dc25d08aef52..070c9b9243f52 100644
--- a/packages/x-date-pickers/src/DigitalClock/tests/timezone.DigitalClock.test.tsx
+++ b/packages/x-date-pickers/src/DigitalClock/tests/timezone.DigitalClock.test.tsx
@@ -1,9 +1,10 @@
import * as React from 'react';
import { spy } from 'sinon';
import { expect } from 'chai';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import { DigitalClock } from '@mui/x-date-pickers/DigitalClock';
import { getDateOffset, describeAdapters } from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
const TIMEZONE_TO_TEST = ['UTC', 'system', 'America/New_York'];
@@ -25,7 +26,7 @@ describe(' - Timezone', () => {
const onChange = spy();
render();
- userEvent.mousePress(screen.getByRole('option', { name: '08:00 AM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '08:00 AM' }));
const expectedDate = adapter.setHours(adapter.date(), 8);
@@ -44,7 +45,7 @@ describe(' - Timezone', () => {
const onChange = spy();
render();
- userEvent.mousePress(screen.getByRole('option', { name: '08:00 AM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '08:00 AM' }));
const expectedDate = adapter.setHours(
adapter.startOfDay(adapter.date(undefined, timezone)),
@@ -75,7 +76,7 @@ describe(' - Timezone', () => {
(adapter.getHours(value) + offsetDiff / 60 + 24) % 24,
);
- userEvent.mousePress(screen.getByRole('option', { name: '08:30 PM' }));
+ fireUserEvent.mousePress(screen.getByRole('option', { name: '08:30 PM' }));
const actualDate = onChange.lastCall.firstArg;
diff --git a/packages/x-date-pickers/src/MobileDatePicker/tests/MobileDatePicker.test.tsx b/packages/x-date-pickers/src/MobileDatePicker/tests/MobileDatePicker.test.tsx
index 1095449d3312e..3dc67b8065386 100644
--- a/packages/x-date-pickers/src/MobileDatePicker/tests/MobileDatePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileDatePicker/tests/MobileDatePicker.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { fireEvent, screen, userEvent } from '@mui/internal-test-utils';
+import { fireEvent, screen } from '@mui/internal-test-utils';
import { PickersDay } from '@mui/x-date-pickers/PickersDay';
import { DayCalendarSkeleton } from '@mui/x-date-pickers/DayCalendarSkeleton';
import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker';
@@ -13,6 +13,7 @@ import {
openPicker,
getFieldSectionsContainer,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe('', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -155,7 +156,7 @@ describe('', () => {
render();
- userEvent.mousePress(getFieldSectionsContainer());
+ fireUserEvent.mousePress(getFieldSectionsContainer());
expect(onOpen.callCount).to.equal(1);
expect(screen.queryByRole('dialog')).toBeVisible();
@@ -188,17 +189,17 @@ describe('', () => {
});
it('should update internal state when controlled value is updated', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true as const,
value: adapterToUse.date('2019-01-01'),
});
// Set a date
- expectFieldValueV7(v7Response.getSectionsContainer(), '01/01/2019');
+ expectFieldValueV7(view.getSectionsContainer(), '01/01/2019');
// Clean value using external control
- v7Response.setProps({ value: null });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ view.setProps({ value: null });
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
// Open and Dismiss the picker
openPicker({ type: 'date', variant: 'mobile' });
@@ -207,7 +208,7 @@ describe('', () => {
clock.runToLast();
// Verify it's still a clean value
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY');
});
});
});
diff --git a/packages/x-date-pickers/src/MobileDatePicker/tests/describes.MobileDatePicker.test.tsx b/packages/x-date-pickers/src/MobileDatePicker/tests/describes.MobileDatePicker.test.tsx
index 5dfe64dc6e899..b988c49e5827e 100644
--- a/packages/x-date-pickers/src/MobileDatePicker/tests/describes.MobileDatePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileDatePicker/tests/describes.MobileDatePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { screen, userEvent, fireEvent } from '@mui/internal-test-utils';
+import { screen, fireEvent } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -12,6 +12,7 @@ import {
} from 'test/utils/pickers';
import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -64,7 +65,7 @@ describe(' - Describes', () => {
}
const newValue = applySameValue ? value : adapterToUse.addDays(value, 1);
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('gridcell', { name: adapterToUse.getDate(newValue).toString() }),
);
diff --git a/packages/x-date-pickers/src/MobileDateTimePicker/tests/MobileDateTimePicker.test.tsx b/packages/x-date-pickers/src/MobileDateTimePicker/tests/MobileDateTimePicker.test.tsx
index ad9c3641efbbd..34849b1b5dc0b 100644
--- a/packages/x-date-pickers/src/MobileDateTimePicker/tests/MobileDateTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileDateTimePicker/tests/MobileDateTimePicker.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { fireTouchChangedEvent, screen, userEvent } from '@mui/internal-test-utils';
+import { fireTouchChangedEvent, screen } from '@mui/internal-test-utils';
import { MobileDateTimePicker } from '@mui/x-date-pickers/MobileDateTimePicker';
import {
adapterToUse,
@@ -10,6 +10,7 @@ import {
getClockTouchEvent,
getFieldSectionsContainer,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe('', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -98,7 +99,7 @@ describe('', () => {
render();
- userEvent.mousePress(getFieldSectionsContainer());
+ fireUserEvent.mousePress(getFieldSectionsContainer());
expect(onOpen.callCount).to.equal(1);
expect(screen.queryByRole('dialog')).toBeVisible();
@@ -131,8 +132,8 @@ describe('', () => {
expect(onClose.callCount).to.equal(0);
// Change the year view
- userEvent.mousePress(screen.getByLabelText(/switch to year view/));
- userEvent.mousePress(screen.getByText('2010', { selector: 'button' }));
+ fireUserEvent.mousePress(screen.getByLabelText(/switch to year view/));
+ fireUserEvent.mousePress(screen.getByText('2010', { selector: 'button' }));
expect(onChange.callCount).to.equal(1);
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2010, 0, 1));
@@ -140,7 +141,7 @@ describe('', () => {
clock.runToLast();
// Change the date
- userEvent.mousePress(screen.getByRole('gridcell', { name: '15' }));
+ fireUserEvent.mousePress(screen.getByRole('gridcell', { name: '15' }));
expect(onChange.callCount).to.equal(2);
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2010, 0, 15));
diff --git a/packages/x-date-pickers/src/MobileDateTimePicker/tests/describes.MobileDateTimePicker.test.tsx b/packages/x-date-pickers/src/MobileDateTimePicker/tests/describes.MobileDateTimePicker.test.tsx
index 4d1d819ad7734..7db743bb1c2ea 100644
--- a/packages/x-date-pickers/src/MobileDateTimePicker/tests/describes.MobileDateTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileDateTimePicker/tests/describes.MobileDateTimePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { screen, userEvent, fireEvent, fireTouchChangedEvent } from '@mui/internal-test-utils';
+import { screen, fireEvent, fireTouchChangedEvent } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -13,6 +13,7 @@ import {
} from 'test/utils/pickers';
import { MobileDateTimePicker } from '@mui/x-date-pickers/MobileDateTimePicker';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({
@@ -78,7 +79,7 @@ describe(' - Describes', () => {
const newValue = applySameValue
? value
: adapterToUse.addMinutes(adapterToUse.addHours(adapterToUse.addDays(value, 1), 1), 5);
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('gridcell', { name: adapterToUse.getDate(newValue).toString() }),
);
const hasMeridiem = adapterToUse.is12HourCycleInCurrentLocale();
@@ -97,7 +98,9 @@ describe(' - Describes', () => {
if (hasMeridiem) {
const newHours = adapterToUse.getHours(newValue);
// select appropriate meridiem
- userEvent.mousePress(screen.getByRole('button', { name: newHours >= 12 ? 'PM' : 'AM' }));
+ fireUserEvent.mousePress(
+ screen.getByRole('button', { name: newHours >= 12 ? 'PM' : 'AM' }),
+ );
}
// Close the picker
@@ -107,7 +110,7 @@ describe(' - Describes', () => {
clock.runToLast();
} else {
// return to the date view in case we'd like to repeat the selection process
- userEvent.mousePress(screen.getByRole('tab', { name: 'pick date' }));
+ fireUserEvent.mousePress(screen.getByRole('tab', { name: 'pick date' }));
}
return newValue;
diff --git a/packages/x-date-pickers/src/MobileDateTimePicker/tests/field.MobileDateTimePicker.test.tsx b/packages/x-date-pickers/src/MobileDateTimePicker/tests/field.MobileDateTimePicker.test.tsx
index 2a8aae0ea83ce..413a025f20021 100644
--- a/packages/x-date-pickers/src/MobileDateTimePicker/tests/field.MobileDateTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileDateTimePicker/tests/field.MobileDateTimePicker.test.tsx
@@ -14,14 +14,14 @@ describe(' - Field', () => {
});
it('should pass the ampm prop to the field', () => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true as const,
ampm: true,
});
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY hh:mm aa');
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY hh:mm aa');
- v7Response.setProps({ ampm: false });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'MM/DD/YYYY hh:mm');
+ view.setProps({ ampm: false });
+ expectFieldValueV7(view.getSectionsContainer(), 'MM/DD/YYYY hh:mm');
});
});
diff --git a/packages/x-date-pickers/src/MobileTimePicker/tests/MobileTimePicker.test.tsx b/packages/x-date-pickers/src/MobileTimePicker/tests/MobileTimePicker.test.tsx
index 5bf9dade08f81..16e28b5b3c295 100644
--- a/packages/x-date-pickers/src/MobileTimePicker/tests/MobileTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileTimePicker/tests/MobileTimePicker.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { spy } from 'sinon';
import { expect } from 'chai';
-import { fireTouchChangedEvent, screen, userEvent, act } from '@mui/internal-test-utils';
+import { fireTouchChangedEvent, screen, act } from '@mui/internal-test-utils';
import { MobileTimePicker } from '@mui/x-date-pickers/MobileTimePicker';
import {
createPickerRenderer,
@@ -10,6 +10,7 @@ import {
getClockTouchEvent,
getFieldSectionsContainer,
} from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe('', () => {
const { render } = createPickerRenderer({ clock: 'fake' });
@@ -20,7 +21,7 @@ describe('', () => {
render();
- userEvent.mousePress(getFieldSectionsContainer());
+ fireUserEvent.mousePress(getFieldSectionsContainer());
expect(onOpen.callCount).to.equal(1);
expect(screen.queryByRole('dialog')).toBeVisible();
diff --git a/packages/x-date-pickers/src/MobileTimePicker/tests/describes.MobileTimePicker.test.tsx b/packages/x-date-pickers/src/MobileTimePicker/tests/describes.MobileTimePicker.test.tsx
index 79b4c2029072e..8a694129a7840 100644
--- a/packages/x-date-pickers/src/MobileTimePicker/tests/describes.MobileTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileTimePicker/tests/describes.MobileTimePicker.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { screen, fireEvent, userEvent, fireTouchChangedEvent } from '@mui/internal-test-utils';
+import { screen, fireEvent, fireTouchChangedEvent } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -14,6 +14,7 @@ import {
} from 'test/utils/pickers';
import { MobileTimePicker } from '@mui/x-date-pickers/MobileTimePicker';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({
@@ -92,7 +93,9 @@ describe(' - Describes', () => {
if (hasMeridiem) {
const newHours = adapterToUse.getHours(newValue);
// select appropriate meridiem
- userEvent.mousePress(screen.getByRole('button', { name: newHours >= 12 ? 'PM' : 'AM' }));
+ fireUserEvent.mousePress(
+ screen.getByRole('button', { name: newHours >= 12 ? 'PM' : 'AM' }),
+ );
}
// Close the picker
@@ -102,7 +105,7 @@ describe(' - Describes', () => {
clock.runToLast();
} else {
// return to the hours view in case we'd like to repeat the selection process
- userEvent.mousePress(screen.getByRole('button', { name: 'Open previous view' }));
+ fireUserEvent.mousePress(screen.getByRole('button', { name: 'Open previous view' }));
}
return newValue;
diff --git a/packages/x-date-pickers/src/MobileTimePicker/tests/field.MobileTimePicker.test.tsx b/packages/x-date-pickers/src/MobileTimePicker/tests/field.MobileTimePicker.test.tsx
index 206189acc74a2..befd200997643 100644
--- a/packages/x-date-pickers/src/MobileTimePicker/tests/field.MobileTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/MobileTimePicker/tests/field.MobileTimePicker.test.tsx
@@ -14,14 +14,14 @@ describe(' - Field', () => {
});
it('should pass the ampm prop to the field', () => {
- const v7Response = renderWithProps(
+ const view = renderWithProps(
{ enableAccessibleFieldDOMStructure: true as const, ampm: true },
{ componentFamily: 'picker' },
);
- expectFieldValueV7(v7Response.getSectionsContainer(), 'hh:mm aa');
+ expectFieldValueV7(view.getSectionsContainer(), 'hh:mm aa');
- v7Response.setProps({ ampm: false });
- expectFieldValueV7(v7Response.getSectionsContainer(), 'hh:mm');
+ view.setProps({ ampm: false });
+ expectFieldValueV7(view.getSectionsContainer(), 'hh:mm');
});
});
diff --git a/packages/x-date-pickers/src/MonthCalendar/tests/describes.MonthCalendar.test.tsx b/packages/x-date-pickers/src/MonthCalendar/tests/describes.MonthCalendar.test.tsx
index f439b851f2c34..ef370265decd6 100644
--- a/packages/x-date-pickers/src/MonthCalendar/tests/describes.MonthCalendar.test.tsx
+++ b/packages/x-date-pickers/src/MonthCalendar/tests/describes.MonthCalendar.test.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
-import { userEvent, screen } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import {
createPickerRenderer,
adapterToUse,
@@ -9,6 +9,7 @@ import {
} from 'test/utils/pickers';
import { MonthCalendar, monthCalendarClasses as classes } from '@mui/x-date-pickers/MonthCalendar';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({ clock: 'fake' });
@@ -54,7 +55,7 @@ describe(' - Describes', () => {
setNewValue: (value) => {
const newValue = adapterToUse.addMonths(value, 1);
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('radio', { name: adapterToUse.format(newValue, 'month') }),
);
diff --git a/packages/x-date-pickers/src/PickersActionBar/PickersActionBar.test.tsx b/packages/x-date-pickers/src/PickersActionBar/PickersActionBar.test.tsx
index c4837e507ce74..465baad26ceef 100644
--- a/packages/x-date-pickers/src/PickersActionBar/PickersActionBar.test.tsx
+++ b/packages/x-date-pickers/src/PickersActionBar/PickersActionBar.test.tsx
@@ -1,9 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { screen, userEvent } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import { PickersActionBar } from '@mui/x-date-pickers/PickersActionBar';
import { createPickerRenderer } from 'test/utils/pickers';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe('', () => {
const { render } = createPickerRenderer({
@@ -44,7 +45,7 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByText(/clear/i));
+ fireUserEvent.mousePress(screen.getByText(/clear/i));
expect(onClear.callCount).to.equal(1);
});
@@ -64,7 +65,7 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByText(/cancel/i));
+ fireUserEvent.mousePress(screen.getByText(/cancel/i));
expect(onCancel.callCount).to.equal(1);
});
@@ -84,7 +85,7 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByText(/ok/i));
+ fireUserEvent.mousePress(screen.getByText(/ok/i));
expect(onAccept.callCount).to.equal(1);
});
@@ -104,7 +105,7 @@ describe('', () => {
/>,
);
- userEvent.mousePress(screen.getByText(/today/i));
+ fireUserEvent.mousePress(screen.getByText(/today/i));
expect(onSetToday.callCount).to.equal(1);
});
diff --git a/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.test.tsx b/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.test.tsx
index 8e2e37371b5db..f5a04623b4af4 100644
--- a/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.test.tsx
+++ b/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { fireTouchChangedEvent, screen, getAllByRole, fireEvent } from '@mui/internal-test-utils';
+import { fireTouchChangedEvent, screen, within, fireEvent } from '@mui/internal-test-utils';
import { adapterToUse, createPickerRenderer, describeValidation } from 'test/utils/pickers';
import { StaticTimePicker } from '@mui/x-date-pickers/StaticTimePicker';
import { describeConformance } from 'test/utils/describeConformance';
@@ -78,7 +78,7 @@ describe('', () => {
// hours are not disabled
const hoursContainer = screen.getByRole('listbox');
- const hours = getAllByRole(hoursContainer, 'option');
+ const hours = within(hoursContainer).getAllByRole('option');
const disabledHours = hours.filter((day) => day.getAttribute('aria-disabled') === 'true');
expect(hours.length).to.equal(12);
@@ -128,7 +128,7 @@ describe('', () => {
// hours are disabled
const hoursContainer = screen.getByRole('listbox');
- const hours = getAllByRole(hoursContainer, 'option');
+ const hours = within(hoursContainer).getAllByRole('option');
const disabledHours = hours.filter((hour) => hour.getAttribute('aria-disabled') === 'true');
expect(hours.length).to.equal(12);
expect(disabledHours.length).to.equal(12);
diff --git a/packages/x-date-pickers/src/TimeClock/tests/TimeClock.test.tsx b/packages/x-date-pickers/src/TimeClock/tests/TimeClock.test.tsx
index 36bfb4c6597ba..5ecc40f8b19cb 100644
--- a/packages/x-date-pickers/src/TimeClock/tests/TimeClock.test.tsx
+++ b/packages/x-date-pickers/src/TimeClock/tests/TimeClock.test.tsx
@@ -1,13 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import {
- fireEvent,
- fireTouchChangedEvent,
- screen,
- within,
- getAllByRole,
-} from '@mui/internal-test-utils';
+import { fireEvent, fireTouchChangedEvent, screen, within } from '@mui/internal-test-utils';
import { TimeClock } from '@mui/x-date-pickers/TimeClock';
import { createPickerRenderer, adapterToUse, timeClockHandler } from 'test/utils/pickers';
@@ -166,7 +160,7 @@ describe('', () => {
// hours are not disabled
const hoursContainer = screen.getByRole('listbox');
- const hours = getAllByRole(hoursContainer, 'option');
+ const hours = within(hoursContainer).getAllByRole('option');
const disabledHours = hours.filter((hour) => hour.getAttribute('aria-disabled') === 'true');
expect(hours.length).to.equal(12);
@@ -194,7 +188,7 @@ describe('', () => {
// hours are disabled
const hoursContainer = screen.getByRole('listbox');
- const hours = getAllByRole(hoursContainer, 'option');
+ const hours = within(hoursContainer).getAllByRole('option');
const disabledHours = hours.filter((hour) => hour.getAttribute('aria-disabled') === 'true');
expect(hours.length).to.equal(12);
diff --git a/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx b/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx
index d9736f41ad511..9ddc968fd0609 100644
--- a/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx
+++ b/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx
@@ -497,27 +497,27 @@ describe(' - Editing', () => {
it('should go to the next section when pressing `2` in a 12-hours format', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: adapter.formats.fullTime12h,
});
- v7Response.selectSection('hours');
+ view.selectSection('hours');
- v7Response.pressKey(0, '2');
- expectFieldValueV7(v7Response.getSectionsContainer(), '02:mm aa');
+ view.pressKey(0, '2');
+ expectFieldValueV7(view.getSectionsContainer(), '02:mm aa');
expect(getCleanedSelectedContent()).to.equal('mm');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: adapter.formats.fullTime12h,
});
const input = getTextbox();
- v6Response.selectSection('hours');
+ view.selectSection('hours');
// Press "2"
fireEvent.change(input, { target: { value: '2:mm aa' } });
@@ -527,32 +527,32 @@ describe(' - Editing', () => {
it('should go to the next section when pressing `1` then `3` in a 12-hours format', () => {
// Test with v7 input
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
format: adapter.formats.fullTime12h,
});
- v7Response.selectSection('hours');
+ view.selectSection('hours');
- v7Response.pressKey(0, '1');
- expectFieldValueV7(v7Response.getSectionsContainer(), '01:mm aa');
+ view.pressKey(0, '1');
+ expectFieldValueV7(view.getSectionsContainer(), '01:mm aa');
expect(getCleanedSelectedContent()).to.equal('01');
// Press "3"
- v7Response.pressKey(0, '3');
- expectFieldValueV7(v7Response.getSectionsContainer(), '03:mm aa');
+ view.pressKey(0, '3');
+ expectFieldValueV7(view.getSectionsContainer(), '03:mm aa');
expect(getCleanedSelectedContent()).to.equal('mm');
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
format: adapter.formats.fullTime12h,
});
const input = getTextbox();
- v6Response.selectSection('hours');
+ view.selectSection('hours');
// Press "1"
fireEvent.change(input, { target: { value: '1:mm aa' } });
@@ -638,30 +638,30 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
});
- v7Response.selectSection('hours');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowDown' });
+ view.selectSection('hours');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowDown' });
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2010, 3, 3, 2, 3, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV6,
});
const input = getTextbox();
- v6Response.selectSection('hours');
+ view.selectSection('hours');
fireEvent.keyDown(input, { key: 'ArrowDown' });
expect(onChangeV6.lastCall.firstArg).toEqualDateTime(new Date(2010, 3, 3, 2, 3, 3));
@@ -671,31 +671,31 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
format: adapter.formats.fullTime24h,
});
- v7Response.selectSection('hours');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'a', ctrlKey: true });
- v7Response.pressKey(null, '');
- fireEvent.keyDown(v7Response.getSectionsContainer(), { key: 'ArrowLeft' });
+ view.selectSection('hours');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'a', ctrlKey: true });
+ view.pressKey(null, '');
+ fireEvent.keyDown(view.getSectionsContainer(), { key: 'ArrowLeft' });
- v7Response.pressKey(0, '3');
- expectFieldValueV7(v7Response.getSectionsContainer(), '03:mm');
+ view.pressKey(0, '3');
+ expectFieldValueV7(view.getSectionsContainer(), '03:mm');
- v7Response.pressKey(1, '4');
- expectFieldValueV7(v7Response.getSectionsContainer(), '03:04');
+ view.pressKey(1, '4');
+ expectFieldValueV7(view.getSectionsContainer(), '03:04');
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2010, 3, 3, 3, 4, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV6,
@@ -703,7 +703,7 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('hours');
+ view.selectSection('hours');
fireEvent.keyDown(input, { key: 'a', ctrlKey: true });
fireEvent.change(input, { target: { value: '' } });
fireEvent.keyDown(input, { key: 'ArrowLeft' });
@@ -720,24 +720,24 @@ describe(' - Editing', () => {
// Test with v7 input
const onChangeV7 = spy();
- const v7Response = renderWithProps({
+ let view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV7,
format: adapter.formats.hours24h,
});
- v7Response.selectSection('hours');
- fireEvent.keyDown(v7Response.getActiveSection(0), { key: 'ArrowDown' });
+ view.selectSection('hours');
+ fireEvent.keyDown(view.getActiveSection(0), { key: 'ArrowDown' });
expect(onChangeV7.lastCall.firstArg).toEqualDateTime(new Date(2010, 3, 3, 2, 3, 3));
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
const onChangeV6 = spy();
- const v6Response = renderWithProps({
+ view = renderWithProps({
enableAccessibleFieldDOMStructure: false,
defaultValue: adapter.date('2010-04-03T03:03:03'),
onChange: onChangeV6,
@@ -745,7 +745,7 @@ describe(' - Editing', () => {
});
const input = getTextbox();
- v6Response.selectSection('hours');
+ view.selectSection('hours');
fireEvent.keyDown(input, { key: 'ArrowDown' });
expect(onChangeV6.lastCall.firstArg).toEqualDateTime(new Date(2010, 3, 3, 2, 3, 3));
diff --git a/packages/x-date-pickers/src/YearCalendar/tests/describes.YearCalendar.test.tsx b/packages/x-date-pickers/src/YearCalendar/tests/describes.YearCalendar.test.tsx
index e2b1c722d71a5..87eeb7fee9f4f 100644
--- a/packages/x-date-pickers/src/YearCalendar/tests/describes.YearCalendar.test.tsx
+++ b/packages/x-date-pickers/src/YearCalendar/tests/describes.YearCalendar.test.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
-import { userEvent, screen } from '@mui/internal-test-utils';
+import { screen } from '@mui/internal-test-utils';
import { YearCalendar, yearCalendarClasses as classes } from '@mui/x-date-pickers/YearCalendar';
import {
createPickerRenderer,
@@ -9,6 +9,7 @@ import {
describeValue,
} from 'test/utils/pickers';
import { describeConformance } from 'test/utils/describeConformance';
+import { fireUserEvent } from 'test/utils/fireUserEvent';
describe(' - Describes', () => {
const { render, clock } = createPickerRenderer({
@@ -51,7 +52,7 @@ describe(' - Describes', () => {
},
setNewValue: (value) => {
const newValue = adapterToUse.addYears(value, 1);
- userEvent.mousePress(
+ fireUserEvent.mousePress(
screen.getByRole('radio', { name: adapterToUse.getYear(newValue).toString() }),
);
diff --git a/packages/x-date-pickers/src/tests/fieldKeyboardInteraction.test.tsx b/packages/x-date-pickers/src/tests/fieldKeyboardInteraction.test.tsx
index f9a7fc6144780..3d7436f158ea1 100644
--- a/packages/x-date-pickers/src/tests/fieldKeyboardInteraction.test.tsx
+++ b/packages/x-date-pickers/src/tests/fieldKeyboardInteraction.test.tsx
@@ -75,28 +75,22 @@ describe(`RTL - test arrows navigation`, () => {
const expectedValues = ['hh', 'mm', 'YYYY', 'MM', 'DD', 'DD'];
// Test with v7 input
- const v7Response = renderWithProps(
- { enableAccessibleFieldDOMStructure: true },
- { direction: 'rtl' },
- );
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true }, { direction: 'rtl' });
- v7Response.selectSection('hours');
+ view.selectSection('hours');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
- fireEvent.keyDown(v7Response.getActiveSection(undefined), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(undefined), { key: 'ArrowRight' });
});
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
- { enableAccessibleFieldDOMStructure: false },
- { direction: 'rtl' },
- );
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false }, { direction: 'rtl' });
const input = getTextbox();
- v6Response.selectSection('hours');
+ view.selectSection('hours');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
@@ -108,28 +102,22 @@ describe(`RTL - test arrows navigation`, () => {
const expectedValues = ['DD', 'MM', 'YYYY', 'mm', 'hh', 'hh'];
// Test with v7 input
- const v7Response = renderWithProps(
- { enableAccessibleFieldDOMStructure: true },
- { direction: 'rtl' },
- );
+ let view = renderWithProps({ enableAccessibleFieldDOMStructure: true }, { direction: 'rtl' });
- v7Response.selectSection('day');
+ view.selectSection('day');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
- fireEvent.keyDown(v7Response.getActiveSection(undefined), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(undefined), { key: 'ArrowLeft' });
});
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
- { enableAccessibleFieldDOMStructure: false },
- { direction: 'rtl' },
- );
+ view = renderWithProps({ enableAccessibleFieldDOMStructure: false }, { direction: 'rtl' });
const input = getTextbox();
- v6Response.selectSection('day');
+ view.selectSection('day');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
@@ -142,7 +130,7 @@ describe(`RTL - test arrows navigation`, () => {
const expectedValues = ['11', '54', '1397', '02', '05', '05'];
// Test with v7 input
- const v7Response = renderWithProps(
+ let view = renderWithProps(
{
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2018-04-25T11:54:00'),
@@ -150,17 +138,17 @@ describe(`RTL - test arrows navigation`, () => {
{ direction: 'rtl' },
);
- v7Response.selectSection('hours');
+ view.selectSection('hours');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
- fireEvent.keyDown(v7Response.getActiveSection(undefined), { key: 'ArrowRight' });
+ fireEvent.keyDown(view.getActiveSection(undefined), { key: 'ArrowRight' });
});
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
+ view = renderWithProps(
{
defaultValue: adapter.date('2018-04-25T11:54:00'),
enableAccessibleFieldDOMStructure: false,
@@ -169,7 +157,7 @@ describe(`RTL - test arrows navigation`, () => {
);
const input = getTextbox();
- v6Response.selectSection('hours');
+ view.selectSection('hours');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
@@ -182,7 +170,7 @@ describe(`RTL - test arrows navigation`, () => {
const expectedValues = ['05', '02', '1397', '54', '11', '11'];
// Test with v7 input
- const v7Response = renderWithProps(
+ let view = renderWithProps(
{
enableAccessibleFieldDOMStructure: true,
defaultValue: adapter.date('2018-04-25T11:54:00'),
@@ -190,17 +178,17 @@ describe(`RTL - test arrows navigation`, () => {
{ direction: 'rtl' },
);
- v7Response.selectSection('day');
+ view.selectSection('day');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
- fireEvent.keyDown(v7Response.getActiveSection(undefined), { key: 'ArrowLeft' });
+ fireEvent.keyDown(view.getActiveSection(undefined), { key: 'ArrowLeft' });
});
- v7Response.unmount();
+ view.unmount();
// Test with v6 input
- const v6Response = renderWithProps(
+ view = renderWithProps(
{
defaultValue: adapter.date('2018-04-25T11:54:00'),
enableAccessibleFieldDOMStructure: false,
@@ -209,7 +197,7 @@ describe(`RTL - test arrows navigation`, () => {
);
const input = getTextbox();
- v6Response.selectSection('day');
+ view.selectSection('day');
expectedValues.forEach((expectedValue) => {
expect(getCleanedSelectedContent()).to.equal(expectedValue);
@@ -265,16 +253,16 @@ adapterToTest.forEach((adapterName) => {
expectedValue: TDate;
sectionConfig: ReturnType;
}) => {
- const v7Response = renderWithProps({
+ const view = renderWithProps({
enableAccessibleFieldDOMStructure: true,
defaultValue: initialValue,
format,
});
- v7Response.selectSection(sectionConfig.type);
- fireEvent.keyDown(v7Response.getActiveSection(0), { key });
+ view.selectSection(sectionConfig.type);
+ fireEvent.keyDown(view.getActiveSection(0), { key });
expectFieldValueV7(
- v7Response.getSectionsContainer(),
+ view.getSectionsContainer(),
cleanValueStr(adapter.formatByString(expectedValue, format), sectionConfig),
);
};
diff --git a/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.test.tsx b/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.test.tsx
index 9e01b62298606..feae408bdcc7f 100644
--- a/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.test.tsx
+++ b/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.test.tsx
@@ -76,54 +76,54 @@ describeTreeView<
describe('itemReordering prop', () => {
it('should allow to drag and drop items when props.itemsReordering={true}', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: true,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
- expect(response.getItemIdTree()).to.deep.equal([
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
+ expect(view.getItemIdTree()).to.deep.equal([
{ id: '2', children: [{ id: '1' }] },
{ id: '3' },
]);
});
it('should not allow to drag and drop items when props.itemsReordering={false}', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: false,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
- expect(response.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
+ expect(view.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
});
it('should not allow to drag and drop items when props.itemsReordering is not defined', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
- expect(response.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
+ expect(view.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
});
it('should allow to expand the new parent of the dragged item when it was not expandable before', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
itemsReordering: true,
defaultExpandedItems: ['1'],
});
- dragEvents.fullDragSequence(response.getItemRoot('1.1'), response.getItemContent('2'));
+ dragEvents.fullDragSequence(view.getItemRoot('1.1'), view.getItemContent('2'));
- fireEvent.focus(response.getItemRoot('2'));
- fireEvent.keyDown(response.getItemRoot('2'), { key: 'Enter' });
+ fireEvent.focus(view.getItemRoot('2'));
+ fireEvent.keyDown(view.getItemRoot('2'), { key: 'Enter' });
- expect(response.getItemIdTree()).to.deep.equal([
+ expect(view.getItemIdTree()).to.deep.equal([
{ id: '1', children: [] },
{ id: '2', children: [{ id: '1.1' }] },
]);
@@ -133,14 +133,14 @@ describeTreeView<
describe('onItemPositionChange prop', () => {
it('should call onItemPositionChange when an item is moved', () => {
const onItemPositionChange = spy();
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: true,
onItemPositionChange,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
expect(onItemPositionChange.callCount).to.equal(1);
expect(onItemPositionChange.lastCall.firstArg).to.deep.equal({
itemId: '1',
@@ -152,27 +152,27 @@ describeTreeView<
describe('isItemReorderable prop', () => {
it('should not allow to drag an item when isItemReorderable returns false', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: true,
canMoveItemToNewPosition: () => false,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
- expect(response.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
+ expect(view.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
});
it('should allow to drag an item when isItemReorderable returns true', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: true,
canMoveItemToNewPosition: () => true,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
- expect(response.getItemIdTree()).to.deep.equal([
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
+ expect(view.getItemIdTree()).to.deep.equal([
{ id: '2', children: [{ id: '1' }] },
{ id: '3' },
]);
@@ -182,14 +182,14 @@ describeTreeView<
describe('canMoveItemToNewPosition prop', () => {
it('should call canMoveItemToNewPosition with the correct parameters', () => {
const canMoveItemToNewPosition = spy();
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: true,
canMoveItemToNewPosition,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
expect(canMoveItemToNewPosition.lastCall.firstArg).to.deep.equal({
itemId: '1',
oldPosition: { parentId: null, index: 0 },
@@ -198,27 +198,27 @@ describeTreeView<
});
it('should not allow to drop an item when canMoveItemToNewPosition returns false', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: true,
canMoveItemToNewPosition: () => false,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
- expect(response.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
+ expect(view.getItemIdTree()).to.deep.equal([{ id: '1' }, { id: '2' }, { id: '3' }]);
});
it('should allow to drop an item when canMoveItemToNewPosition returns true', () => {
- const response = render({
+ const view = render({
experimentalFeatures: { indentationAtItemLevel: true, itemsReordering: true },
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
itemsReordering: true,
canMoveItemToNewPosition: () => true,
});
- dragEvents.fullDragSequence(response.getItemRoot('1'), response.getItemContent('2'));
- expect(response.getItemIdTree()).to.deep.equal([
+ dragEvents.fullDragSequence(view.getItemRoot('1'), view.getItemContent('2'));
+ expect(view.getItemIdTree()).to.deep.equal([
{ id: '2', children: [{ id: '1' }] },
{ id: '3' },
]);
diff --git a/packages/x-tree-view/src/TreeItem/TreeItem.test.tsx b/packages/x-tree-view/src/TreeItem/TreeItem.test.tsx
index d85f3e7aa395a..f893aec46d2ac 100644
--- a/packages/x-tree-view/src/TreeItem/TreeItem.test.tsx
+++ b/packages/x-tree-view/src/TreeItem/TreeItem.test.tsx
@@ -21,12 +21,12 @@ describeTreeView<[]>('TreeItem component', ({ render, treeItemComponentName }) =
));
- const response = render({
+ const view = render({
items: [{ id: '1' }],
slotProps: { item: { ContentComponent } },
});
- expect(response.getItemContent('1').textContent).to.equal('MOCK CONTENT COMPONENT');
+ expect(view.getItemContent('1').textContent).to.equal('MOCK CONTENT COMPONENT');
});
it('should use the ContentProps prop when defined', function test() {
@@ -40,12 +40,12 @@ describeTreeView<[]>('TreeItem component', ({ render, treeItemComponentName }) =
));
- const response = render({
+ const view = render({
items: [{ id: '1' }],
slotProps: { item: { ContentComponent, ContentProps: { customProp: 'ABCDEF' } as any } },
});
- expect(response.getItemContent('1').textContent).to.equal('ABCDEF');
+ expect(view.getItemContent('1').textContent).to.equal('ABCDEF');
});
it('should render TreeItem when itemId prop is escaping characters without throwing an error', function test() {
@@ -53,11 +53,11 @@ describeTreeView<[]>('TreeItem component', ({ render, treeItemComponentName }) =
this.skip();
}
- const response = render({
+ const view = render({
items: [{ id: 'C:\\\\', label: 'ABCDEF' }],
});
- expect(response.getItemContent('C:\\\\').textContent).to.equal('ABCDEF');
+ expect(view.getItemContent('C:\\\\').textContent).to.equal('ABCDEF');
});
});
});
diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.test.tsx b/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.test.tsx
index 418a8c4596740..8019dcba99bbf 100644
--- a/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.test.tsx
+++ b/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.test.tsx
@@ -17,63 +17,63 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
({ render, setup }) => {
describe('model props (expandedItems, defaultExpandedItems, onExpandedItemsChange)', () => {
it('should not expand items when no default state and no control state are defined', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
});
- expect(response.isItemExpanded('1')).to.equal(false);
- expect(response.getAllTreeItemIds()).to.deep.equal(['1', '2']);
+ expect(view.isItemExpanded('1')).to.equal(false);
+ expect(view.getAllTreeItemIds()).to.deep.equal(['1', '2']);
});
it('should use the default state when defined', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
defaultExpandedItems: ['1'],
});
- expect(response.isItemExpanded('1')).to.equal(true);
- expect(response.getAllTreeItemIds()).to.deep.equal(['1', '1.1', '2']);
+ expect(view.isItemExpanded('1')).to.equal(true);
+ expect(view.getAllTreeItemIds()).to.deep.equal(['1', '1.1', '2']);
});
it('should use the controlled state when defined', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
expandedItems: ['1'],
});
- expect(response.isItemExpanded('1')).to.equal(true);
- expect(response.getItemRoot('1.1')).toBeVisible();
+ expect(view.isItemExpanded('1')).to.equal(true);
+ expect(view.getItemRoot('1.1')).toBeVisible();
});
it('should use the controlled state instead of the default state when both are defined', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
expandedItems: ['1'],
defaultExpandedItems: ['2'],
});
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(true);
});
it('should react to controlled state update', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
expandedItems: [],
});
- response.setProps({ expandedItems: ['1'] });
- expect(response.isItemExpanded('1')).to.equal(true);
+ view.setProps({ expandedItems: ['1'] });
+ expect(view.isItemExpanded('1')).to.equal(true);
});
it('should call the onExpandedItemsChange callback when the model is updated (add expanded item to empty list)', () => {
const onExpandedItemsChange = spy();
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
onExpandedItemsChange,
});
- fireEvent.click(response.getItemContent('1'));
+ fireEvent.click(view.getItemContent('1'));
expect(onExpandedItemsChange.callCount).to.equal(1);
expect(onExpandedItemsChange.lastCall.args[1]).to.deep.equal(['1']);
@@ -82,7 +82,7 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
it('should call the onExpandedItemsChange callback when the model is updated (add expanded item to non-empty list)', () => {
const onExpandedItemsChange = spy();
- const response = render({
+ const view = render({
items: [
{ id: '1', children: [{ id: '1.1' }] },
{ id: '2', children: [{ id: '2.1' }] },
@@ -91,7 +91,7 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
defaultExpandedItems: ['1'],
});
- fireEvent.click(response.getItemContent('2'));
+ fireEvent.click(view.getItemContent('2'));
expect(onExpandedItemsChange.callCount).to.equal(1);
expect(onExpandedItemsChange.lastCall.args[1]).to.deep.equal(['2', '1']);
@@ -100,7 +100,7 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
it('should call the onExpandedItemsChange callback when the model is updated (remove expanded item)', () => {
const onExpandedItemsChange = spy();
- const response = render({
+ const view = render({
items: [
{ id: '1', children: [{ id: '1.1' }] },
{ id: '2', children: [{ id: '2.1' }] },
@@ -109,35 +109,35 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
defaultExpandedItems: ['1'],
});
- fireEvent.click(response.getItemContent('1'));
+ fireEvent.click(view.getItemContent('1'));
expect(onExpandedItemsChange.callCount).to.equal(1);
expect(onExpandedItemsChange.lastCall.args[1]).to.deep.equal([]);
});
it('should warn when switching from controlled to uncontrolled', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }],
expandedItems: [],
});
expect(() => {
- response.setProps({ expandedItems: undefined });
+ view.setProps({ expandedItems: undefined });
}).toErrorDev(
'MUI X: A component is changing the controlled expandedItems state of TreeView to be uncontrolled.',
);
});
it('should warn and not react to update when updating the default state', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
defaultExpandedItems: ['1'],
});
expect(() => {
- response.setProps({ defaultExpandedItems: ['2'] });
- expect(response.isItemExpanded('1')).to.equal(true);
- expect(response.isItemExpanded('2')).to.equal(false);
+ view.setProps({ defaultExpandedItems: ['2'] });
+ expect(view.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('2')).to.equal(false);
}).toErrorDev(
'MUI X: A component is changing the default expandedItems state of an uncontrolled TreeView after being initialized. To suppress this warning opt to use a controlled TreeView.',
);
@@ -146,65 +146,65 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
describe('item click interaction', () => {
it('should expand collapsed item when clicking on an item content', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
});
- expect(response.isItemExpanded('1')).to.equal(false);
- fireEvent.click(response.getItemContent('1'));
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(false);
+ fireEvent.click(view.getItemContent('1'));
+ expect(view.isItemExpanded('1')).to.equal(true);
});
it('should collapse expanded item when clicking on an item content', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
defaultExpandedItems: ['1'],
});
- expect(response.isItemExpanded('1')).to.equal(true);
- fireEvent.click(response.getItemContent('1'));
- expect(response.isItemExpanded('1')).to.equal(false);
+ expect(view.isItemExpanded('1')).to.equal(true);
+ fireEvent.click(view.getItemContent('1'));
+ expect(view.isItemExpanded('1')).to.equal(false);
});
it('should not expand collapsed item when clicking on a disabled item content', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', disabled: true, children: [{ id: '1.1' }] }, { id: '2' }],
});
- expect(response.isItemExpanded('1')).to.equal(false);
- fireEvent.click(response.getItemContent('1'));
- expect(response.isItemExpanded('1')).to.equal(false);
+ expect(view.isItemExpanded('1')).to.equal(false);
+ fireEvent.click(view.getItemContent('1'));
+ expect(view.isItemExpanded('1')).to.equal(false);
});
it('should not collapse expanded item when clicking on a disabled item', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', disabled: true, children: [{ id: '1.1' }] }, { id: '2' }],
defaultExpandedItems: ['1'],
});
- expect(response.isItemExpanded('1')).to.equal(true);
- fireEvent.click(response.getItemContent('1'));
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(true);
+ fireEvent.click(view.getItemContent('1'));
+ expect(view.isItemExpanded('1')).to.equal(true);
});
it('should expand collapsed item when clicking on an item label', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
});
- expect(response.isItemExpanded('1')).to.equal(false);
- fireEvent.click(response.getItemLabel('1'));
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(false);
+ fireEvent.click(view.getItemLabel('1'));
+ expect(view.isItemExpanded('1')).to.equal(true);
});
it('should expand collapsed item when clicking on an item icon container', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
});
- expect(response.isItemExpanded('1')).to.equal(false);
- fireEvent.click(response.getItemIconContainer('1'));
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(false);
+ fireEvent.click(view.getItemIconContainer('1'));
+ expect(view.isItemExpanded('1')).to.equal(true);
});
it('should be able to limit the expansion to the icon', function test() {
@@ -245,16 +245,16 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
);
});
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }, { id: '2' }],
slots: { item: CustomTreeItem },
});
- expect(response.isItemExpanded('1')).to.equal(false);
- fireEvent.click(response.getItemContent('1'));
- expect(response.isItemExpanded('1')).to.equal(false);
- fireEvent.click(response.getItemIconContainer('1'));
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(false);
+ fireEvent.click(view.getItemContent('1'));
+ expect(view.isItemExpanded('1')).to.equal(false);
+ fireEvent.click(view.getItemIconContainer('1'));
+ expect(view.isItemExpanded('1')).to.equal(true);
});
});
@@ -262,28 +262,28 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
// This `describe` only tests basics scenarios, more complex scenarios are tested in this file's other `describe`.
describe('aria-expanded item attribute', () => {
it('should have the attribute `aria-expanded=false` if collapsed', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
});
- expect(response.getItemRoot('1')).to.have.attribute('aria-expanded', 'false');
+ expect(view.getItemRoot('1')).to.have.attribute('aria-expanded', 'false');
});
it('should have the attribute `aria-expanded=true` if expanded', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
defaultExpandedItems: ['1'],
});
- expect(response.getItemRoot('1')).to.have.attribute('aria-expanded', 'true');
+ expect(view.getItemRoot('1')).to.have.attribute('aria-expanded', 'true');
});
it('should not have the attribute `aria-expanded` if no children are present', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }],
});
- expect(response.getItemRoot('1')).not.to.have.attribute('aria-expanded');
+ expect(view.getItemRoot('1')).not.to.have.attribute('aria-expanded');
});
});
@@ -291,12 +291,12 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
it('should call the onItemExpansionToggle callback when expanding an item', () => {
const onItemExpansionToggle = spy();
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
onItemExpansionToggle,
});
- fireEvent.click(response.getItemContent('1'));
+ fireEvent.click(view.getItemContent('1'));
expect(onItemExpansionToggle.callCount).to.equal(1);
expect(onItemExpansionToggle.lastCall.args[1]).to.equal('1');
expect(onItemExpansionToggle.lastCall.args[2]).to.equal(true);
@@ -305,13 +305,13 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
it('should call the onItemExpansionToggle callback when collapsing an item', () => {
const onItemExpansionToggle = spy();
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
defaultExpandedItems: ['1'],
onItemExpansionToggle,
});
- fireEvent.click(response.getItemContent('1'));
+ fireEvent.click(view.getItemContent('1'));
expect(onItemExpansionToggle.callCount).to.equal(1);
expect(onItemExpansionToggle.lastCall.args[1]).to.equal('1');
expect(onItemExpansionToggle.lastCall.args[2]).to.equal(false);
@@ -322,16 +322,16 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
it('should expand a collapsed item when calling the setItemExpansion method with `isExpanded=true`', () => {
const onItemExpansionToggle = spy();
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
onItemExpansionToggle,
});
act(() => {
- response.apiRef.current.setItemExpansion({} as any, '1', true);
+ view.apiRef.current.setItemExpansion({} as any, '1', true);
});
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(true);
expect(onItemExpansionToggle.callCount).to.equal(1);
expect(onItemExpansionToggle.lastCall.args[1]).to.equal('1');
expect(onItemExpansionToggle.lastCall.args[2]).to.equal(true);
@@ -340,17 +340,17 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
it('should collapse an expanded item when calling the setItemExpansion method with `isExpanded=false`', () => {
const onItemExpansionToggle = spy();
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
defaultExpandedItems: ['1'],
onItemExpansionToggle,
});
act(() => {
- response.apiRef.current.setItemExpansion({} as any, '1', false);
+ view.apiRef.current.setItemExpansion({} as any, '1', false);
});
- expect(response.isItemExpanded('1')).to.equal(false);
+ expect(view.isItemExpanded('1')).to.equal(false);
expect(onItemExpansionToggle.callCount).to.equal(1);
expect(onItemExpansionToggle.lastCall.args[1]).to.equal('1');
expect(onItemExpansionToggle.lastCall.args[2]).to.equal(false);
@@ -359,33 +359,33 @@ describeTreeView<[UseTreeViewExpansionSignature]>(
it('should do nothing when calling the setItemExpansion method with `isExpanded=true` on an already expanded item', () => {
const onItemExpansionToggle = spy();
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
defaultExpandedItems: ['1'],
onItemExpansionToggle,
});
act(() => {
- response.apiRef.current.setItemExpansion({} as any, '1', true);
+ view.apiRef.current.setItemExpansion({} as any, '1', true);
});
- expect(response.isItemExpanded('1')).to.equal(true);
+ expect(view.isItemExpanded('1')).to.equal(true);
expect(onItemExpansionToggle.callCount).to.equal(0);
});
it('should do nothing when calling the setItemExpansion method with `isExpanded=false` on an already collapsed item', () => {
const onItemExpansionToggle = spy();
- const response = render({
+ const view = render({
items: [{ id: '1', children: [{ id: '1.1' }] }],
onItemExpansionToggle,
});
act(() => {
- response.apiRef.current.setItemExpansion({} as any, '1', false);
+ view.apiRef.current.setItemExpansion({} as any, '1', false);
});
- expect(response.isItemExpanded('1')).to.equal(false);
+ expect(view.isItemExpanded('1')).to.equal(false);
expect(onItemExpansionToggle.callCount).to.equal(0);
});
});
diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.test.tsx b/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.test.tsx
index 6bd9dc2448937..94cf0c21ea63f 100644
--- a/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.test.tsx
+++ b/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.test.tsx
@@ -20,107 +20,107 @@ describeTreeView<
({ render, renderFromJSX, TreeItemComponent, treeViewComponentName, TreeViewComponent }) => {
describe('basic behavior', () => {
it('should allow to focus an item', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2' }],
});
- fireEvent.focus(response.getItemRoot('2'));
- expect(response.getFocusedItemId()).to.equal('2');
+ fireEvent.focus(view.getItemRoot('2'));
+ expect(view.getFocusedItemId()).to.equal('2');
- fireEvent.focus(response.getItemRoot('1'));
- expect(response.getFocusedItemId()).to.equal('1');
+ fireEvent.focus(view.getItemRoot('1'));
+ expect(view.getFocusedItemId()).to.equal('1');
});
it('should move the focus when the focused item is removed', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2' }],
});
- fireEvent.focus(response.getItemRoot('2'));
- expect(response.getFocusedItemId()).to.equal('2');
+ fireEvent.focus(view.getItemRoot('2'));
+ expect(view.getFocusedItemId()).to.equal('2');
- response.setItems([{ id: '1' }]);
- expect(response.getFocusedItemId()).to.equal('1');
+ view.setItems([{ id: '1' }]);
+ expect(view.getFocusedItemId()).to.equal('1');
});
});
describe('tabIndex HTML attribute', () => {
it('should set tabIndex={0} on the first item if none are selected', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2' }],
});
- expect(response.getItemRoot('1').tabIndex).to.equal(0);
- expect(response.getItemRoot('2').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('1').tabIndex).to.equal(0);
+ expect(view.getItemRoot('2').tabIndex).to.equal(-1);
});
it('should set tabIndex={0} on the selected item (single selection)', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2' }],
selectedItems: '2',
});
- expect(response.getItemRoot('1').tabIndex).to.equal(-1);
- expect(response.getItemRoot('2').tabIndex).to.equal(0);
+ expect(view.getItemRoot('1').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('2').tabIndex).to.equal(0);
});
it('should set tabIndex={0} on the first selected item (multi selection)', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2' }, { id: '3' }],
selectedItems: ['2', '3'],
multiSelect: true,
});
- expect(response.getItemRoot('1').tabIndex).to.equal(-1);
- expect(response.getItemRoot('2').tabIndex).to.equal(0);
- expect(response.getItemRoot('3').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('1').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('2').tabIndex).to.equal(0);
+ expect(view.getItemRoot('3').tabIndex).to.equal(-1);
});
it('should set tabIndex={0} on the first item if the selected item is not visible', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2', children: [{ id: '2.1' }] }],
selectedItems: '2.1',
});
- expect(response.getItemRoot('1').tabIndex).to.equal(0);
- expect(response.getItemRoot('2').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('1').tabIndex).to.equal(0);
+ expect(view.getItemRoot('2').tabIndex).to.equal(-1);
});
it('should set tabIndex={0} on the first item if the no selected item is visible', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2', children: [{ id: '2.1' }, { id: '2.2' }] }],
selectedItems: ['2.1', '2.2'],
multiSelect: true,
});
- expect(response.getItemRoot('1').tabIndex).to.equal(0);
- expect(response.getItemRoot('2').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('1').tabIndex).to.equal(0);
+ expect(view.getItemRoot('2').tabIndex).to.equal(-1);
});
});
describe('focusItem api method', () => {
it('should focus the item', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2' }],
});
act(() => {
- response.apiRef.current.focusItem({} as any, '2');
+ view.apiRef.current.focusItem({} as any, '2');
});
- expect(response.getFocusedItemId()).to.equal('2');
+ expect(view.getFocusedItemId()).to.equal('2');
});
it('should not focus item if parent is collapsed', () => {
- const response = render({
+ const view = render({
items: [{ id: '1' }, { id: '2', children: [{ id: '2.1' }] }],
});
act(() => {
- response.apiRef.current.focusItem({} as any, '2.1');
+ view.apiRef.current.focusItem({} as any, '2.1');
});
- expect(response.getFocusedItemId()).to.equal(null);
+ expect(view.getFocusedItemId()).to.equal(null);
});
});
@@ -128,13 +128,13 @@ describeTreeView<
it('should be called when an item is focused', () => {
const onItemFocus = spy();
- const response = render({
+ const view = render({
items: [{ id: '1' }],
onItemFocus,
});
act(() => {
- response.getItemRoot('1').focus();
+ view.getItemRoot('1').focus();
});
expect(onItemFocus.callCount).to.equal(1);
@@ -145,47 +145,47 @@ describeTreeView<
describe('disabledItemsFocusable prop', () => {
describe('disabledItemFocusable={false}', () => {
it('should prevent focus by mouse', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', disabled: true }],
disabledItemsFocusable: false,
});
- fireEvent.click(response.getItemContent('1'));
- expect(response.getFocusedItemId()).to.equal(null);
+ fireEvent.click(view.getItemContent('1'));
+ expect(view.getFocusedItemId()).to.equal(null);
});
it('should tab tabIndex={-1} on the disabled item and tabIndex={0} on the first non-disabled item', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', disabled: true }, { id: '2' }, { id: '3' }],
disabledItemsFocusable: false,
});
- expect(response.getItemRoot('1').tabIndex).to.equal(-1);
- expect(response.getItemRoot('2').tabIndex).to.equal(0);
- expect(response.getItemRoot('3').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('1').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('2').tabIndex).to.equal(0);
+ expect(view.getItemRoot('3').tabIndex).to.equal(-1);
});
});
describe('disabledItemFocusable={true}', () => {
it('should prevent focus by mouse', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', disabled: true }],
disabledItemsFocusable: true,
});
- fireEvent.click(response.getItemContent('1'));
- expect(response.getFocusedItemId()).to.equal(null);
+ fireEvent.click(view.getItemContent('1'));
+ expect(view.getFocusedItemId()).to.equal(null);
});
it('should tab tabIndex={0} on the disabled item and tabIndex={-1} on the other items', () => {
- const response = render({
+ const view = render({
items: [{ id: '1', disabled: true }, { id: '2' }, { id: '3' }],
disabledItemsFocusable: true,
});
- expect(response.getItemRoot('1').tabIndex).to.equal(0);
- expect(response.getItemRoot('2').tabIndex).to.equal(-1);
- expect(response.getItemRoot('3').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('1').tabIndex).to.equal(0);
+ expect(view.getItemRoot('2').tabIndex).to.equal(-1);
+ expect(view.getItemRoot('3').tabIndex).to.equal(-1);
});
});
});
@@ -227,19 +227,19 @@ describeTreeView<
);
}
- const response = renderFromJSX(