From b8830e4ad4fd1a55f1c52d7cfbab1e666c2eae56 Mon Sep 17 00:00:00 2001 From: Brandon Marshall Date: Fri, 23 Aug 2024 08:13:33 -0700 Subject: [PATCH] PR Changes --- libs/blocks/marketo/marketo.js | 11 +++++++++-- test/blocks/marketo/marketo.test.html | 6 +++++- test/blocks/marketo/mocks/marketo-utils.js | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/blocks/marketo/marketo.js b/libs/blocks/marketo/marketo.js index ab608d8caae..64e6d1144fc 100644 --- a/libs/blocks/marketo/marketo.js +++ b/libs/blocks/marketo/marketo.js @@ -13,7 +13,14 @@ /* * Marketo Form */ -import { parseEncodedConfig, loadScript, localizeLink, createTag, createIntersectionObserver } from '../../utils/utils.js'; +import { + parseEncodedConfig, + loadScript, + loadLink, + localizeLink, + createTag, + createIntersectionObserver, +} from '../../utils/utils.js'; const ROOT_MARGIN = 50; const FORM_ID = 'form id'; @@ -222,7 +229,7 @@ export default function init(el) { el.replaceChildren(fragment); el.classList.add('loading'); - document.head.append(createTag('link', { rel: 'dns-prefetch', href: `https://${baseURL}` })); + loadLink(`https://${baseURL}`, { rel: 'dns-prefetch' }); createIntersectionObserver({ el, diff --git a/test/blocks/marketo/marketo.test.html b/test/blocks/marketo/marketo.test.html index 862ee6f6e1d..20556d343a9 100644 --- a/test/blocks/marketo/marketo.test.html +++ b/test/blocks/marketo/marketo.test.html @@ -65,7 +65,7 @@

Fill out the form to view the repo import { expect } from '@esm-bundle/chai'; import { stub } from 'sinon'; import { waitForElement } from '../../helpers/waitfor.js'; - import { loadScript, parseEncodedConfig } from '../../../libs/utils/utils.js'; + import { loadScript, loadLink, parseEncodedConfig } from '../../../libs/utils/utils.js'; import init, { setPreferences, formValidate, formSuccess } from '../../../libs/blocks/marketo/marketo.js'; runTests(() => { @@ -86,6 +86,10 @@

Fill out the form to view the repo expect(desc).to.exist; }); + it('preload Marketo', async () => { + expect(loadLink.calledOnce).to.be.true; + }); + it('loads Marketo script', async () => { expect(loadScript.calledOnce).to.be.true; expect(loadScript.calledWith('https://engage.adobe.com/js/forms2/js/forms2.min.js')).to.be.true; diff --git a/test/blocks/marketo/mocks/marketo-utils.js b/test/blocks/marketo/mocks/marketo-utils.js index 0c987870106..9cf1cf9f9a1 100644 --- a/test/blocks/marketo/mocks/marketo-utils.js +++ b/test/blocks/marketo/mocks/marketo-utils.js @@ -63,3 +63,7 @@ export function createIntersectionObserver({ el, callback /* , once = true, opti } export const localizeLink = (href) => href; + +export const loadLink = stub().returns(new Promise((resolve) => { + resolve(); +}));