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

feat(DatePicker, DatePickerInput): refactors to functional component #10224

Merged
merged 27 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c2b9af0
feat(DatePickerInput): refactors input to function
jnm2377 Dec 3, 2021
315d2ef
Update packages/react/src/components/DatePickerInput/next/DatePickerI…
jnm2377 Dec 6, 2021
6ea3d35
fix: clean up
jnm2377 Dec 6, 2021
a746fe8
chore: merge
jnm2377 Dec 6, 2021
b060327
feat: add date picker v11 story and index
jnm2377 Dec 9, 2021
b20a989
feat: date picker ref changes not working yet
jnm2377 Dec 9, 2021
e19db8e
feat: date picker refactor
jnm2377 Dec 11, 2021
9bf1e61
feat: date-picker v11 tests
jnm2377 Dec 11, 2021
66b39c5
Merge branch 'main' of github.com:carbon-design-system/carbon into da…
jnm2377 Dec 11, 2021
2946d5f
fix: next datepicker stories
jnm2377 Dec 14, 2021
c86a3ef
fix: component did update useEffect
jnm2377 Jan 4, 2022
f51a2aa
chore: remove console.log
jnm2377 Jan 4, 2022
9321cab
Merge branch 'main' of github.com:carbon-design-system/carbon into da…
jnm2377 Jan 5, 2022
4127fdd
fix: test import
jnm2377 Jan 5, 2022
6481f42
fix: icon click events
jnm2377 Jan 7, 2022
ca258da
fix: component prop updates
jnm2377 Jan 7, 2022
031cd0d
fix: deprecated props
jnm2377 Jan 7, 2022
d1f5fd4
fix: prop useEffect updates
jnm2377 Jan 7, 2022
403e07f
chore: update tests
jnm2377 Jan 10, 2022
3a90052
chore: remove test
jnm2377 Jan 11, 2022
78d1329
Update packages/react/src/components/DatePicker/next/DatePicker-test.js
jnm2377 Jan 11, 2022
434171f
Update packages/react/src/components/DatePicker/next/DatePicker.js
jnm2377 Jan 11, 2022
ff9932d
Update packages/react/src/components/DatePicker/next/DatePicker.js
jnm2377 Jan 11, 2022
9621a27
Update packages/react/src/components/DatePicker/next/DatePicker.js
jnm2377 Jan 11, 2022
1139c0e
fix: format
jnm2377 Jan 11, 2022
a34c725
fix: update classnames
jnm2377 Jan 14, 2022
fa9429a
Merge branch 'main' into date-picker-input-refactor
kodiakhq[bot] Jan 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/react/src/components/DatePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

import * as FeatureFlags from '@carbon/feature-flags';
import { default as DatePickerNext } from './next/DatePicker';
import { default as DatePickerClassic } from './DatePicker';

const DatePicker = FeatureFlags.enabled('enable-v11-release')
? DatePickerNext
: DatePickerClassic;

export default DatePicker;
export { default as DatePickerSkeleton } from './DatePicker.Skeleton';
export default from './DatePicker';
233 changes: 233 additions & 0 deletions packages/react/src/components/DatePicker/next/DatePicker-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import DatePicker from './DatePicker';
import { mount } from 'enzyme';
import DatePickerInput from '../../DatePickerInput/next/DatePickerInput';

const prefix = 'bx';

function getFlatpickrCalendar() {
return document.querySelector(`.${prefix}--date-picker__calendar`);
}

// function isCalendarVisible() {
// const calendar = document.querySelector(`.${prefix}--date-picker__calendar`);
// return calendar.classList.contains('open');
// }
jnm2377 marked this conversation as resolved.
Show resolved Hide resolved

