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
*/
async show(elementToFocusAfterHide = this.elementToFocusAfterHide) {
this._showComplete = new Promise(resolve => {
this._showResolve = resolve;
});
if (this.manager) {
this.manager.show(this);
}
if (this.isShown) {
this._showResolve();
return;
}
@ -438,6 +443,7 @@ export class OverlayController {
this.elementToFocusAfterHide = elementToFocusAfterHide;
this.dispatchEvent(new Event('show'));
}
this._showResolve();
}
async _handlePosition({ phase }) {
@ -510,11 +516,16 @@ export class OverlayController {
* @event hide right after the overlay is hidden
*/
async hide() {
this._hideComplete = new Promise(resolve => {
this._hideResolve = resolve;
});
if (this.manager) {
this.manager.hide(this);
}
if (!this.isShown) {
this._hideResolve();
return;
}
@ -528,6 +539,7 @@ export class OverlayController {
this.dispatchEvent(new Event('hide'));
this._restoreFocus();
}
this._hideResolve();
}
// 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}>
`);
el.opened = true;
expect(el.opened).to.be.true;
await el.updateComplete;
if (el.repositionComplete) {
await el.repositionComplete;
}
await nextFrame(); // overlayCtrl show/hide is async
await el._overlayCtrl._showComplete;
expect(el.opened).to.be.true;
expect(el._overlayCtrl.isShown).to.be.true;
el.opened = false;
expect(el.opened).to.be.false;
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;
});