Skip to content

Commit

Permalink
MWPW-144683 Remove Null from Article Header
Browse files Browse the repository at this point in the history
  • Loading branch information
meganthecoder committed Mar 20, 2024
1 parent ce26d1f commit 84a31ca
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion blog/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function buildArticleHeader(el) {
const { locale } = getConfig();
const authorURL = getMetadata('author-url') || (author ? `${locale.contentRoot}/authors/${author.replace(/[^0-9a-z]/gi, '-').toLowerCase()}` : null);
const publicationDate = getMetadata('publication-date');
const categoryTag = getLinkForTopic(category);
const categoryTag = category ? getLinkForTopic(category) : '';
const articleHeaderBlockEl = buildBlock('article-header', [
[`<p>${categoryTag}</p>`],
[h1],
Expand Down
11 changes: 11 additions & 0 deletions test/scripts/mocks/blocks/article-feed/article-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function loadTaxonomy() {

}

export function getLinkForTopic() {
return '#';
}

export function getTaxonomyModule() {
return true;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<main>
<div>
<h1 id="connecting-external-data-sources-to-adobe-experience-manager-guides-is-now-a-breeze">Connecting external data sources to Adobe Experience Manager Guides is now a breeze</h1>
<picture>
<img src="">
</picture>
<p><em>Rohit Bansal is a principal product marketing manager at Adobe, leading global go-to-market strategy for Adobe Experience Manager Guides. With over 14 years of experience, Rohit has led marketing for product and services firms in the B2B domain — and managed key functions like product marketing, digital marketing, thought leadership, demand generation, and partner relations. A passionate data-driven marketer, he is also a big advocate of the customer experience.</em></p>
</div>
</main>
4 changes: 4 additions & 0 deletions test/scripts/mocks/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<meta name="publication-date" content="08-10-2023">
<meta property="article:tag" content="Customer Intelligence">
<meta property="article:tag" content="Customer Success">
<meta name="category" content="The Latest">
File renamed without changes.
8 changes: 8 additions & 0 deletions test/scripts/mocks/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function getMetadata(name, doc = document) {
const attr = name && name.includes(':') ? 'property' : 'name';
const meta = doc.head.querySelector(`meta[${attr}="${name}"]`);
return meta && meta.content;
}
export function getConfig() {
return { locale: '' };
}
24 changes: 17 additions & 7 deletions test/scripts/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ describe('Libs', () => {
});
});

const metadata = await readFile({ path: './mocks/tagsHead.html' });
const metadata = await readFile({ path: './mocks/head.html' });

window.lana = { log: () => {} };

describe('Auto Blocks', () => {
before(() => {
setLibs('/libs');
setLibs('/test/scripts/mocks', { hostname: 'none', search: '' });
document.head.innerHTML = metadata;
});

beforeEach(() => {
Expand All @@ -64,30 +65,39 @@ describe('Auto Blocks', () => {
});

it('catches errors', async () => {
document.head.innerHTML = metadata;
document.body.innerHTML = '';
await buildAutoBlocks();
expect(window.lana.log.called).to.be.true;
});

it('builds the tags block', async () => {
document.head.innerHTML = metadata;
document.body.innerHTML = await readFile({ path: './mocks/tagsBody.html' });
document.body.innerHTML = await readFile({ path: './mocks/body.html' });
await buildAutoBlocks();
expect(document.querySelector('.tags')).to.exist;
});

it('inserts the tags block before recommended articles if present', async () => {
document.head.innerHTML = metadata;
document.body.innerHTML = await readFile({ path: './mocks/tagsWithRecBody.html' });
await buildAutoBlocks();
expect(document.querySelector('.tags + .recommended-articles')).to.exist;
});

it('inserts the tags block in section before recommended articles if present', async () => {
document.head.innerHTML = metadata;
document.body.innerHTML = await readFile({ path: './mocks/tagsWithRecSectionBody.html' });
await buildAutoBlocks();
expect(document.querySelector('.before-rec .tags')).to.exist;
});

it('builds the article header block', async () => {
document.body.innerHTML = await readFile({ path: './mocks/body.html' });
await buildAutoBlocks();
expect(document.querySelector('.article-header')).to.exist;
});

it('does not display null category', async () => {
document.head.innerHTML = await readFile({ path: './mocks/noCategoryHead.html' });
document.body.innerHTML = await readFile({ path: './mocks/body.html' });
await buildAutoBlocks();
expect(document.querySelector('.article-header > div').textContent).to.not.equal('null');
});
});

0 comments on commit 84a31ca

Please sign in to comment.