2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-08 20:42:28 +03:00

fix: when custom formatting causes the time-panel error (#377)

This commit is contained in:
mengxiong10
2019-11-21 18:24:51 +08:00
parent 742c4083ea
commit bf949afc7d
2 changed files with 19 additions and 3 deletions
+14
View File
@@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils';
import TimePanel from '../src/time/time-panel';
import ListColumns from '../src/time/list-columns.vue';
let wrapper;
@@ -96,4 +97,17 @@ describe('TimePanel', () => {
hour.trigger('click');
expect(wrapper.emitted().select).toBeUndefined();
});
it('fix: when the custom format pass into time panel', () => {
wrapper = mount(TimePanel, {
propsData: {
value: new Date(),
format: {},
},
});
const cols = wrapper.find(ListColumns);
expect(cols.props('showHour')).toBe(true);
expect(cols.props('showMinute')).toBe(true);
expect(cols.props('showSecond')).toBe(true);
});
});
+5 -3
View File
@@ -11,7 +11,7 @@
:date="innerValue"
:get-classes="getClasses"
:options="timePickerOptions"
:format="format"
:format="innerForamt"
@select="handleSelect"
></list-options>
<list-columns
@@ -53,7 +53,6 @@ export default {
},
},
format: {
type: String,
default: 'HH:mm:ss',
},
timeTitleFormat: {
@@ -115,8 +114,11 @@ export default {
const date = new Date(this.innerValue);
return this.formatDate(date, titleFormat);
},
innerForamt() {
return typeof this.format === 'string' ? this.format : 'HH:mm:ss';
},
ShowHourMinuteSecondAMPM() {
const { format } = this;
const format = this.innerForamt;
const defaultProps = {
showHour: /[HhKk]/.test(format),
showMinute: /m/.test(format),