|
1 | 1 | import { expect } from '@esm-bundle/chai'; |
2 | 2 | import { aTimeout, esc, fixtureSync, oneEvent } from '@vaadin/testing-helpers'; |
| 3 | +import sinon from 'sinon'; |
3 | 4 | import '../vaadin-dialog.js'; |
4 | 5 | import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js'; |
5 | 6 |
|
@@ -113,19 +114,44 @@ describe('vaadin-dialog', () => { |
113 | 114 | }); |
114 | 115 | }); |
115 | 116 |
|
116 | | - describe('detaching', () => { |
117 | | - it('should close the overlay when detached', () => { |
118 | | - dialog.parentNode.removeChild(dialog); |
| 117 | + describe('removing and adding to the DOM', () => { |
| 118 | + it('should close the overlay when removed from DOM', async () => { |
| 119 | + dialog.remove(); |
| 120 | + await aTimeout(0); |
| 121 | + |
| 122 | + expect(dialog.opened).to.be.false; |
| 123 | + }); |
| 124 | + |
| 125 | + it('should restore opened state when added to the DOM', async () => { |
| 126 | + const parent = dialog.parentNode; |
| 127 | + dialog.remove(); |
| 128 | + await aTimeout(0); |
119 | 129 | expect(dialog.opened).to.be.false; |
| 130 | + |
| 131 | + parent.appendChild(dialog); |
| 132 | + expect(dialog.opened).to.be.true; |
120 | 133 | }); |
121 | 134 |
|
122 | | - it('should not close the overlay when moved within the DOM', () => { |
| 135 | + it('should not close the overlay when moved within the DOM', async () => { |
123 | 136 | const newParent = document.createElement('div'); |
124 | 137 | document.body.appendChild(newParent); |
125 | | - |
126 | 138 | newParent.appendChild(dialog); |
| 139 | + await aTimeout(0); |
| 140 | + |
127 | 141 | expect(dialog.opened).to.be.true; |
128 | 142 | }); |
| 143 | + |
| 144 | + it('should not dispatch opened changed events when moved within the DOM', async () => { |
| 145 | + const onOpenedChanged = sinon.spy(); |
| 146 | + dialog.addEventListener('opened-changed', onOpenedChanged); |
| 147 | + |
| 148 | + const newParent = document.createElement('div'); |
| 149 | + document.body.appendChild(newParent); |
| 150 | + newParent.appendChild(dialog); |
| 151 | + await aTimeout(0); |
| 152 | + |
| 153 | + expect(onOpenedChanged.called).to.be.false; |
| 154 | + }); |
129 | 155 | }); |
130 | 156 |
|
131 | 157 | describe('modeless', () => { |
|
0 commit comments