Descuadre de meses componente calendar #1733
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-09-26 10:43:06 +02:00
parent f28305de9b
commit ca4009088d
2 changed files with 30 additions and 16 deletions

View File

@ -259,10 +259,11 @@ export default class Calendar extends Component {
* @param {Integer} skip - Months to skip at once
*/
moveNext(skip = 1) {
let next = this.defaultDate.getMonth() + skip;
this.defaultDate.setMonth(next);
this.defaultDate.setHours(0, 0, 0, 0);
const next = this.defaultDate.getMonth() + skip;
this.defaultDate.setDate(1);
this.defaultDate.setHours(null, null, null, null);
this.defaultDate.setMonth(next);
this.repaint();
this.emit('moveNext');
@ -274,14 +275,14 @@ export default class Calendar extends Component {
* @param {Integer} skip - Months to skip at once
*/
movePrevious(skip = 1) {
let previous = this.defaultDate.getMonth() - skip;
this.defaultDate.setMonth(previous);
this.defaultDate.setHours(0, 0, 0, 0);
const previous = this.defaultDate.getMonth() - skip;
const lastDate = this.lastDay(this.defaultDate);
this.defaultDate.setDate(lastDate.getDate());
this.defaultDate.setDate(1);
this.defaultDate.setHours(null, null, null, null);
this.defaultDate.setMonth(previous);
this.repaint();
this.emit('movePrevious');
}
@ -318,14 +319,17 @@ export default class Calendar extends Component {
}
renderStyle(style) {
if (style) {
return {
'background-color': style.backgroundColor,
'font-weight': style.fontWeight,
'opacity': style.opacity,
'color': style.color
};
}
const normalizedStyle = {};
const properties = Object.keys(style);
properties.forEach(attribute => {
const attrName = attribute.split(/(?=[A-Z])/).
join('-').toLowerCase();
normalizedStyle[attrName] = style[attribute];
});
return normalizedStyle;
}
}

View File

@ -116,5 +116,15 @@ describe('Component vnCalendar', () => {
expect(controller.emit).toHaveBeenCalledWith('selection', {values: days});
});
});
describe('renderStyle()', () => {
it(`should normalize CSS attributes`, () => {
const result = controller.renderStyle({
backgroundColor: 'red'
});
expect(result['background-color']).toEqual('red');
});
});
});