From 4f474c972bc7d2af97413d143af38656f0dbf1f0 Mon Sep 17 00:00:00 2001 From: Serhii Kulykov Date: Mon, 2 Dec 2024 16:12:09 +0200 Subject: [PATCH] test: update date-picker tests to not use async close helper (#8260) --- packages/date-picker/test/basic.common.js | 6 +++--- packages/date-picker/test/events.common.js | 6 +++--- packages/date-picker/test/helpers.js | 9 +-------- packages/date-picker/test/keyboard-input.common.js | 7 +++---- packages/date-picker/test/validation.common.js | 4 ++-- packages/date-picker/test/wai-aria.common.js | 6 +++--- packages/field-highlighter/test/field-components.test.js | 8 ++++---- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/packages/date-picker/test/basic.common.js b/packages/date-picker/test/basic.common.js index 8bda9279e1..887c0b2cd8 100644 --- a/packages/date-picker/test/basic.common.js +++ b/packages/date-picker/test/basic.common.js @@ -3,7 +3,7 @@ import { click, fixtureSync, keyboardEventFor, nextRender, oneEvent, tap } from import { sendKeys } from '@web/test-runner-commands'; import sinon from 'sinon'; import { parseDate } from '../src/vaadin-date-picker-helper.js'; -import { close, open, touchTap, waitForOverlayRender } from './helpers.js'; +import { open, touchTap, waitForOverlayRender } from './helpers.js'; describe('basic features', () => { let datePicker, input, overlay; @@ -60,13 +60,13 @@ describe('basic features', () => { datePicker.addEventListener('opened-changed', spy); await open(datePicker); expect(spy.calledOnce).to.be.true; - await close(datePicker); + datePicker.close(); expect(spy.calledTwice).to.be.true; }); it('should set opened to false with close call', async () => { await open(datePicker); - await close(datePicker); + datePicker.close(); expect(datePicker.opened).to.be.false; }); diff --git a/packages/date-picker/test/events.common.js b/packages/date-picker/test/events.common.js index b1cf887578..2aadaa57b5 100644 --- a/packages/date-picker/test/events.common.js +++ b/packages/date-picker/test/events.common.js @@ -2,7 +2,7 @@ import { expect } from '@vaadin/chai-plugins'; import { fixtureSync, nextRender } from '@vaadin/testing-helpers'; import { sendKeys } from '@web/test-runner-commands'; import sinon from 'sinon'; -import { close, open, waitForOverlayRender, waitForScrollToFinish } from './helpers.js'; +import { open, waitForOverlayRender, waitForScrollToFinish } from './helpers.js'; describe('events', () => { let datePicker; @@ -21,7 +21,7 @@ describe('events', () => { it('should not be fired on programmatic value change when opened', async () => { await open(datePicker); datePicker.value = '2000-01-01'; - await close(datePicker); + datePicker.close(); expect(changeSpy.called).to.be.false; }); @@ -29,7 +29,7 @@ describe('events', () => { await sendKeys({ type: '1/2/2000' }); await waitForScrollToFinish(datePicker); datePicker.value = '2000-01-01'; - await close(datePicker); + datePicker.close(); expect(changeSpy.called).to.be.false; }); }); diff --git a/packages/date-picker/test/helpers.js b/packages/date-picker/test/helpers.js index 128e6ed0ec..6ea039f2e4 100644 --- a/packages/date-picker/test/helpers.js +++ b/packages/date-picker/test/helpers.js @@ -1,4 +1,4 @@ -import { fire, listenOnce, makeSoloTouchEvent, nextRender } from '@vaadin/testing-helpers'; +import { fire, makeSoloTouchEvent, nextRender } from '@vaadin/testing-helpers'; import { flush } from '@polymer/polymer/lib/utils/flush.js'; import { afterNextRender } from '@polymer/polymer/lib/utils/render-status.js'; import { isElementFocused } from '@vaadin/a11y-base/src/focus-utils.js'; @@ -60,13 +60,6 @@ export async function open(datePicker) { await waitForOverlayRender(); } -export function close(datePicker) { - return new Promise((resolve) => { - listenOnce(datePicker.$.overlay, 'vaadin-overlay-close', resolve); - datePicker.close(); - }); -} - export function idleCallback() { return new Promise((resolve) => { if (window.requestIdleCallback) { diff --git a/packages/date-picker/test/keyboard-input.common.js b/packages/date-picker/test/keyboard-input.common.js index cae25b31ae..f05dd65cf8 100644 --- a/packages/date-picker/test/keyboard-input.common.js +++ b/packages/date-picker/test/keyboard-input.common.js @@ -4,7 +4,6 @@ import { sendKeys } from '@web/test-runner-commands'; import sinon from 'sinon'; import { formatISODate, getAdjustedYear, parseDate } from '../src/vaadin-date-picker-helper.js'; import { - close, getFocusableCell, getFocusedCell, idleCallback, @@ -145,7 +144,7 @@ describe('keyboard', () => { it('should select focused date on close', async () => { await open(datePicker); - await close(datePicker); + datePicker.close(); expect(datePicker._selectedDate).to.equal(datePicker._focusedDate); }); }); @@ -292,10 +291,10 @@ describe('keyboard', () => { expect(spy.called).to.be.true; }); - it('should clear selection on close', async () => { + it('should clear selection on close', () => { input.select(); - await close(datePicker); + datePicker.close(); expect(input.selectionStart).to.equal(input.selectionEnd); }); diff --git a/packages/date-picker/test/validation.common.js b/packages/date-picker/test/validation.common.js index a02096b30c..f15cca0d12 100644 --- a/packages/date-picker/test/validation.common.js +++ b/packages/date-picker/test/validation.common.js @@ -1,7 +1,7 @@ import { expect } from '@vaadin/chai-plugins'; import { enter, fixtureSync, nextRender, nextUpdate } from '@vaadin/testing-helpers'; import sinon from 'sinon'; -import { close, open, setInputValue, waitForOverlayRender } from './helpers.js'; +import { open, setInputValue, waitForOverlayRender } from './helpers.js'; class DatePicker2016 extends customElements.get('vaadin-date-picker') { checkValidity() { @@ -133,7 +133,7 @@ describe('validation', () => { expect(datePicker.validate()).to.be.false; await open(datePicker); datePicker.value = '2000-02-01'; - await close(datePicker); + datePicker.close(); expect(datePicker.invalid).to.be.false; }); diff --git a/packages/date-picker/test/wai-aria.common.js b/packages/date-picker/test/wai-aria.common.js index 2ff2dd1b1c..d15da14223 100644 --- a/packages/date-picker/test/wai-aria.common.js +++ b/packages/date-picker/test/wai-aria.common.js @@ -1,6 +1,6 @@ import { expect } from '@vaadin/chai-plugins'; import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers'; -import { activateScroller, close, getDefaultI18n, open } from './helpers.js'; +import { activateScroller, getDefaultI18n, open } from './helpers.js'; describe('WAI-ARIA', () => { describe('date picker', () => { @@ -15,7 +15,7 @@ describe('WAI-ARIA', () => { it('should toggle aria-expanded attribute on open', async () => { await open(datePicker); expect(input.getAttribute('aria-expanded')).to.equal('true'); - await close(datePicker); + datePicker.close(); expect(input.getAttribute('aria-expanded')).to.equal('false'); }); @@ -113,7 +113,7 @@ describe('WAI-ARIA', () => { it('should remove aria-hidden from other elements when overlay is closed', async () => { await open(datePicker); - await close(datePicker); + datePicker.close(); expect(button.hasAttribute('aria-hidden')).to.be.false; expect(input.hasAttribute('aria-hidden')).to.be.false; }); diff --git a/packages/field-highlighter/test/field-components.test.js b/packages/field-highlighter/test/field-components.test.js index 2d701d0dab..2991e97757 100644 --- a/packages/field-highlighter/test/field-components.test.js +++ b/packages/field-highlighter/test/field-components.test.js @@ -11,7 +11,7 @@ import '@vaadin/radio-group'; import '@vaadin/select'; import '@vaadin/text-field'; import { html, render } from 'lit'; -import { close, waitForOverlayRender } from '@vaadin/date-picker/test/helpers.js'; +import { waitForOverlayRender } from '@vaadin/date-picker/test/helpers.js'; import { FieldHighlighter } from '../src/vaadin-field-highlighter.js'; async function waitForIntersectionObserver() { @@ -93,7 +93,7 @@ describe('field components', () => { field.focus(); await open(field); await waitForOverlayRender(); - await close(field); + field.close(); expect(hideSpy.callCount).to.equal(0); }); @@ -102,7 +102,7 @@ describe('field components', () => { await waitForOverlayRender(); field.focus(); - await close(field); + field.close(); expect(hideSpy.callCount).to.equal(0); }); @@ -477,7 +477,7 @@ describe('field components', () => { // Focus date element and then time-picker await date._overlayContent.focusDateElement(); time.focus(); - await close(date); + date.close(); expect(hideSpy.callCount).to.equal(1); expect(hideSpy.firstCall.args[0].detail.fieldIndex).to.equal(0);