Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Update tests with latest state of StrictMode compatibility #27042

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { SinonFakeTimers, useFakeTimers } from 'sinon';
import { fireEvent, screen, describeConformanceV5 } from 'test/utils';
import CalendarPicker, { calendarPickerClasses as classes } from '@material-ui/lab/CalendarPicker';
import {
Expand All @@ -10,6 +11,15 @@ import {
} from '../internal/pickers/test-utils';

describe('<CalendarPicker />', () => {
let clock: SinonFakeTimers;
beforeEach(() => {
clock = useFakeTimers();
});
afterEach(() => {
clock.restore();
});

// StrictModeViolation: Uses StrictMode incompatible API of `react-transition-group`
const render = createPickerRender({ strict: false });

describeConformanceV5(<CalendarPicker date={adapterToUse.date()} onChange={() => {}} />, () => ({
Expand Down
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { SinonFakeTimers, spy, useFakeTimers } from 'sinon';
import TextField from '@material-ui/core/TextField';
import { TransitionProps } from '@material-ui/core/transitions';
import { act, fireEvent, screen, userEvent } from 'test/utils';
Expand Down Expand Up @@ -42,6 +42,14 @@ const UncontrolledOpenDesktopDatePicker = (({
}) as typeof DesktopDatePicker;

describe('<DesktopDatePicker />', () => {
let clock: SinonFakeTimers;
beforeEach(() => {
clock = useFakeTimers();
});
afterEach(() => {
clock.restore();
});
// StrictModeViolation: Uses CalendarPicker
const render = createPickerRender({ strict: false });

it('prop: components.OpenPickerIcon', () => {
Expand Down
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { SinonFakeTimers, spy, useFakeTimers } from 'sinon';
import { act, describeConformance, screen, fireEvent, userEvent } from 'test/utils';
import { createTheme, ThemeProvider } from '@material-ui/core/styles';
import TextField, { TextFieldProps } from '@material-ui/core/TextField';
Expand All @@ -23,14 +23,15 @@ const defaultRangeRenderInput = (startProps: TextFieldProps, endProps: TextField
);

describe('<DesktopDateRangePicker />', () => {
const render = createPickerRender({ strict: false });

before(function beforeHook() {
if (!/jsdom/.test(window.navigator.userAgent)) {
// FIXME This test suite is extremely flaky in test:karma
Copy link
Member Author

Choose a reason for hiding this comment

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

Was likely flaky due to real timers.

this.skip();
}
let clock: SinonFakeTimers;
beforeEach(() => {
clock = useFakeTimers();
});
afterEach(() => {
clock.restore();
});
// StrictModeViolation: Uses CalendarPicker
const render = createPickerRender({ strict: false });

describeConformance(
<DesktopDateRangePicker
Expand Down
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { expect } from 'chai';
import { spy, useFakeTimers, SinonFakeTimers } from 'sinon';
import TextField from '@material-ui/core/TextField';
import { fireEvent, screen } from 'test/utils';
import { act, fireEvent, screen } from 'test/utils';
import PickersDay from '@material-ui/lab/PickersDay';
import CalendarPickerSkeleton from '@material-ui/lab/CalendarPickerSkeleton';
import MobileDatePicker from '@material-ui/lab/MobileDatePicker';
Expand All @@ -16,6 +16,14 @@ import {
} from '../internal/pickers/test-utils';

describe('<MobileDatePicker />', () => {
let clock: SinonFakeTimers;
beforeEach(() => {
clock = useFakeTimers(new Date());
});
afterEach(() => {
clock.restore();
});
// StrictModeViolation: Uses CalendarPicker
const render = createPickerRender({ strict: false });

it('Accepts date on `OK` button click', () => {
Expand Down Expand Up @@ -267,39 +275,29 @@ describe('<MobileDatePicker />', () => {
expect(screen.getByText('July')).toBeVisible();
});

describe('mock time', () => {
let clock: SinonFakeTimers;

beforeEach(() => {
clock = useFakeTimers(new Date());
});

afterEach(() => {
clock.restore();
});

it('prop `showTodayButton` – accept current date when "today" button is clicked', () => {
const onCloseMock = spy();
const handleChange = spy();
render(
<MobileDatePicker
renderInput={(params) => <TextField {...params} />}
showTodayButton
cancelText="stream"
onClose={onCloseMock}
onChange={handleChange}
value={adapterToUse.date('2018-01-01T00:00:00.000')}
DialogProps={{ TransitionComponent: FakeTransitionComponent }}
/>,
);
const start = adapterToUse.date();
fireEvent.click(screen.getByRole('textbox'));
it('prop `showTodayButton` – accept current date when "today" button is clicked', () => {
const onCloseMock = spy();
const handleChange = spy();
render(
<MobileDatePicker
renderInput={(params) => <TextField {...params} />}
showTodayButton
cancelText="stream"
onClose={onCloseMock}
onChange={handleChange}
value={adapterToUse.date('2018-01-01T00:00:00.000')}
DialogProps={{ TransitionComponent: FakeTransitionComponent }}
/>,
);
const start = adapterToUse.date();
fireEvent.click(screen.getByRole('textbox'));
act(() => {
clock.tick(10);
fireEvent.click(screen.getByText(/today/i));

expect(onCloseMock.callCount).to.equal(1);
expect(handleChange.callCount).to.equal(1);
expect(adapterToUse.getDiff(handleChange.args[0][0], start)).to.equal(10);
});
fireEvent.click(screen.getByText(/today/i));

expect(onCloseMock.callCount).to.equal(1);
expect(handleChange.callCount).to.equal(1);
expect(adapterToUse.getDiff(handleChange.args[0][0], start)).to.equal(10);
});
});
Expand Up @@ -17,6 +17,7 @@ describe('<MobileDateTimePicker />', () => {
clock.restore();
});

// StrictModeViolation: Uses CalendarPicker
const render = createPickerRender({ strict: false });

it('opens dialog on textField click for Mobile mode', () => {
Expand Down
@@ -1,5 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { SinonFakeTimers, useFakeTimers } from 'sinon';
import TextField from '@material-ui/core/TextField';
import { fireEvent, screen } from 'test/utils';
import StaticDatePicker from '@material-ui/lab/StaticDatePicker';
Expand All @@ -11,6 +12,14 @@ import {
} from '../internal/pickers/test-utils';

describe('<StaticDatePicker />', () => {
let clock: SinonFakeTimers;
beforeEach(() => {
clock = useFakeTimers();
});
afterEach(() => {
clock.restore();
});
// StrictModeViolation: Uses CalendarPicker
const render = createPickerRender({ strict: false });

it('render proper month', () => {
Expand Down
Expand Up @@ -12,6 +12,7 @@ import StylesProvider from '../StylesProvider';
import ThemeProvider from '../ThemeProvider';

describe('makeStyles', () => {
// StrictModeViolation: uses `useSynchronousEffect`
const mount = createMount({ strict: null });

/**
Expand Down