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-148054: Mnemonics list in a text block #2405

Merged
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
11 changes: 9 additions & 2 deletions libs/blocks/text/text.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { decorateBlockBg, decorateBlockText, getBlockSize, decorateTextOverrides } from '../../utils/decorate.js';
import { createTag, loadStyle, getConfig } from '../../utils/utils.js';
import { createTag, loadStyle, getConfig, loadBlock } from '../../utils/utils.js';

// size: [heading, body, ...detail]
const blockTypeSizes = {
Expand Down Expand Up @@ -76,7 +76,7 @@ function decorateLinkFarms(el) {
});
}

export default function init(el) {
export default async function init(el) {
el.classList.add('text-block', 'con-block');
let rows = el.querySelectorAll(':scope > div');
if (rows.length > 1) {
Expand Down Expand Up @@ -117,4 +117,11 @@ export default function init(el) {
lastActionArea.insertAdjacentElement('afterend', div);
div.append(lastActionArea);
}

const mnemonicList = el.querySelector('.mnemonic-list');
const foreground = mnemonicList?.closest('.foreground');
if (foreground) {
mnemonicList.querySelectorAll('p').forEach((product) => product.removeAttribute('class'));
await loadBlock(mnemonicList);
}
}
23 changes: 23 additions & 0 deletions test/blocks/text/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,26 @@ <h3 id="text">Text</h3>
</div>
</div>
</div>

<div id="mnemonics" class="text quiet medium light center xxl-spacing mnemonic-list text-block con-block has-bg">
<div class="background"></div>
<div class="foreground">
<div data-valign="middle">
<h2 id="get-20-creative-cloud-for-less-than-the-price-of-3-apps" class="heading-l">Get 20+ creative cloud for less than the price of 3 apps.</h2>
<p class="body-m">The All Apps plan includes 20+ apps and services plus 20,000 fonts, storage, templates, and tutorials for less than the price of acrobat, photoshop, and premiere pro sold separately.</p>
<div class="mnemonic-list" data-path="/fragments/mirafedas/includes">
<div>
<div data-valign="middle">
<p class="body-m"><strong>Includes:</strong></p>
<p class="body-m"><strong>Acrobat</strong></p>
<p class="body-m"><strong>Photoshop</strong></p>
<p class="body-m"><strong>Premiere Pro</strong></p>
<p class="body-m"><strong>Illustrator</strong></p>
<p class="body-m"><strong>Adobe Express</strong></p>
<p class="body-m"><strong>Lightroom</strong></p>
</div>
</div>
</div>
</div>
</div>
</div>
19 changes: 19 additions & 0 deletions test/blocks/text/text.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import { setConfig } from '../../../libs/utils/utils.js';

const conf = {
codeRoot: '/libs',
contentRoot: `${window.location.origin}`,
};
setConfig(conf);

document.body.innerHTML = await readFile({ path: './mocks/body.html' });
const { default: init } = await import('../../../libs/blocks/text/text.js');
Expand Down Expand Up @@ -78,4 +85,16 @@ describe('text block', () => {
expect(actionArea.parentElement.className.includes('cta-container')).to.be.false;
});
});
describe('text block with mnemonics list', () => {
it('renders mnemonics list', async () => {
const textBlockWithMnemonics = document.querySelector('#mnemonics');
await init(textBlockWithMnemonics);
const mnemonicsList = textBlockWithMnemonics.querySelector('.mnemonic-list');
const productList = mnemonicsList?.querySelector('.product-list');
const productItems = productList?.querySelectorAll('.product-item');
expect(mnemonicsList).to.exist;
expect(productList).to.exist;
expect(productItems.length).to.equal(7);
});
});
});
Loading