Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-144683 Remove Null from Article Header #37

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this here to prevent errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are here as mocks for the external milo scripts, as called out as best practice by the community. Before, I've tried to use import maps like we do in milo tests, but they don't work with template strings in dynamic imports. Here, I'm mocking the external scripts by setting milo libs to pull from the localhost mocks folder.

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">
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');
});
});