Merge pull request #808 from ing-bank/fix/flakiness-overlayctrl

fix(overlays): add protected show and hide complete hooks,fix flaky test
This commit is contained in:
Thijs Louisse 2020-07-09 12:34:15 +02:00 committed by GitHub
commit 5a50ab5977
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View file

@ -419,11 +419,16 @@ export class OverlayController {
* @param {HTMLElement} elementToFocusAfterHide * @param {HTMLElement} elementToFocusAfterHide
*/ */
async show(elementToFocusAfterHide = this.elementToFocusAfterHide) { async show(elementToFocusAfterHide = this.elementToFocusAfterHide) {
this._showComplete = new Promise(resolve => {
this._showResolve = resolve;
});
if (this.manager) { if (this.manager) {
this.manager.show(this); this.manager.show(this);
} }
if (this.isShown) { if (this.isShown) {
this._showResolve();
return; return;
} }
@ -438,6 +443,7 @@ export class OverlayController {
this.elementToFocusAfterHide = elementToFocusAfterHide; this.elementToFocusAfterHide = elementToFocusAfterHide;
this.dispatchEvent(new Event('show')); this.dispatchEvent(new Event('show'));
} }
this._showResolve();
} }
async _handlePosition({ phase }) { async _handlePosition({ phase }) {
@ -510,11 +516,16 @@ export class OverlayController {
* @event hide right after the overlay is hidden * @event hide right after the overlay is hidden
*/ */
async hide() { async hide() {
this._hideComplete = new Promise(resolve => {
this._hideResolve = resolve;
});
if (this.manager) { if (this.manager) {
this.manager.hide(this); this.manager.hide(this);
} }
if (!this.isShown) { if (!this.isShown) {
this._hideResolve();
return; return;
} }
@ -528,6 +539,7 @@ export class OverlayController {
this.dispatchEvent(new Event('hide')); this.dispatchEvent(new Event('hide'));
this._restoreFocus(); this._restoreFocus();
} }
this._hideResolve();
} }
// eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars // eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars

View file

@ -29,18 +29,15 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
</${tag}> </${tag}>
`); `);
el.opened = true; el.opened = true;
expect(el.opened).to.be.true;
await el.updateComplete; await el.updateComplete;
if (el.repositionComplete) { await el._overlayCtrl._showComplete;
await el.repositionComplete; expect(el.opened).to.be.true;
}
await nextFrame(); // overlayCtrl show/hide is async
expect(el._overlayCtrl.isShown).to.be.true; expect(el._overlayCtrl.isShown).to.be.true;
el.opened = false; el.opened = false;
expect(el.opened).to.be.false;
await el.updateComplete; await el.updateComplete;
await nextFrame(); // overlayCtrl show/hide is async await el._overlayCtrl._hideComplete;
expect(el.opened).to.be.false;
expect(el._overlayCtrl.isShown).to.be.false; expect(el._overlayCtrl.isShown).to.be.false;
}); });