diff --git a/lib/package.json b/lib/package.json index d8fa9cb7b..c6a2d8817 100644 --- a/lib/package.json +++ b/lib/package.json @@ -140,7 +140,7 @@ ], "globals": { "ts-jest": { - "tsConfig": "./tsconfig.json" + "tsConfig": "./src/__tests__/tsconfig.json" } } } diff --git a/lib/src/__tests__/e2e/DateTimePickerInline.test.tsx b/lib/src/__tests__/e2e/DateTimePickerInline.test.tsx new file mode 100644 index 000000000..da0945a96 --- /dev/null +++ b/lib/src/__tests__/e2e/DateTimePickerInline.test.tsx @@ -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; + const onChangeMock = jest.fn(); + const onCloseMock = jest.fn(); + const onOpenMock = jest.fn(); + + beforeEach(() => { + jest.clearAllMocks(); + component = mount( + + ); + }); + + 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(); + }); +}); diff --git a/lib/src/__tests__/tsconfig.json b/lib/src/__tests__/tsconfig.json new file mode 100644 index 000000000..08b7b1085 --- /dev/null +++ b/lib/src/__tests__/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../../tsconfig.json", + "include": ["./**/*.tsx"], + "exclude": [] +}