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 Allow Article Header Without Category #2084

Merged
merged 6 commits into from
Apr 9, 2024
Merged
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
6 changes: 4 additions & 2 deletions libs/blocks/article-header/article-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const resp = await fetch(`${url.toLowerCase()}.plain.html`);
if (!resp?.ok) {
console.log(`Could not retrieve metadata for ${url}`);

Check warning on line 13 in libs/blocks/article-header/article-header.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 Unexpected console statement. Raw Output: {"ruleId":"no-console","severity":1,"message":"Unexpected console statement.","line":13,"column":5,"nodeType":"MemberExpression","messageId":"unexpected","endLine":13,"endColumn":16}
return null;
}

Expand Down Expand Up @@ -140,13 +140,15 @@

const childrenEls = Array.from(blockEl.children);
if (childrenEls.length < 4) {
console.warn('Block does not have enough children');

Check warning on line 143 in libs/blocks/article-header/article-header.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 Unexpected console statement. Raw Output: {"ruleId":"no-console","severity":1,"message":"Unexpected console statement.","line":143,"column":5,"nodeType":"MemberExpression","messageId":"unexpected","endLine":143,"endColumn":17}
}

const categoryContainer = childrenEls[0];
const categoryEl = categoryContainer.firstElementChild.firstElementChild;
const categoryTag = getLinkForTopic(categoryEl.textContent);
categoryEl.innerHTML = categoryTag;
if (categoryEl?.textContent) {
const categoryTag = getLinkForTopic(categoryEl.textContent);
categoryEl.innerHTML = categoryTag;
}
categoryContainer.classList.add('article-category');

const titleContainer = childrenEls[1];
Expand Down
8 changes: 8 additions & 0 deletions test/blocks/article-header/article-header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ describe('test the invalid article header', () => {
expect(date.classList.contains('article-date-invalid')).to.be.false;
});
});

describe('article header', () => {
it('allows a blank category', async () => {
document.body.innerHTML = await readFile({ path: './mocks/body-without-category.html' });
await init(document.body.querySelector('.article-header'));
expect(document.body.querySelector('.article-category a')).to.be.null;
});
});
30 changes: 30 additions & 0 deletions test/blocks/article-header/mocks/body-without-category.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div>
<div class="section">
<div class="article-header">
<div>
<div>
</div>
</div>
<div>
<div>
<h1 id="celebrating-a-special-milestone-10-things-you-might-not-know-about-adobes-40-years-of-innovation">
Celebrating a special milestone: 10 things you might not know about Adobe’s 40 years of innovation</h1>
</div>
</div>
<div>
<div>
<p><a href="/test/blocks/article-header/mocks/adobe-communication-team">Adobe Communications Team</a></p>
<p>12-05-2022</p>
</div>
</div>
<div>
<div>
<p>
<picture>
</picture>
</p>
</div>
</div>
</div>
</div>
</div>
Loading