Skip to content

Commit

Permalink
MWPW-148185 [MILO][MEP] Promo modal suppression mechanism (#3030)
Browse files Browse the repository at this point in the history
* Possible working modal suppression.

* Added conditional parameters and unit test.
  • Loading branch information
AdobeLinhart authored Oct 22, 2024
1 parent 47f1c0d commit c30fa5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libs/blocks/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ export function delayedModal(el) {

// Deep link-based
export default function init(el) {
const { modalHash } = el.dataset;
const { modalHash, modalPath } = el.dataset;
if (getConfig().mep?.fragments?.[modalPath]?.action === 'remove') return null;
if (delayedModal(el) || window.location.hash !== modalHash || document.querySelector(`div.dialog-modal${modalHash}`)) return null;
if (dialogLoadingSet.has(modalHash?.replace('#', ''))) return null; // prevent duplicate modal loading
const details = findDetails(window.location.hash, el);
Expand Down
8 changes: 8 additions & 0 deletions test/blocks/modals/modals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';
import { delay, waitForElement, waitForRemoval } from '../../helpers/waitfor.js';
import { mockFetch } from '../../helpers/generalHelpers.js';
import { getConfig } from '../../../libs/utils/utils.js';

document.body.innerHTML = await readFile({ path: './mocks/body.html' });

Expand Down Expand Up @@ -250,6 +251,13 @@ describe('Modals', () => {
expect(window.location.hash).to.equal('#category=pdf-esignatures&search=acro&types=desktop%2Cmobile');
window.location.hash = '';
});

it('never create modal when removed by MEP', async () => {
const config = getConfig();
config.mep = { fragments: { '/milo': { action: 'remove' } } };
const modal = init(document.getElementById('milo-modal-link'));
expect(modal).to.be.null;
});
});

describe('sendAnalytics', () => {
Expand Down

0 comments on commit c30fa5b

Please sign in to comment.