From 4f8bab84f58d697ed937c5f8f7e4a548f9557e28 Mon Sep 17 00:00:00 2001 From: Jingle Huang Date: Tue, 29 Oct 2024 13:54:59 -0500 Subject: [PATCH] fix ut --- express/blocks/grid-marquee/grid-marquee.js | 32 +++-- test/blocks/grid-marquee/grid-marquee.test.js | 6 + test/blocks/grid-marquee/mocks/body.html | 110 +++++++++--------- 3 files changed, 78 insertions(+), 70 deletions(-) diff --git a/express/blocks/grid-marquee/grid-marquee.js b/express/blocks/grid-marquee/grid-marquee.js index 453aeacf..8522cf63 100644 --- a/express/blocks/grid-marquee/grid-marquee.js +++ b/express/blocks/grid-marquee/grid-marquee.js @@ -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; } @@ -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!'); ob.unobserve(el); cards.forEach((card) => card.lazyCB()); }).observe(el); diff --git a/test/blocks/grid-marquee/grid-marquee.test.js b/test/blocks/grid-marquee/grid-marquee.test.js index 427e87d5..bc0e0bf3 100644 --- a/test/blocks/grid-marquee/grid-marquee.test.js +++ b/test/blocks/grid-marquee/grid-marquee.test.js @@ -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', () => { diff --git a/test/blocks/grid-marquee/mocks/body.html b/test/blocks/grid-marquee/mocks/body.html index c16fce18..4f1f431d 100644 --- a/test/blocks/grid-marquee/mocks/body.html +++ b/test/blocks/grid-marquee/mocks/body.html @@ -1,19 +1,19 @@ -
+
-

The quick and easy app to create anything.

+

The quick and easy create-anything app.

Make stunning social posts, images, videos, flyers, and more with Adobe Express. Dream it. Make it. Easy.

-

Start 30-day Premium Trial Get Adobe Express Free

+

Start 30-day free trial Get Adobe Express Free

- - - - + + + +
@@ -21,89 +21,93 @@

The quick and easy app to cre

- - - - - https://main--express--adobecom.hlx.page/express/assets/video/seo/media_10d7e792a1e995d5a1d921fc10bf7f89765035107.mp4 + + + + +

-

Edit your media in one click

+

+

Edit with one click

Photo

-

Remove Background

-

Resize Image

-

Crop Image

-

Convert JPG to PNG

-

Convert PNG to JPG

+

Remove Background

+

Resize Image

+

Crop Image

+

Convert JPG to PNG

+

Convert PNG to JPG

Video

-

Crop Video

-

Trim Video

-

Resize Video

-

Merge Video

-

Caption Video

+

Crop Video

+

Trim Video

+

Resize Video

+

Merge Video

+

Caption Video

- - - - - https://main--express--adobecom.hlx.page/express/assets/video/seo/media_161a751e45895871d9f32e4e08260a5d95bc9f9ac.mp4 + + + + +

+

Create fast with generative AI

-

Generate Image

-

Generate Template

-

Generate Fill

-

Music Generator

-

Text to Speech

-

AI Voiceover

+

Generate Image

+

Generate Template

+

Generative Fill

+

Music Generator

+

Text to Speech

+

AI Voiceover

- - - - - https://main--express--adobecom.hlx.page/express/assets/video/seo/media_1e7122e12681a5da4eb0fe8d6107dff7f6a95c33e.mp4 + + + + +

+

Explore amazing content

-

Templates

-

Photos

-

Videos

-

Design Assets

-

Add-ons

+

Templates

+

Photos

+

Videos

+

Design Assets

+

Add-ons

-
\ No newline at end of file +