diff --git a/libs/blocks/merch-card-collection/merch-card-collection.js b/libs/blocks/merch-card-collection/merch-card-collection.js index 8e8b5bbffb..31e7b37c57 100644 --- a/libs/blocks/merch-card-collection/merch-card-collection.js +++ b/libs/blocks/merch-card-collection/merch-card-collection.js @@ -5,7 +5,9 @@ import { } from '../../utils/utils.js'; import { replaceText } from '../../features/placeholders.js'; -const DIGITS_ONLY = /^\d+$/; +const DIGITS_ONLY = /^\/?\d+\/?$/; +const FILTER_REGEX = /(filter|\/filter\/)/; +const SEARCH_REGEX = /search|\/search\//; export const OVERRIDE_PATHS = 'overrides'; const LITERAL_SLOTS = [ @@ -272,14 +274,14 @@ export default async function init(el) { const literalsEl = el.lastElementChild?.firstElementChild; // parse literals const literalSlots = []; - if (literalsEl && /filter/.test(literalsEl.querySelector('u')?.innerText)) { + if (literalsEl && FILTER_REGEX.test(literalsEl.querySelector('u')?.innerText)) { literalsEl.querySelectorAll('u').forEach((u) => { const text = u.innerText.trim(); if (DIGITS_ONLY.test(text)) { u.outerHTML = ''; - } else if (text === 'search') { + } else if (SEARCH_REGEX.test(text)) { u.outerHTML = ''; - } else if (text === 'filter') { + } else if (FILTER_REGEX.test(text)) { u.outerHTML = ''; } }); diff --git a/libs/features/mas/src/utils.js b/libs/features/mas/src/utils.js index 760dca1497..86b81d01ee 100644 --- a/libs/features/mas/src/utils.js +++ b/libs/features/mas/src/utils.js @@ -9,7 +9,7 @@ export function debounce(func, delay) { } export const getSlotText = (element, name) => - element.querySelector(`[slot="${name}"]`).textContent.trim(); + element.querySelector(`[slot="${name}"]`)?.textContent?.trim(); /** * Helper function to create an element with attributes diff --git a/test/blocks/merch-card-collection/merch-card-collection.test.js b/test/blocks/merch-card-collection/merch-card-collection.test.js index 430669515c..bb8ee5affd 100644 --- a/test/blocks/merch-card-collection/merch-card-collection.test.js +++ b/test/blocks/merch-card-collection/merch-card-collection.test.js @@ -159,6 +159,12 @@ describe('Merch Cards', async () => { expect(merchCards.outerHTML).to.equal(merchCards.nextElementSibling.outerHTML); }); + it('should parse literals 4 translation too', async () => { + const merchCards = await init(document.getElementById('literals-4-translation')); + await delay(500); + expect(merchCards.outerHTML).to.equal(merchCards.nextElementSibling.outerHTML); + }); + it('should override cards when asked to', async () => { const el = document.getElementById('multipleFilters'); setConfig({ diff --git a/test/blocks/merch-card-collection/mocks/merch-card-collection.html b/test/blocks/merch-card-collection/mocks/merch-card-collection.html index 659df59a77..f0f34e128c 100644 --- a/test/blocks/merch-card-collection/mocks/merch-card-collection.html +++ b/test/blocks/merch-card-collection/mocks/merch-card-collection.html @@ -85,8 +85,8 @@
Popularity
Alphabetical
0 results
-1 result in filter
-10 results in filter
+1 result in /filter/
+10 results in /filter/
1 result for search
10 results for search
1 result for: search
@@ -192,8 +192,46 @@Show more
- + +all, 18
+Search all products
+Filters
+Sort
+Popularity
+Alphabetical
+0 results
+1 result in /filter/
+/10/ results in /filter/
+1 result for /search/
+/10/ results for /search/
+1 result for: /search/
+/10/ results for: /search/
+Your search for /search/ did not yield any results
+Your search for /search/ did not yield any results. Try a different search term.
+Suggestions:
+Show more
+Search all products
Filters
Sort
Popularity
Alphabetical
0 results
1 result in
results in
1 result for
results for
1 result for:
results for:
Your search for did not yield any results
Your search for did not yield any results. Try a different search term.
Suggestions:
Show more