Skip to content

Commit

Permalink
Updating unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Snehal Sonawane authored and Snehal Sonawane committed Jan 25, 2025
1 parent e1a4244 commit 77168ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const setBreadcrumbSEO = (breadcrumbs) => {
};
breadcrumbs.querySelectorAll('ul > li').forEach((item, idx) => {
const link = item.querySelector('a');
const name = link ? link.innerText.trim() : [...item.childNodes].filter((node) => !node.matches?.('span[aria-hidden="true"]')).map((node) => node.textContent.trim()).join('');
breadcrumbsSEO.itemListElement.push({
'@type': 'ListItem',
position: idx + 1,
name: link ? link.innerText.trim() : item.innerText.trim(),
name,
item: link?.href,
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/blocks/global-navigation/features/breadcrumbs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ describe('breadcrumbs', () => {
document.head.innerHTML = '<meta name="breadcrumbs-page-title" content="Custom Title"><meta name="breadcrumbs-show-current-page" content="on">';
const breadcrumb = await breadcrumbs(breadcrumbMock());
assertBreadcrumb({ breadcrumb, length: 5 });
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim()).to.equal('Custom Title');
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim().replace(/^\//, '').trim()).to.equal('Custom Title');
});

it('should use a custom page title if its explicity set even without breadcrumbs-show-current-page:ON', async () => {
document.head.innerHTML = '<meta name="breadcrumbs-page-title" content="Custom Title">';
const breadcrumb = await breadcrumbs(breadcrumbMock());
assertBreadcrumb({ breadcrumb, length: 5 });
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim()).to.equal('Custom Title');
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim().replace(/^\//, '').trim()).to.equal('Custom Title');
});

it('should create a breadcrumb SEO element', async () => {
Expand Down

0 comments on commit 77168ec

Please sign in to comment.