Skip to content

Commit

Permalink
refactor: update time-picker observer to not use Polymer syntax (#8077)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Nov 1, 2024
1 parent 1faa71f commit 92cf750
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/time-picker/src/vaadin-time-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
static get observers() {
return [
'__updateAriaAttributes(__dropdownItems, opened, inputElement)',
'__updateDropdownItems(i18n.*, min, max, step)',
'__updateDropdownItems(i18n, min, max, step)',
];
}

Expand Down Expand Up @@ -589,7 +589,7 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
}

/** @private */
__updateDropdownItems(_i18n, min, max, step) {
__updateDropdownItems(i18n, min, max, step) {
const minTimeObj = validateTime(parseISOTime(min || MIN_ALLOWED_TIME), step);
const minSec = this.__getSec(minTimeObj);

Expand All @@ -605,7 +605,7 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
}

if (this.value) {
this._comboBoxValue = this.i18n.formatTime(this.i18n.parseTime(this.value));
this._comboBoxValue = i18n.formatTime(i18n.parseTime(this.value));
}
}

Expand Down
18 changes: 9 additions & 9 deletions packages/time-picker/test/time-picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,39 +391,39 @@ describe('time-picker', () => {

describe('custom functions', () => {
it('should use custom parser if that exists', () => {
timePicker.set('i18n.parseTime', sinon.stub().returns({ hours: 12, minutes: 0, seconds: 0 }));
timePicker.i18n = { ...timePicker.i18n, parseTime: sinon.stub().returns({ hours: 12, minutes: 0, seconds: 0 }) };
timePicker.value = '12';
expect(timePicker.i18n.parseTime.args[0][0]).to.be.equal('12:00');
expect(timePicker.value).to.be.equal('12:00');
});

it('should align values of dropdown and input when i18n was reassigned', () => {
timePicker.value = '12';
timePicker.set('i18n', {
timePicker.i18n = {
formatTime: sinon.stub().withArgs({ hours: 12, minutes: 0 }).returns('12:00 AM'),
parseTime: sinon.stub().returns({ hours: 12, minutes: 0, seconds: 0 }),
});
};
expect(comboBox.selectedItem).to.be.deep.equal({ label: '12:00 AM', value: '12:00 AM' });
expect(comboBox.value).to.be.equal('12:00 AM');
expect(inputElement.value).to.be.equal('12:00 AM');
expect(timePicker.value).to.be.equal('12:00');
});

it('should use custom formatter if that exists', () => {
timePicker.set('i18n', {
timePicker.i18n = {
formatTime: sinon.stub().withArgs({ hours: 12, minutes: 0 }).returns('12:00 AM'),
parseTime: sinon.stub().returns({ hours: 12, minutes: 0, seconds: 0 }),
});
};
timePicker.value = '12';
expect(timePicker.value).to.be.equal('12:00');
expect(comboBox.value).to.be.equal('12:00 AM');
});

it('should accept custom time formatter', () => {
timePicker.set('i18n.formatTime', sinon.stub().returns('1200'));
const parseTime = sinon.stub();
parseTime.withArgs('1200').returns({ hours: 12, minutes: 0 });
timePicker.set('i18n.parseTime', parseTime);
timePicker.i18n = {
formatTime: sinon.stub().returns('1200'),
parseTime: sinon.stub().withArgs('1200').returns({ hours: 12, minutes: 0 }),
};
timePicker.value = '12:00';
expect(inputElement.value).to.equal('1200');
expect(timePicker.value).to.equal('12:00');
Expand Down

0 comments on commit 92cf750

Please sign in to comment.