Skip to content

Commit

Permalink
PR Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon32 committed Aug 23, 2024
1 parent 9d6191f commit b8830e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions libs/blocks/marketo/marketo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion test/blocks/marketo/marketo.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h2 id="fill-out-the-form-to-view-the-report">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(() => {
Expand All @@ -86,6 +86,10 @@ <h2 id="fill-out-the-form-to-view-the-report">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;
Expand Down
4 changes: 4 additions & 0 deletions test/blocks/marketo/mocks/marketo-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));

0 comments on commit b8830e4

Please sign in to comment.