|
| 1 | +import { expect } from '@vaadin/chai-plugins'; |
| 2 | +import { sendKeys } from '@vaadin/test-runner-commands'; |
| 3 | +import { fixtureSync, nextRender } from '@vaadin/testing-helpers'; |
| 4 | +import './not-animated-styles.js'; |
| 5 | +import '@vaadin/dialog/src/vaadin-dialog.js'; |
| 6 | +import '@vaadin/notification/src/vaadin-notification.js'; |
| 7 | + |
| 8 | +describe('notification and dialog', () => { |
| 9 | + let dialog, dialogInput, notification, notificationInput; |
| 10 | + |
| 11 | + beforeEach(async () => { |
| 12 | + const container = fixtureSync(` |
| 13 | + <div> |
| 14 | + <vaadin-dialog></vaadin-dialog> |
| 15 | + <vaadin-notification></vaadin-notification> |
| 16 | + </div> |
| 17 | + `); |
| 18 | + dialog = container.querySelector('vaadin-dialog'); |
| 19 | + dialog.renderer = (root) => { |
| 20 | + if (root.firstElementChild) { |
| 21 | + return; |
| 22 | + } |
| 23 | + dialogInput = document.createElement('input'); |
| 24 | + root.append(dialogInput); |
| 25 | + }; |
| 26 | + dialog.opened = true; |
| 27 | + |
| 28 | + notification = container.querySelector('vaadin-notification'); |
| 29 | + notification.renderer = (root) => { |
| 30 | + if (root.firstElementChild) { |
| 31 | + return; |
| 32 | + } |
| 33 | + notificationInput = document.createElement('input'); |
| 34 | + root.append(notificationInput); |
| 35 | + }; |
| 36 | + notification.opened = true; |
| 37 | + |
| 38 | + await nextRender(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should prevent the dialog from closing when pressing Escape in the notification', async () => { |
| 42 | + notificationInput.focus(); |
| 43 | + await sendKeys({ press: 'Escape' }); |
| 44 | + |
| 45 | + expect(dialog.opened).to.be.true; |
| 46 | + }); |
| 47 | + |
| 48 | + it('should allow the dialog to close when pressing Escape in the dialog', async () => { |
| 49 | + dialogInput.focus(); |
| 50 | + await sendKeys({ press: 'Escape' }); |
| 51 | + |
| 52 | + expect(dialog.opened).to.be.false; |
| 53 | + }); |
| 54 | + |
| 55 | + it('should prevent the dialog from closing when clicking in the notification', () => { |
| 56 | + notificationInput.click(); |
| 57 | + |
| 58 | + expect(dialog.opened).to.be.true; |
| 59 | + }); |
| 60 | + |
| 61 | + it('should allow the dialog to close when clicking outside', () => { |
| 62 | + document.body.click(); |
| 63 | + |
| 64 | + expect(dialog.opened).to.be.false; |
| 65 | + }); |
| 66 | +}); |
0 commit comments