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

Update unit tests #86

Merged
merged 4 commits into from
Nov 29, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/DatePicker/DatePicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('<DatePicker />', () => {
wrapper.find('input[type="text"]').simulate('keypress', { key: 'Enter' });

wrapper = mount(defaultDatePicker);
const date = new Date();
let date = new Date();
wrapper.instance().updateDate(date);
expect(wrapper.state('selectedDate')).toEqual(date);
formattedDate = `${date.getMonth() +
Expand All @@ -207,15 +207,26 @@ describe('<DatePicker />', () => {

expect(wrapper.instance().formatDate([])).toEqual('');

// enter end year of 3001
wrapper = mount(rangeDatePicker);

startRangeDate = new Date();
endRangeDate = new Date();
endRangeDate.setFullYear(3001);

arrDates = [startRangeDate, endRangeDate];
expect(wrapper.instance().formatDate(arrDates)).toEqual('');

expect(wrapper.instance().formatDate([])).toEqual('');

// default date picker format date
wrapper = mount(defaultDatePicker);
startRangeDate = new Date();

formattedDate = `${startRangeDate.getMonth() +
1}/${startRangeDate.getDate()}/${startRangeDate.getFullYear()}`;

expect(wrapper.instance().formatDate(startRangeDate)).toEqual('');

arrDates = [startRangeDate];
});

test('modify date on change', () => {
Expand Down
32 changes: 16 additions & 16 deletions src/Time/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ class TimeItem extends Component {
const { style, arialabel } = this.state;
const { type, placeholder, disabled, spinners } = this.props;
return (
<div className='fd-time__item'>
<div className="fd-time__item">
{spinners ? (
<div className='fd-time__control'>
<div className="fd-time__control">
<button
className=' fd-button--light fd-button--xs sap-icon--navigation-up-arrow '
className=" fd-button--light fd-button--xs sap-icon--navigation-up-arrow "
aria-label={arialabel.buttonUp}
disabled={disabled}
onClick={this._onUp}
Expand All @@ -259,11 +259,11 @@ class TimeItem extends Component {
) : (
''
)}
<div className='fd-time__input'>
<div className="fd-time__input">
<input
className={style}
type='text'
maxLength='2'
type="text"
maxLength="2"
placeholder={placeholder}
onChange={this.onChange}
value={this.props.value}
Expand All @@ -273,9 +273,9 @@ class TimeItem extends Component {
/>
</div>
{spinners ? (
<div className='fd-time__control'>
<div className="fd-time__control">
<button
className=' fd-button--light fd-button--xs sap-icon--navigation-down-arrow'
className=" fd-button--light fd-button--xs sap-icon--navigation-down-arrow"
aria-label={arialabel.buttonDown}
disabled={disabled}
onClick={this._onDown}
Expand Down Expand Up @@ -370,9 +370,9 @@ export class Time extends Component {
this.props.onChange(this.state.time);
}
};
onUpdateTime = () => {
this.props.onUpdateTime();
};
// onUpdateTime = () => {
// this.props.onUpdateTime();
// };
render() {
const {
showHour,
Expand All @@ -391,7 +391,7 @@ export class Time extends Component {
max = 24;
}
return (
<div id={id} className='fd-time'>
<div id={id} className="fd-time">
{/* Hours */}
{showHour ? (
<TimeItem
Expand All @@ -402,7 +402,7 @@ export class Time extends Component {
max={max}
value={time.hour}
updateTime={this.updateTime}
name='hour'
name="hour"
time={time}
format12Hours={format12Hours}
spinners={spinners}
Expand All @@ -420,7 +420,7 @@ export class Time extends Component {
max={'60'}
value={this.state.time.minute}
updateTime={this.updateTime}
name='minute'
name="minute"
time={time}
format12Hours={format12Hours}
spinners={spinners}
Expand All @@ -438,7 +438,7 @@ export class Time extends Component {
max={'60'}
value={this.state.time.second}
updateTime={this.updateTime}
name='second'
name="second"
time={time}
format12Hours={format12Hours}
spinners={spinners}
Expand All @@ -455,7 +455,7 @@ export class Time extends Component {
time={this.state.time}
value={CLOCK[this.state.time.meridiem]}
updateTime={this.updateTime}
name='meridiem'
name="meridiem"
spinners={spinners}
/>
) : (
Expand Down
89 changes: 89 additions & 0 deletions src/Time/Time.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,22 @@ describe('<Time />', () => {
expect(wrapper.state('time').minute).toEqual(0);
expect(wrapper.state('time').second).toEqual(0);

wrapper = mount(
<Time
format12Hours={false}
time={{ hour: 23, minute: 0, second: 0, meridiem: 0 }}
name="meridiem"
/>
);
expect(wrapper.state('time').hour).toEqual(23);
wrapper
.find(
'button.fd-button--light.fd-button--xs.sap-icon--navigation-up-arrow'
)
.at(0)
.simulate('click');
expect(wrapper.state('time').hour).toEqual('00');

wrapper = mount(
<Time
format12Hours={true}
Expand Down Expand Up @@ -435,6 +451,23 @@ describe('<Time />', () => {
expect(wrapper.state('time').minute).toEqual(0);
expect(wrapper.state('time').second).toEqual(0);
expect(wrapper.state('time').meridiem).toEqual(0);

wrapper = mount(
<Time
format12Hours={true}
time={{ hour: 11, minute: 0, second: 0, meridiem: 0 }}
name="meridiem"
/>
);
expect(wrapper.state('time').hour).toEqual(11);
wrapper
.find(
'button.fd-button--light.fd-button--xs.sap-icon--navigation-up-arrow'
)
.at(0)
.simulate('click');
expect(wrapper.state('time').hour).toEqual(12);
expect(wrapper.state('time').meridiem).toEqual(1);
});

test('clicking up on minutes', () => {
Expand All @@ -456,6 +489,23 @@ describe('<Time />', () => {
expect(wrapper.state('time').minute).toEqual('01');
expect(wrapper.state('time').second).toEqual(0);

wrapper = mount(
<Time
format12Hours={false}
time={{ hour: 24, minute: 59, second: 0, meridiem: 0 }}
name="meridiem"
/>
);
expect(wrapper.state('time').minute).toEqual(59);
wrapper
.find(
'button.fd-button--light.fd-button--xs.sap-icon--navigation-up-arrow'
)
.at(1)
.simulate('click');
expect(wrapper.state('time').hour).toEqual('00');
expect(wrapper.state('time').minute).toEqual('00');

wrapper = mount(
<Time
format12Hours={true}
Expand All @@ -475,6 +525,45 @@ describe('<Time />', () => {
expect(wrapper.state('time').second).toEqual(0);
expect(wrapper.state('time').meridiem).toEqual(0);

wrapper = mount(
<Time
format12Hours={true}
time={{ hour: 1, minute: 59, second: 0, meridiem: 0 }}
name="meridiem"
/>
);
expect(wrapper.state('time').hour).toEqual(1);
expect(wrapper.state('time').minute).toEqual(59);

wrapper
.find(
'button.fd-button--light.fd-button--xs.sap-icon--navigation-up-arrow'
)
.at(1)
.simulate('click');
expect(wrapper.state('time').hour).toEqual('01');
expect(wrapper.state('time').minute).toEqual('00');

wrapper = mount(
<Time
format12Hours={true}
time={{ hour: 11, minute: 59, second: 0, meridiem: 0 }}
name="meridiem"
/>
);
expect(wrapper.state('time').hour).toEqual(11);
expect(wrapper.state('time').minute).toEqual(59);

wrapper
.find(
'button.fd-button--light.fd-button--xs.sap-icon--navigation-up-arrow'
)
.at(1)
.simulate('click');
expect(wrapper.state('time').hour).toEqual(12);
expect(wrapper.state('time').minute).toEqual('00');
expect(wrapper.state('time').meridiem).toEqual(1);

wrapper = mount(
<Time
format12Hours={true}
Expand Down
47 changes: 24 additions & 23 deletions src/TimePicker/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ class TimePickerItem extends Component {
//validate hh:mm and mm:ss
let regex = new RegExp('(1[0-2]|0?[0-9]):([0-5][0-9])');
this.inputCheck(regex, value);
} else if (showHour && showMinute && showSecond && !format12Hours) {
//validate hh:mm:ss
let regex = new RegExp('(1[0-2]|0?[0-9]):([0-5][0-9]):([0-5][0-9])');
this.inputCheck(regex, value);
}
// else if (showHour && showMinute && showSecond && !format12Hours) {
// //validate hh:mm:ss
// let regex = new RegExp('(1[0-2]|0?[0-9]):([0-5][0-9]):([0-5][0-9])');
// this.inputCheck(regex, value);
// }
};
/**
* @param {string} regex
Expand Down Expand Up @@ -353,9 +354,9 @@ export class TimePicker extends React.Component {
return { time: time, value: value };
});
};
updateTime = time => {
this.setState({ time: time });
};
// updateTime = time => {
// this.setState({ time: time });
// };
updateValue = value => {
this.setState({ value: value });
};
Expand All @@ -379,22 +380,22 @@ export class TimePicker extends React.Component {
}
return value;
};
formatPlaceHolder = () => {
let value = '';
if (this.state.showHour) {
value = 'hh';
}
if (this.state.showMinute) {
value = value ? value + ':mm' : 'mm';
}
if (this.state.showSecond) {
value = value ? value + ':ss' : 'ss';
}
if (this.state.format12Hours) {
value = value + ' am/pm';
}
return value;
};
// formatPlaceHolder = () => {
// let value = '';
// if (this.state.showHour) {
// value = 'hh';
// }
// if (this.state.showMinute) {
// value = value ? value + ':mm' : 'mm';
// }
// if (this.state.showSecond) {
// value = value ? value + ':ss' : 'ss';
// }
// if (this.state.format12Hours) {
// value = value + ' am/pm';
// }
// return value;
// };
render() {
const { id, ...props } = this.props;
const { popoverId, timeId } = this.state;
Expand Down
Loading