Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix for flakyness in ci #4762

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions packages/overlay/stories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,29 @@ governing permissions and limitations under the License.
import { html, TemplateResult } from '@spectrum-web-components/base';
import type { Overlay } from '@spectrum-web-components/overlay';

function nextFrame(): Promise<void> {
return new Promise((res) => requestAnimationFrame(() => res()));
}

class IsOverlayOpen extends HTMLElement {
ready!: (value: boolean | PromiseLike<boolean>) => void;

constructor() {
super();
this.readyPromise = new Promise((res) => {
this.ready = res;
this.readyPromise = new Promise((resolve) => {
this.ready = resolve;
this.setup();
});
}

async setup(): Promise<void> {
await nextFrame();

// Add a listener for the 'sp-opened' event, which opens the overlay
document.addEventListener('sp-opened', this.handleOpened);
}

handleOpened = async (event: Event): Promise<void> => {
const overlay = event.target as Overlay;
const actions = [nextFrame(), overlay.updateComplete];

await Promise.all(actions);
// Focus happens _after_ `sp-opened` by at least two frames.
await nextFrame();
await nextFrame();
await nextFrame();
await nextFrame();
// Wait for the overlay to fully finish updating
await overlay.updateComplete;

// Resolve the ready promise
this.ready(true);
};

Expand Down
Loading