|
1 | 1 | import { expect } from '@vaadin/chai-plugins';
|
2 | 2 | import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
|
| 3 | +import { sendKeys } from '@web/test-runner-commands'; |
| 4 | +import './not-animated-styles.js'; |
| 5 | +import '@vaadin/dialog'; |
3 | 6 | import '@vaadin/notification';
|
4 | 7 | import '@vaadin/popover';
|
5 | 8 | import '@vaadin/tooltip';
|
@@ -61,4 +64,85 @@ describe('notification and overlays', () => {
|
61 | 64 | expect(popoverZIndex).to.be.above(notificationZIndex);
|
62 | 65 | });
|
63 | 66 | });
|
| 67 | + |
| 68 | + describe('notification and dialog', () => { |
| 69 | + let dialog1, dialog2, notification; |
| 70 | + |
| 71 | + beforeEach(async () => { |
| 72 | + dialog1 = fixtureSync('<vaadin-dialog></vaadin-dialog>'); |
| 73 | + await nextRender(); |
| 74 | + |
| 75 | + dialog1.renderer = (root) => { |
| 76 | + if (!root.firstChild) { |
| 77 | + notification = document.createElement('vaadin-notification'); |
| 78 | + notification.renderer = (root) => { |
| 79 | + root.textContent = 'Hello!'; |
| 80 | + }; |
| 81 | + |
| 82 | + dialog2 = document.createElement('vaadin-dialog'); |
| 83 | + dialog2.renderer = (root2) => { |
| 84 | + if (!root2.firstChild) { |
| 85 | + const close = document.createElement('button'); |
| 86 | + close.textContent = 'Close and show notification'; |
| 87 | + close.addEventListener('click', () => { |
| 88 | + console.log('close and show'); |
| 89 | + notification.opened = true; |
| 90 | + dialog2.opened = false; |
| 91 | + }); |
| 92 | + root2.appendChild(close); |
| 93 | + } |
| 94 | + }; |
| 95 | + |
| 96 | + const open = document.createElement('button'); |
| 97 | + open.setAttribute('id', 'open'); |
| 98 | + open.textContent = 'Open dialog 2'; |
| 99 | + open.addEventListener('click', () => { |
| 100 | + dialog2.opened = true; |
| 101 | + }); |
| 102 | + |
| 103 | + const show = document.createElement('button'); |
| 104 | + show.setAttribute('id', 'show'); |
| 105 | + show.textContent = 'Show notification'; |
| 106 | + show.addEventListener('click', () => { |
| 107 | + notification.opened = true; |
| 108 | + }); |
| 109 | + |
| 110 | + root.append(notification, dialog2, open, show); |
| 111 | + } |
| 112 | + }; |
| 113 | + }); |
| 114 | + |
| 115 | + afterEach(() => { |
| 116 | + notification.opened = false; |
| 117 | + }); |
| 118 | + |
| 119 | + it('should remove pointer-events when closing dialog and opening notification', async () => { |
| 120 | + dialog1.opened = true; |
| 121 | + await nextRender(); |
| 122 | + |
| 123 | + // Open dialog 2 |
| 124 | + dialog1.$.overlay.querySelector('#open').click(); |
| 125 | + await nextRender(); |
| 126 | + expect(getComputedStyle(dialog1.$.overlay.$.overlay).pointerEvents).to.equal('none'); |
| 127 | + |
| 128 | + // Close dialog 2 and show notification |
| 129 | + dialog2.$.overlay.querySelector('button').click(); |
| 130 | + await nextRender(); |
| 131 | + |
| 132 | + expect(getComputedStyle(dialog1.$.overlay.$.overlay).pointerEvents).to.equal('auto'); |
| 133 | + }); |
| 134 | + |
| 135 | + it('should allow closing the dialog on Escape press after opening notification', async () => { |
| 136 | + dialog1.opened = true; |
| 137 | + await nextRender(); |
| 138 | + |
| 139 | + // Show notification |
| 140 | + dialog1.$.overlay.querySelector('#show').click(); |
| 141 | + await nextRender(); |
| 142 | + |
| 143 | + await sendKeys({ press: 'Escape' }); |
| 144 | + |
| 145 | + expect(dialog1.opened).to.be.false; |
| 146 | + }); |
| 147 | + }); |
64 | 148 | });
|
0 commit comments