Skip to content

Commit

Permalink
test: add missing test for date-picker label click (#8261)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Dec 2, 2024
1 parent 4f474c9 commit 781a58e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/date-picker/src/vaadin-date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element

/** @private */
_onVaadinOverlayClose(e) {
// Prevent closing the overlay on label element click
if (e.detail.sourceEvent && e.detail.sourceEvent.composedPath().includes(this)) {
e.preventDefault();
}
Expand Down
1 change: 1 addition & 0 deletions packages/date-picker/src/vaadin-lit-date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element

/** @private */
_onVaadinOverlayClose(e) {
// Prevent closing the overlay on label element click
if (e.detail.sourceEvent && e.detail.sourceEvent.composedPath().includes(this)) {
e.preventDefault();
}
Expand Down
26 changes: 26 additions & 0 deletions packages/date-picker/test/dropdown.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ describe('dropdown', () => {
});
});

describe('label click', () => {
let label;

beforeEach(() => {
label = datePicker.querySelector('label');
});

it('should open by clicking the label', async () => {
label.click();
await oneEvent(overlay, 'vaadin-overlay-open');
expect(datePicker.opened).to.be.true;
expect(overlay.opened).to.be.true;
});

it('should prevent overlay close on label click', async () => {
label.click();
await oneEvent(overlay, 'vaadin-overlay-open');

const spy = sinon.spy();
overlay.addEventListener('vaadin-overlay-close', spy);

label.click();
expect(spy.firstCall.args[0].defaultPrevented).to.be.true;
});
});

describe('scroll to date', () => {
it('should scroll to today by default', async () => {
datePicker.open();
Expand Down

0 comments on commit 781a58e

Please sign in to comment.