Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ describe("getEntryIdentifiersInCurrentPage", () => {
expect(entriesInCurrentPage.length).toBe(0);
expect(entriesInCurrentPage).toEqual([]);
});

test("should filter out elements with empty data-cslp attribute and not break", () => {
document.body.innerHTML = `
<div>
<h1 data-cslp="">Empty CSLP</h1>
<h1 data-cslp="page.bltf5bb5f8fb088a332.en-us.page_components.0.hero_banner.banner_title">Valid CSLP</h1>
Comment thread
csAyushDubey marked this conversation as resolved.
</div>
`;
const { entriesInCurrentPage } = getEntryIdentifiersInCurrentPage();
expect(entriesInCurrentPage.length).toBe(1);
expect(entriesInCurrentPage[0].entryUid).toBe('bltf5bb5f8fb088a332');
});
});
6 changes: 3 additions & 3 deletions src/visualBuilder/utils/getEntryIdentifiersInCurrentPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export function getEntryIdentifiersInCurrentPage(): EntryIdentifiers {
);
const uniqueEntriesMap = new Map<string, { entryUid: string, contentTypeUid: string, locale: string}>();
elementsWithCslp.forEach((element) => {
const cslpData = extractDetailsFromCslp(
element.getAttribute("data-cslp") as string
);
const cslpValue = element.getAttribute("data-cslp");
if (!cslpValue) return;
const cslpData = extractDetailsFromCslp(cslpValue);
Comment thread
hiteshshetty-dev marked this conversation as resolved.
uniqueEntriesMap.set(cslpData.entry_uid,
{
entryUid: cslpData.entry_uid,
Expand Down
Loading