Skip to content

Commit

Permalink
Changed pep loading logic to poll for modals only after the close mod…
Browse files Browse the repository at this point in the history
…al dialog comes through
  • Loading branch information
sharmrj committed Jun 5, 2024
1 parent d5fbaef commit 2ad215a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions libs/features/webapp-prompt/webapp-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ class AppPrompt {
this.getAnchorState = getAnchorState;
this.id = this.promptPath.split('/').pop();
this.elements = {};
if (modalsActive()) waitForClosedModalsThen(this.init);
else this.init();
if (modalsActive()) {
window.addEventListener(
'milo:modal:closed',
() => waitForClosedModalsThen(this.init),
{ once: true },
);
} else this.init();
}

init = async () => {
Expand Down
9 changes: 6 additions & 3 deletions test/features/webapp-prompt/webapp-prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ describe('PEP', () => {
});

it('should not render PEP when the GRM is open', async () => {
document.body.insertAdjacentHTML('afterbegin', '<div class="locale-modal-v2"></div>');
document.body.insertAdjacentHTML('afterbegin', '<div class="locale-modal"></div>');
document.body.insertAdjacentHTML('afterbegin', '<div class="locale-modal-v2 dialog-modal"></div>');
document.body.insertAdjacentHTML('afterbegin', '<div class="dialog-modal"></div>');

await initPep({});

Expand All @@ -104,8 +104,11 @@ describe('PEP', () => {
expect(document.querySelector(allSelectors.pepWrapper)).to.not.exist;
}

const event = new CustomEvent('milo:modal:closed');
window.dispatchEvent(event);

document.querySelector('.locale-modal-v2')?.remove();
document.querySelector('.locale-modal')?.remove();
document.querySelector('.dialog-modal')?.remove();

await clock.runAllAsync();
expect(document.querySelector(allSelectors.pepWrapper)).to.exist;
Expand Down

0 comments on commit 2ad215a

Please sign in to comment.