describe('DatePicker', () => {
describe('Renders as expected', () => {
let wrapper;
let datepicker;

beforeEach(() => {
wrapper = mount(
<DatePicker
onChange={() => {}}
className="extra-class"
dateFormat="m/d/Y">
<DatePickerInput
id="date-picker-input-id-start"
placeholder="mm/dd/yyyy"
labelText="Start date"
/>
<DatePickerInput
id="date-picker-input-id-finish"
placeholder="mm/dd/yyyy"
labelText="End date"
/>
</DatePicker>
);
datepicker = wrapper.childAt(0);
});

it('should add extra classes that are passed via className', () => {
expect(datepicker.hasClass('extra-class')).toBe(true);
});

it('should add the date picker type as expected', () => {
expect(wrapper.props().datePickerType).toEqual(undefined);
wrapper.setProps({ datePickerType: 'simple' });
expect(wrapper.props().datePickerType).toEqual('simple');
});

it('should add the date format as expected', () => {
expect(wrapper.props().dateFormat).toEqual('m/d/Y');
wrapper.setProps({ dateFormat: 'd/m/Y' });
expect(wrapper.props().dateFormat).toEqual('d/m/Y');
});

it('has the value as expected', () => {
expect(wrapper.props().value).toEqual(undefined);
wrapper.setProps({ value: '11/08/2017' });
expect(wrapper.props().value).toEqual('11/08/2017');
});

it('should render the children as expected', () => {
expect(wrapper.props().children.length).toEqual(2);
});
});

describe('Simple date picker', () => {
let wrapper;

beforeEach(() => {
wrapper = mount(
<DatePicker datePickerType="simple" className="extra-class">
<DatePickerInput
placeholder="mm/dd/yyyy"
labelText="Date Picker label"
id="date-picker-single"
/>
</DatePicker>
);
});

it('has the value as expected', () => {
expect(wrapper.props().value).toEqual(undefined);
wrapper.setProps({ value: '11/08/2017' });
expect(wrapper.props().value).toEqual('11/08/2017');
});

it('should not initialize a calendar', () => {
expect(getFlatpickrCalendar()).not.toBeInTheDocument();
});
});

describe('Single date picker', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(
<DatePicker
onChange={() => {}}
datePickerType="single"
className="extra-class">
<DatePickerInput
placeholder="mm/dd/yyyy"
labelText="Date Picker label"
id="date-picker-single"
/>
</DatePicker>
);
});

it('should initialize a calendar', () => {
expect(getFlatpickrCalendar()).toBeInTheDocument();
});

it('should update the classnames', () => {
expect(
getFlatpickrCalendar().classList.contains(
`${prefix}--date-picker__calendar`
)
).toBe(true);
});

it('has the value as expected', () => {
expect(wrapper.props().value).toEqual(undefined);
wrapper.setProps({ value: '11/08/2017' });
expect(wrapper.props().value).toEqual('11/08/2017');
});
});

describe('Date picker with locale', () => {
let wrapper;
let wrapperNoLocale;
beforeEach(() => {
wrapper = mount(
<DatePicker
onChange={() => {}}
datePickerType="range"
className="extra-class"
locale="es">
<DatePickerInput
id="date-picker-input-id-start"
placeholder="mm/dd/yyyy"
labelText="Start date"
/>
<DatePickerInput
id="date-picker-input-id-finish"
placeholder="mm/dd/yyyy"
labelText="End date"
/>
</DatePicker>
);

wrapperNoLocale = mount(
<DatePicker
onChange={() => {}}
datePickerType="range"
className="extra-class">
<DatePickerInput
id="date-picker-input-id-start"
placeholder="mm/dd/yyyy"
labelText="Start date"
/>
<DatePickerInput
id="date-picker-input-id-finish"
placeholder="mm/dd/yyyy"
labelText="End date"
/>
</DatePicker>
);
});

it('has the range date picker locale', () => {
const datepicker = wrapper.find('DatePicker');
expect(datepicker.props().locale).toBe('es');
});

it('has the range date picker without locale defined', () => {
const datepicker = wrapperNoLocale.find('DatePicker');
expect(datepicker.props().locale).toBe(undefined);
});
});

describe('Date picker with minDate and maxDate', () => {
let mockConsoleError;
let wrapper;

beforeEach(() => {
mockConsoleError = jest.spyOn(console, 'error');
wrapper = mount(
<DatePicker
onChange={() => {}}
datePickerType="range"
className="extra-class"
minDate="01/01/2018"
maxDate="01/30/2018">
<DatePickerInput
id="date-picker-input-id-start"
placeholder="mm/dd/yyyy"
labelText="Start date"
/>
<DatePickerInput
id="date-picker-input-id-finish"
placeholder="mm/dd/yyyy"
labelText="End date"
/>
</DatePicker>
);
});

afterEach(() => {
mockConsoleError.mockRestore();
});

it('has the range date picker with min and max dates', () => {
const datepicker = wrapper.find('DatePicker');
expect(datepicker.props().minDate).toBe('01/01/2018');
expect(datepicker.props().maxDate).toBe('01/30/2018');
});

it('should not have "console.error" being created', () => {
expect(mockConsoleError).not.toHaveBeenCalled();
});
});
});
Loading