|
1 | 1 | import { expect } from '@vaadin/chai-plugins'; |
2 | 2 | import { sendKeys, setViewport } from '@vaadin/test-runner-commands'; |
3 | | -import { aTimeout, fixtureSync, nextRender, outsideClick, tabKeyDown, tap } from '@vaadin/testing-helpers'; |
| 3 | +import { aTimeout, fixtureSync, nextRender, nextUpdate, outsideClick, tabKeyDown, tap } from '@vaadin/testing-helpers'; |
4 | 4 | import sinon from 'sinon'; |
5 | 5 | import '../src/vaadin-date-picker.js'; |
6 | 6 | import { getFocusableCell, open, touchTap, untilOverlayRendered } from './helpers.js'; |
@@ -156,6 +156,60 @@ describe('fullscreen mode', () => { |
156 | 156 | }); |
157 | 157 | }); |
158 | 158 |
|
| 159 | + describe('validation', () => { |
| 160 | + let validateSpy; |
| 161 | + |
| 162 | + beforeEach(async () => { |
| 163 | + datePicker.required = true; |
| 164 | + await nextUpdate(datePicker); |
| 165 | + validateSpy = sinon.spy(datePicker, 'validate'); |
| 166 | + }); |
| 167 | + |
| 168 | + it('should not validate when focusing the input', () => { |
| 169 | + input.focus(); |
| 170 | + expect(validateSpy.called).to.be.false; |
| 171 | + expect(datePicker.invalid).to.be.false; |
| 172 | + }); |
| 173 | + |
| 174 | + it('should not validate when opening overlay on input tap', async () => { |
| 175 | + input.focus(); |
| 176 | + tap(input); |
| 177 | + await untilOverlayRendered(datePicker); |
| 178 | + expect(validateSpy.called).to.be.false; |
| 179 | + expect(datePicker.invalid).to.be.false; |
| 180 | + }); |
| 181 | + |
| 182 | + it('should validate when closing overlay on outside click', async () => { |
| 183 | + await open(datePicker); |
| 184 | + validateSpy.resetHistory(); |
| 185 | + |
| 186 | + outsideClick(); |
| 187 | + await nextRender(); |
| 188 | + |
| 189 | + expect(validateSpy.called).to.be.true; |
| 190 | + expect(datePicker.invalid).to.be.true; |
| 191 | + }); |
| 192 | + |
| 193 | + it('should validate on blur after the input has been blurred internally', async () => { |
| 194 | + input.focus(); |
| 195 | + tap(input); |
| 196 | + await untilOverlayRendered(datePicker); |
| 197 | + datePicker.close(); |
| 198 | + await nextRender(); |
| 199 | + |
| 200 | + // Make the input focusable |
| 201 | + datePicker.autoOpenDisabled = true; |
| 202 | + await nextUpdate(datePicker); |
| 203 | + validateSpy.resetHistory(); |
| 204 | + |
| 205 | + input.focus(); |
| 206 | + input.blur(); |
| 207 | + |
| 208 | + expect(validateSpy.called).to.be.true; |
| 209 | + expect(datePicker.invalid).to.be.true; |
| 210 | + }); |
| 211 | + }); |
| 212 | + |
159 | 213 | describe('buttons', () => { |
160 | 214 | let overlayContent; |
161 | 215 |
|
|
0 commit comments