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-144470 Support article header author without link #2863

Merged
merged 1 commit into from
Sep 16, 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
9 changes: 5 additions & 4 deletions libs/blocks/article-header/article-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ function openPopup(e) {
}

async function buildAuthorInfo(authorEl, bylineContainer) {
const { href, textContent } = authorEl;
const { textContent } = authorEl;
const link = authorEl.href || authorEl.dataset.authorPage;
const config = getConfig();
const base = config.miloLibs || config.codeRoot;
const authorImg = createTag('div', { class: 'article-author-image' });
authorImg.style.backgroundImage = `url(${base}/blocks/article-header/adobe-logo.svg)`;
bylineContainer.prepend(authorImg);

const doc = await validateAuthorUrl(href);
const doc = await validateAuthorUrl(link);
if (!doc) {
const p = createTag('p', null, textContent);
authorEl.replaceWith(p);
Expand All @@ -48,7 +49,7 @@ async function buildAuthorInfo(authorEl, bylineContainer) {

const img = doc.querySelector('img');
if (img) {
img.setAttribute('alt', authorEl.textContent);
img.setAttribute('alt', textContent);
authorImg.append(img);
if (!img.complete) {
img.addEventListener('load', () => {
Expand Down Expand Up @@ -197,7 +198,7 @@ export default async function init(blockEl) {
bylineContainer.firstElementChild.classList.add('article-byline-info');

const authorContainer = bylineContainer.firstElementChild.firstElementChild;
const authorEl = authorContainer.querySelector('a');
const authorEl = authorContainer.firstElementChild;
authorContainer.classList.add('article-author');

buildAuthorInfo(authorEl, bylineContainer);
Expand Down
15 changes: 15 additions & 0 deletions test/blocks/article-header/article-header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ describe('article header', () => {
const categoryLink = document.querySelector('.article-category a');
expect(categoryLink.href.includes('/topics/')).to.be.true;
});

it('adds an author image from a link', () => {
const img = document.querySelector('.article-author-image img');
const link = document.querySelector('.article-author a');
expect(img).to.exist;
expect(link).to.exist;
});

it('adds an author image from data attribute', async () => {
await init(document.querySelector('#article-header-no-author-link'));
const img = document.querySelector('.article-author-image img');
const author = document.querySelector('.article-author [data-author-page]');
expect(img).to.exist;
expect(author).to.exist;
});
});

describe('test the invalid article header', () => {
Expand Down
28 changes: 28 additions & 0 deletions test/blocks/article-header/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@ <h1 id="celebrating-a-special-milestone-10-things-you-might-not-know-about-adobe
</div>
</div>
</div>
<div id="article-header-no-author-link" class="article-header">
<div>
<div>
<p><a href="" data-topic-link="Adobe Life">Adobe Life</a></p>
</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><span data-author-page="/test/blocks/article-header/mocks/adobe-communication-team">Adobe Communications Team</span></p>
<p>12-05-2022</p>
</div>
</div>
<div>
<div>
<p>
<picture>
</picture>
<em>Caption</em>
</p>
</div>
</div>
</div>
Loading