From 46631ba5badb17fbec531d8e53e81e13432c9cd6 Mon Sep 17 00:00:00 2001 From: Mira Date: Thu, 15 Feb 2024 14:42:23 +0100 Subject: [PATCH] changed the creates and opens the delayed modal test --- .../personalization/delayedModal.test.js | 145 +++++++++--------- 1 file changed, 70 insertions(+), 75 deletions(-) diff --git a/test/features/personalization/delayedModal.test.js b/test/features/personalization/delayedModal.test.js index 775551e6560..72f12969187 100644 --- a/test/features/personalization/delayedModal.test.js +++ b/test/features/personalization/delayedModal.test.js @@ -1,82 +1,77 @@ import { expect } from '@esm-bundle/chai'; -// import { parseUrl } from '../../../libs/features/personalization/personalization.js'; -// eslint-disable-next-line max-len -// import { defineDelayedModalParams, decorateDelayedModalAnchor, initDelayedModal } from '../../../libs/blocks/modal/modal.js'; -// import { waitForElement } from '../../helpers/waitfor.js'; +import { parseUrl } from '../../../libs/features/personalization/personalization.js'; +import { defineDelayedModalParams, decorateDelayedModalAnchor, initDelayedModal } from '../../../libs/blocks/modal/modal.js'; +import { waitForElement } from '../../helpers/waitfor.js'; -// const DELAYED_MODAL_DISPLAY_MODE = { -// oncePerPageLoad: 'pageload', -// oncePerSession: 'session', -// }; -// const hash = '#dm'; +const DELAYED_MODAL_DISPLAY_MODE = { + oncePerPageLoad: 'pageload', + oncePerSession: 'session', +}; +const hash = '#dm'; -it('dummy test, will remove', () => { - expect(true).to.be.true; +it('parses URL properly', () => { + expect(parseUrl()).to.deep.equal({}); + expect(parseUrl('https://www.adobe.com/')).to.deep.equal({ + hash: '', + href: '/', + pathname: '/', + search: '', + }); + expect(parseUrl('https://www.adobe.com/testpage/?delay=1&display=pageload#dm')).to.deep.equal({ + hash, + href: '/testpage/?delay=1&display=pageload#dm', + pathname: '/testpage/', + search: '?delay=1&display=pageload', + }); }); -// it('parses URL properly', () => { -// expect(parseUrl()).to.deep.equal({}); -// expect(parseUrl('https://www.adobe.com/')).to.deep.equal({ -// hash: '', -// href: '/', -// pathname: '/', -// search: '', -// }); -// expect(parseUrl('https://www.adobe.com/testpage/?delay=1&display=pageload#dm')).to.deep.equal({ -// hash, -// href: '/testpage/?delay=1&display=pageload#dm', -// pathname: '/testpage/', -// search: '?delay=1&display=pageload', -// }); -// }); - -// it('takes the delayed modal parameters from the URL', () => { -// expect(defineDelayedModalParams()).to.deep.equal({}); -// expect(defineDelayedModalParams('?delay=invalid&display=invalid')).to.be.undefined; -// expect(defineDelayedModalParams('?delay=1&display=pageload')).to.deep.equal({ -// delay: '1', -// displayMode: 'pageload', -// DELAYED_MODAL_DISPLAY_MODE, -// }); -// }); +it('takes the delayed modal parameters from the URL', () => { + expect(defineDelayedModalParams()).to.deep.equal({}); + expect(defineDelayedModalParams('?delay=invalid&display=invalid')).to.be.undefined; + expect(defineDelayedModalParams('?delay=1&display=pageload')).to.deep.equal({ + delay: '1', + displayMode: 'pageload', + DELAYED_MODAL_DISPLAY_MODE, + }); +}); -// it('add proper attributes and class names to the link', () => { -// const a = document.createElement('a'); -// decorateDelayedModalAnchor({ -// a, -// hash, -// pathname: '/testpage/', -// }); -// expect(a.getAttribute('href')).to.equal(hash); -// expect(a.getAttribute('data-modal-hash')).to.equal(hash); -// expect(a.getAttribute('data-modal-path')).to.equal('/testpage/'); -// expect(a.getAttribute('style')).to.equal('display: none'); -// expect(a.classList.contains('modal')).to.be.true; -// expect(a.classList.contains('link-block')).to.be.true; -// a.remove(); -// }); +it('add proper attributes and class names to the link', () => { + const a = document.createElement('a'); + decorateDelayedModalAnchor({ + a, + hash, + pathname: '/testpage/', + }); + expect(a.getAttribute('href')).to.equal(hash); + expect(a.getAttribute('data-modal-hash')).to.equal(hash); + expect(a.getAttribute('data-modal-path')).to.equal('/testpage/'); + expect(a.getAttribute('style')).to.equal('display: none'); + expect(a.classList.contains('modal')).to.be.true; + expect(a.classList.contains('link-block')).to.be.true; + a.remove(); +}); -// it('creates and opens the delayed modal', async () => { -// const a = document.createElement('a'); -// decorateDelayedModalAnchor({ -// a, -// hash, -// pathname: '/testpage', -// }); -// document.body.appendChild(a); -// initDelayedModal({ -// a, -// delay: '1', -// displayMode: 'pageload', -// hash, -// contentUrl: '/testpage', -// DELAYED_MODAL_DISPLAY_MODE, -// }); -// const delayedModal = await waitForElement(hash); -// eslint-disable-next-line max-len -// const modalStylesLink = window.document.head.querySelector('link[href="undefined/blocks/modal/modal.css"]'); -// expect(delayedModal).to.exist; -// expect(modalStylesLink).to.exist; -// delayedModal.remove(); -// a.remove(); -// }); +it('creates and opens the delayed modal', async () => { + const a = document.createElement('a'); + decorateDelayedModalAnchor({ + a, + hash, + pathname: '/testpage', + }); + document.body.appendChild(a); + initDelayedModal({ + a, + delay: '1', + displayMode: 'pageload', + hash, + contentUrl: '/testpage', + DELAYED_MODAL_DISPLAY_MODE, + }); + const delayedModal = await waitForElement(hash); + const modalStylesLink = window.document.head.querySelector('link[href="undefined/blocks/modal/modal.css"]'); + expect(delayedModal).to.exist; + expect(modalStylesLink).to.exist; + delayedModal.remove(); + modalStylesLink.remove(); + a.remove(); +});