Skip to content

Commit

Permalink
[test] Make seconds views test pass in browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Sep 21, 2021
1 parent 98e0000 commit 7dc423f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 deletions.
46 changes: 1 addition & 45 deletions packages/mui-lab/src/DateTimePicker/DateTimePicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react';
import TextField from '@mui/material/TextField';
import DateTimePicker from '@mui/lab/DateTimePicker';
import { expect } from 'chai';
import { createPickerRender, getByMuiTest } from '../internal/pickers/test-utils';
import { createPickerRender } from '../internal/pickers/test-utils';

describe('<DateTimePicker />', () => {
const render = createPickerRender();
Expand All @@ -17,47 +16,4 @@ describe('<DateTimePicker />', () => {
/>,
);
});

it('should be render seconds on view', () => {
const date = new Date(2021, 10, 20, 10, 1, 22);
render(
<DateTimePicker
renderInput={(params) => <TextField {...params} />}
onChange={() => {}}
open={Boolean(true)}
views={['seconds']}
value={date}
/>,
);
expect(getByMuiTest('seconds')).to.have.text('22');
});

it('should not be render seconds by default', () => {
const date = new Date(2021, 10, 20, 10, 1, 22);
render(
<DateTimePicker
renderInput={(params) => <TextField {...params} />}
onChange={() => {}}
open={Boolean(true)}
value={date}
/>,
);
expect(() => getByMuiTest('seconds')).throw('Unable to find an element');
});

it('should be render date and time by default', () => {
const date = new Date(2021, 10, 20, 10, 1, 22);
render(
<DateTimePicker
renderInput={(params) => <TextField {...params} />}
onChange={() => {}}
open={Boolean(true)}
value={date}
/>,
);
expect(getByMuiTest('hours')).to.have.text('10');
expect(getByMuiTest('minutes')).to.have.text('01');
expect(getByMuiTest('datetimepicker-toolbar-year')).to.have.text('2021');
expect(getByMuiTest('datetimepicker-toolbar-day')).to.have.text('Nov 20');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { expect } from 'chai';
import { spy, useFakeTimers, SinonSpy, SinonFakeTimers } from 'sinon';
import { fireEvent, fireTouchChangedEvent, screen } from 'test/utils';
import MobileDateTimePicker from '@mui/lab/MobileDateTimePicker';
import { adapterToUse, getByMuiTest, createPickerRender } from '../internal/pickers/test-utils';
import {
adapterToUse,
getByMuiTest,
queryByMuiTest,
createPickerRender,
} from '../internal/pickers/test-utils';

describe('<MobileDateTimePicker />', () => {
let clock: SinonFakeTimers;
Expand Down Expand Up @@ -128,4 +133,34 @@ describe('<MobileDateTimePicker />', () => {
fireEvent.click(screen.getByText('Cancel'));
expect(onCloseMock.callCount).to.equal(1);
});

it('should render date and time by default', () => {
render(
<MobileDateTimePicker
renderInput={(params) => <TextField {...params} />}
onChange={() => {}}
open
value={adapterToUse.date('2021-11-20T10:01:22.000')}
/>,
);

expect(queryByMuiTest(document.body, 'seconds')).to.equal(null);
expect(getByMuiTest('hours')).to.have.text('10');
expect(getByMuiTest('minutes')).to.have.text('01');
expect(getByMuiTest('datetimepicker-toolbar-year')).to.have.text('2021');
expect(getByMuiTest('datetimepicker-toolbar-day')).to.have.text('Nov 20');
});

it('can render seconds on view', () => {
render(
<MobileDateTimePicker
renderInput={(params) => <TextField {...params} />}
onChange={() => {}}
open
views={['seconds']}
value={adapterToUse.date('2021-11-20T10:01:22.000')}
/>,
);
expect(getByMuiTest('seconds')).to.have.text('22');
});
});

0 comments on commit 7dc423f

Please sign in to comment.