Skip to content

Commit

Permalink
Merge pull request #743 from dmtrKovalenko/feature/e2e-inline-datetim…
Browse files Browse the repository at this point in the history
…epicker

Add unit tests for inline datetime picker
  • Loading branch information
dmtrKovalenko authored Nov 6, 2018
2 parents 8e0a32a + 955feb4 commit 211fa4e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
],
"globals": {
"ts-jest": {
"tsConfig": "./tsconfig.json"
"tsConfig": "./src/__tests__/tsconfig.json"
}
}
}
Expand Down
73 changes: 73 additions & 0 deletions lib/src/__tests__/e2e/DateTimePickerInline.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { PopoverProps } from '@material-ui/core/Popover';
import { ReactWrapper } from 'enzyme';
import * as React from 'react';
import DateTimePickerInline, {
DateTimePickerInlineProps,
} from '../../DateTimePicker/DateTimePickerInline';
import { mount, utilsToUse } from '../test-utils';

describe('e2e - DateTimePickerInline', () => {
let component: ReactWrapper<DateTimePickerInlineProps>;
const onChangeMock = jest.fn();
const onCloseMock = jest.fn();
const onOpenMock = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
component = mount(
<DateTimePickerInline
onChange={onChangeMock}
onClose={onCloseMock}
onOpen={onOpenMock}
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
/>
);
});

it('Should renders', () => {
expect(component).toBeTruthy();
});

it('Should open modal with picker on click', () => {
component.find('input').simulate('click');
expect(component.find('WithStyles(Popover)').props().open).toBeTruthy();
expect(onOpenMock).toHaveBeenCalled();
});

it('Should close on popover close request', () => {
const popoverOnClose = (component
.find('WithStyles(Popover)')
.props() as PopoverProps).onClose;
if (!popoverOnClose) {
throw new Error('expected popoverOnClose');
}
popoverOnClose({} as any);
expect(component.find('WithStyles(Popover)').props().open).toBeFalsy();
expect(onCloseMock).toHaveBeenCalled();
});

it('Should get the full workflow for datetime picker', () => {
// Date
component.find('input').simulate('click');
component
.find('Day button')
.at(10)
.simulate('click');

expect(component.find('Clock').prop('type')).toBe('hours');

// Hour
component
.find('Clock div[role="menu"]')
.simulate('mouseUp', { nativeEvent: { offsetX: 10, offsetY: 20 } });

expect(component.find('Clock').prop('type')).toBe('minutes');

// Minutes
component
.find('Clock div[role="menu"]')
.simulate('mouseUp', { nativeEvent: { offsetX: 10, offsetY: 20 } });

expect(onChangeMock).toHaveBeenCalled();
});
});
5 changes: 5 additions & 0 deletions lib/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["./**/*.tsx"],
"exclude": []
}

0 comments on commit 211fa4e

Please sign in to comment.