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:
commit
5a50ab5977
2 changed files with 16 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue