Skip to content

Commit bdb485e

Browse files
authored
test: update dialog tests to pass with the Lit based version (#6155)
1 parent abf5ff7 commit bdb485e

4 files changed

Lines changed: 116 additions & 40 deletions

File tree

‎packages/dialog/test/dialog.test.js‎

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { aTimeout, esc, fixtureSync, oneEvent } from '@vaadin/testing-helpers';
2+
import { aTimeout, click, esc, fixtureSync, nextRender, nextUpdate } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import '../vaadin-dialog.js';
55
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js';
@@ -25,8 +25,9 @@ describe('vaadin-dialog', () => {
2525
describe('host element', () => {
2626
let dialog;
2727

28-
beforeEach(() => {
28+
beforeEach(async () => {
2929
dialog = fixtureSync('<vaadin-dialog></vaadin-dialog>');
30+
await nextRender();
3031
});
3132

3233
it('should enforce display: none to hide the host element', () => {
@@ -38,48 +39,62 @@ describe('vaadin-dialog', () => {
3839
describe('opened', () => {
3940
let dialog, backdrop, overlay;
4041

41-
beforeEach(() => {
42+
beforeEach(async () => {
4243
dialog = fixtureSync(`
4344
<vaadin-dialog opened theme="foo"></vaadin-dialog>
4445
`);
46+
await nextRender();
4547

4648
dialog.renderer = (root) => {
4749
root.innerHTML = '<div>Simple dialog</div>';
4850
};
51+
await nextUpdate(dialog);
4952

5053
overlay = dialog.$.overlay;
5154
backdrop = overlay.$.backdrop;
5255
});
5356

57+
afterEach(async () => {
58+
dialog.opened = false;
59+
await nextRender();
60+
});
61+
5462
describe('attributes', () => {
5563
it('overlay should have the `dialog` role', () => {
5664
expect(overlay.getAttribute('role')).to.be.eql('dialog');
5765
});
5866

59-
it('overlay should have the `aria-label` attribute (if set)', () => {
67+
it('overlay should have the `aria-label` attribute (if set)', async () => {
6068
dialog.ariaLabel = 'accessible';
69+
await nextUpdate(dialog);
6170
expect(overlay.getAttribute('aria-label')).to.be.eql('accessible');
6271
});
6372

6473
it('overlay should not have the `aria-label` attribute (if not set)', () => {
6574
expect(overlay.getAttribute('aria-label')).to.be.null;
6675
});
6776

68-
it('overlay should not have `aria-label` attribute if set to undefined', () => {
77+
it('overlay should not have `aria-label` attribute if set to undefined', async () => {
6978
dialog.ariaLabel = 'accessible';
79+
await nextUpdate(dialog);
7080
dialog.ariaLabel = undefined;
81+
await nextUpdate(dialog);
7182
expect(overlay.getAttribute('aria-label')).to.be.null;
7283
});
7384

74-
it('overlay should not have `aria-label` attribute if set to null', () => {
85+
it('overlay should not have `aria-label` attribute if set to null', async () => {
7586
dialog.ariaLabel = 'accessible';
87+
await nextUpdate(dialog);
7688
dialog.ariaLabel = null;
89+
await nextUpdate(dialog);
7790
expect(overlay.getAttribute('aria-label')).to.be.null;
7891
});
7992

80-
it('overlay should not have `aria-label` attribute if set to empty string', () => {
93+
it('overlay should not have `aria-label` attribute if set to empty string', async () => {
8194
dialog.ariaLabel = 'accessible';
95+
await nextUpdate(dialog);
8296
dialog.ariaLabel = '';
97+
await nextUpdate(dialog);
8398
expect(overlay.getAttribute('aria-label')).to.be.null;
8499
});
85100

@@ -89,28 +104,33 @@ describe('vaadin-dialog', () => {
89104
});
90105

91106
describe('no-close-on-esc', () => {
92-
it('should close itself on ESC press by default', () => {
107+
it('should close itself on ESC press by default', async () => {
93108
esc(document.body);
94-
expect(dialog.opened).to.eql(false);
109+
await nextUpdate(dialog);
110+
expect(dialog.opened).to.be.false;
95111
});
96112

97-
it('should not close itself on ESC press when no-close-on-esc is true', () => {
113+
it('should not close itself on ESC press when no-close-on-esc is true', async () => {
98114
dialog.noCloseOnEsc = true;
115+
await nextUpdate(dialog);
99116
esc(document.body);
100-
expect(dialog.opened).to.eql(true);
117+
expect(dialog.opened).to.be.true;
101118
});
102119
});
103120

104121
describe('no-close-on-outside-click', () => {
105-
it('should close itself on outside click by default', () => {
106-
backdrop.dispatchEvent(new CustomEvent('click', { bubbles: true, composed: true }));
107-
expect(dialog.opened).to.eql(false);
122+
it('should close itself on outside click by default', async () => {
123+
click(backdrop);
124+
await nextUpdate(dialog);
125+
expect(dialog.opened).to.be.false;
108126
});
109127

110-
it('should not close itself on outside click when no-close-on-outside-click is true', () => {
128+
it('should not close itself on outside click when no-close-on-outside-click is true', async () => {
111129
dialog.noCloseOnOutsideClick = true;
112-
backdrop.dispatchEvent(new CustomEvent('click', { bubbles: true, composed: true }));
113-
expect(dialog.opened).to.eql(true);
130+
await nextUpdate(dialog);
131+
click(backdrop);
132+
await nextUpdate(dialog);
133+
expect(dialog.opened).to.be.true;
114134
});
115135
});
116136

@@ -160,8 +180,9 @@ describe('vaadin-dialog', () => {
160180
expect(backdrop.hidden).to.be.false;
161181
});
162182

163-
it('should not be modal when modeless is true', () => {
183+
it('should not be modal when modeless is true', async () => {
164184
dialog.modeless = true;
185+
await nextUpdate(dialog);
165186
expect(overlay.modeless).to.be.true;
166187
expect(backdrop.hidden).to.be.true;
167188
});
@@ -171,8 +192,14 @@ describe('vaadin-dialog', () => {
171192
describe('without renderer', () => {
172193
let dialog;
173194

174-
beforeEach(() => {
195+
beforeEach(async () => {
175196
dialog = fixtureSync('<vaadin-dialog></vaadin-dialog>');
197+
await nextRender();
198+
});
199+
200+
afterEach(async () => {
201+
dialog.opened = false;
202+
await nextRender();
176203
});
177204

178205
it('should not throw an exception if renderer is not present', () => {
@@ -182,8 +209,9 @@ describe('vaadin-dialog', () => {
182209
expect(openDialog).to.not.throw();
183210
});
184211

185-
it('should have min-width for content', () => {
212+
it('should have min-width for content', async () => {
186213
dialog.opened = true;
214+
await nextRender();
187215
const contentMinWidth = parseFloat(getComputedStyle(dialog.$.overlay.$.content).minWidth);
188216
expect(contentMinWidth).to.be.gt(0);
189217
});
@@ -192,29 +220,35 @@ describe('vaadin-dialog', () => {
192220
describe('focus restoration', () => {
193221
let dialog, button, overlay;
194222

195-
beforeEach(() => {
223+
beforeEach(async () => {
196224
const wrapper = fixtureSync(`
197225
<div>
198226
<vaadin-dialog></vaadin-dialog>
199227
<button></button>
200228
</div>
201229
`);
202230
[dialog, button] = wrapper.children;
231+
await nextRender();
203232
overlay = dialog.$.overlay;
204233
button.focus();
205234
});
206235

236+
afterEach(async () => {
237+
dialog.opened = false;
238+
await nextRender();
239+
});
240+
207241
it('should move focus to the dialog on open', async () => {
208242
dialog.opened = true;
209-
await oneEvent(overlay, 'vaadin-overlay-open');
243+
await nextRender();
210244
expect(getDeepActiveElement()).to.equal(overlay.$.overlay);
211245
});
212246

213247
it('should restore focus on dialog close', async () => {
214248
dialog.opened = true;
215-
await oneEvent(overlay, 'vaadin-overlay-open');
249+
await nextRender();
216250
dialog.opened = false;
217-
await aTimeout(0);
251+
await nextRender();
218252
expect(getDeepActiveElement()).to.equal(button);
219253
});
220254
});

‎packages/dialog/test/draggable-resizable.test.js‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextFrame, nextRender, nextUpdate } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import '@vaadin/text-area/vaadin-text-area.js';
55
import './not-animated-styles.js';
@@ -63,11 +63,12 @@ describe('helper methods', () => {
6363
dialog1.renderer = (root) => {
6464
root.innerHTML = '<div>Modeless dialog 1</div>';
6565
};
66-
66+
await nextUpdate(dialog1);
6767
dialog2 = dialogs[1];
6868
dialog2.renderer = (root) => {
6969
root.innerHTML = '<div>Modeless dialog 2</div>';
7070
};
71+
await nextUpdate(dialog2);
7172
overlay = dialog1.$.overlay;
7273
overlayPart = overlay.$.overlay;
7374
container = overlay.$.resizerContainer;
@@ -102,8 +103,9 @@ describe('helper methods', () => {
102103
expect(dialog1.$.overlay._last).to.be.true;
103104
});
104105

105-
it('should not move to top if not modeless', () => {
106+
it('should not move to top if not modeless', async () => {
106107
dialog1.modeless = false;
108+
await nextUpdate(dialog1);
107109
const spy = sinon.spy(dialog1.$.overlay, 'bringToFront');
108110
dispatchMouseEvent(container, 'mousedown');
109111
expect(spy.called).to.be.false;
@@ -116,12 +118,14 @@ describe('resizable', () => {
116118

117119
beforeEach(async () => {
118120
dialog = fixtureSync(`
119-
<vaadin-dialog resizable opened modeless></vaadin-dialog>
121+
<vaadin-dialog resizable modeless></vaadin-dialog>
120122
`);
121123
await nextRender();
122124
dialog.renderer = (root) => {
123125
root.innerHTML = '<div>Resizable dialog</div>';
124126
};
127+
dialog.opened = true;
128+
await nextRender();
125129
overlayPart = dialog.$.overlay.$.overlay;
126130
bounds = overlayPart.getBoundingClientRect();
127131
dx = 30;
@@ -349,7 +353,7 @@ describe('draggable', () => {
349353

350354
beforeEach(async () => {
351355
dialog = fixtureSync(`
352-
<vaadin-dialog draggable opened modeless></vaadin-dialog>
356+
<vaadin-dialog draggable modeless></vaadin-dialog>
353357
`);
354358
await nextRender();
355359
dialog.renderer = (root) => {
@@ -360,6 +364,10 @@ describe('draggable', () => {
360364
<button>OK</button>
361365
`;
362366
};
367+
await nextUpdate(dialog);
368+
369+
dialog.opened = true;
370+
await nextRender();
363371

364372
container = dialog.$.overlay.$.resizerContainer;
365373
content = dialog.$.overlay.$.content;
@@ -522,7 +530,7 @@ describe('draggable', () => {
522530
dialog.modeless = true;
523531
button.style.marginBottom = '200px';
524532
dialog.$.overlay.setBounds({ height: '100px' });
525-
await nextFrame();
533+
await nextUpdate(dialog);
526534
container.scrollTop = 100;
527535
expect(container.scrollTop).to.equal(100);
528536
drag(container);
@@ -614,6 +622,7 @@ describe('touch', () => {
614622
<button>OK</button>
615623
`;
616624
};
625+
await nextRender();
617626

618627
resizableOverlay = resizable.$.overlay;
619628
draggableOverlay = draggable.$.overlay;
@@ -705,13 +714,14 @@ describe('touch', () => {
705714
describe('bring to front', () => {
706715
let wrapper, modalDialog, modelessDialog;
707716

708-
beforeEach(() => {
717+
beforeEach(async () => {
709718
wrapper = fixtureSync(`
710719
<div>
711720
<vaadin-dialog id="modalDialog"></vaadin-dialog>
712721
<vaadin-dialog id="modelessDialog" modeless></vaadin-dialog>
713722
</div>
714723
`);
724+
await nextRender();
715725
[modalDialog, modelessDialog] = wrapper.children;
716726

717727
modalDialog.renderer = (root) => {

0 commit comments

Comments
 (0)