Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
JingleH committed Oct 29, 2024
1 parent e08c27c commit 4f8bab8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 70 deletions.
32 changes: 15 additions & 17 deletions express/blocks/grid-marquee/grid-marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,27 @@ function toCard(drawer) {
return { card, lazyCB };
}

async function formatDynamicCartLink(a, plan) {
async function formatDynamicCartLink(a) {
try {
const pattern = /.*commerce.*adobe\.com.*/gm;
if (!pattern.test(a.href)) return a;
a.style.visibility = 'hidden';
const {
fetchPlanOnePlans,
buildUrl,
} = await import('../../scripts/utils/pricing.js');
const pattern = /.*commerce.*adobe\.com.*/;
if (pattern.test(a.href)) {
let response;
if (!plan) {
response = await fetchPlanOnePlans(a.href);
} else {
response = plan;
}
const newTrialHref = buildUrl(
response.url,
response.country,
response.language,
response.offerId,
);
a.href = newTrialHref;
}
const {
url,
country,
language,
offerId,
} = await fetchPlanOnePlans(a.href);
const newTrialHref = buildUrl(url, country, language, offerId);
a.href = newTrialHref;
} catch (error) {
window.lana.log(`Failed to fetch prices for page plan: ${error}`);
}
a.style.visibility = 'visible';
return a;
}

Expand Down Expand Up @@ -224,10 +220,12 @@ export default function init(el) {
logo.classList.add('express-logo');
const cards = items.map((item) => toCard(item));
const cardsContainer = createTag('div', { class: 'cards-container' }, cards.map(({ card }) => card));
[...cardsContainer.querySelectorAll('p:empty')].forEach((p) => p.remove());
foreground.append(logo, decorateHeadline(headline), cardsContainer, ...(el.classList.contains('ratings') ? [makeRatings()] : []));
background.classList.add('background');
el.append(foreground);
new IntersectionObserver((entries, ob) => {
console.log('io!');

Check warning on line 228 in express/blocks/grid-marquee/grid-marquee.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement

Check warning on line 228 in express/blocks/grid-marquee/grid-marquee.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
ob.unobserve(el);
cards.forEach((card) => card.lazyCB());
}).observe(el);
Expand Down
6 changes: 6 additions & 0 deletions test/blocks/grid-marquee/grid-marquee.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import { delay } from '../../helpers/waitfor.js';

const imports = await Promise.all([import('../../../express/scripts/utils.js'), import('../../../express/scripts/scripts.js')]);
const { getLibs } = imports[0];
await import(`${getLibs()}/utils/utils.js`).then((mod) => {
const conf = {};
mod.setConfig(conf);
});
const [, { default: decorate }] = await Promise.all([import('../../../express/scripts/scripts.js'), import('../../../express/blocks/grid-marquee/grid-marquee.js')]);
document.body.innerHTML = await readFile({ path: './mocks/body.html' });
describe('grid-marquee', () => {
Expand Down
Loading

0 comments on commit 4f8bab8

Please sign in to comment.