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

[Release] Stage to Main #2138

Merged
merged 8 commits into from
Apr 15, 2024
13 changes: 13 additions & 0 deletions libs/blocks/global-footer/global-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,20 @@
if (url.hash !== '') {
// Hash -> region selector opens a modal
decorateAutoBlock(regionPickerElem); // add modal-specific attributes
// TODO remove logs after finding the root cause for the region picker 404s -> MWPW-143627
if (regionPickerElem.classList[0] !== 'modal') {
lanaLog({
message: `Modal block class missing from region picker pre loading the block; locale: ${locale}; regionPickerElem: ${regionPickerElem.outerHTML}`,
tags: 'errorType=warn,module=global-footer',
});
}

Check warning on line 235 in libs/blocks/global-footer/global-footer.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/global-footer/global-footer.js#L231-L235

Added lines #L231 - L235 were not covered by tests
await loadBlock(regionPickerElem); // load modal logic and styles
if (regionPickerElem.classList[0] !== 'modal') {
lanaLog({
message: `Modal block class missing from region picker post loading the block; locale: ${locale}; regionPickerElem: ${regionPickerElem.outerHTML}`,
tags: 'errorType=warn,module=global-footer',
});
}

Check warning on line 242 in libs/blocks/global-footer/global-footer.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/global-footer/global-footer.js#L238-L242

Added lines #L238 - L242 were not covered by tests
// 'decorateAutoBlock' logic replaces class name entirely, need to add it back
regionPickerElem.classList.add(regionPickerClass);
regionPickerElem.addEventListener('click', () => {
Expand Down
5 changes: 5 additions & 0 deletions libs/blocks/global-navigation/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
.feds-navLink[class *= '-gradient'] {
display: flex;
border-radius: 4px;
font-weight: 600;
}

.feds-menu-column--group .feds-navLink[class *= '-gradient'] {
Expand Down Expand Up @@ -281,4 +282,8 @@
.feds-navLink--ai-gradient {
background: linear-gradient(90deg, #bce3ff, #ffe9d3, #f8d5e4);
}

.feds-navLink--gray-gradient {
background: #eaeaea;
}
}
4 changes: 2 additions & 2 deletions libs/blocks/mobile-app-banner/mobile-app-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function branchInit(header, key) {
export default async function init(el) {
const header = document.querySelector('.global-navigation');
if (!header) return;
const row = el.querySelector(':scope > div');
const product = row.textContent.trim().toLowerCase();
const classListArray = Array.from(el.classList);
const product = classListArray.find((token) => token.startsWith('product-')).split('-')[1];
const key = await getKey(product);
if (key) branchInit(header, key);
}
2 changes: 1 addition & 1 deletion libs/blocks/modal/modal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/no-cycle */
import { createTag, getMetadata, localizeLink, loadStyle, getConfig } from '../../utils/utils.js';

const FOCUSABLES = 'a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]';
const FOCUSABLES = 'a:not(.hide-video), button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]';
const CLOSE_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
<g transform="translate(-10500 3403)">
<circle cx="10" cy="10" r="10" transform="translate(10500 -3403)" fill="#707070"/>
Expand Down
4 changes: 0 additions & 4 deletions libs/blocks/tabs/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@
margin-inline-start: 24px;
}

.tabs[class*='pill'] {
background: unset;
}

.tabs[class*='pill'] .tab-content {
border-bottom: none;
}
Expand Down
2 changes: 2 additions & 0 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,8 @@ async function documentPostSectionLoading(config) {
import('../martech/attributes.js').then((analytics) => {
document.querySelectorAll('main > div').forEach((section, idx) => analytics.decorateSectionAnalytics(section, idx, config));
});

document.body.appendChild(createTag('div', { id: 'page-load-ok-milo', style: 'display: none;' }));
}

async function processSection(section, config, isDoc) {
Expand Down
67 changes: 67 additions & 0 deletions test/blocks/mobile-app-banner/mobile-app-banner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';
import { delay } from '../../helpers/waitfor.js';

const { setConfig } = await import('../../../libs/utils/utils.js');

const mockConfig = { contentRoot: '/test/blocks/mobile-app-banner/mocks' };
setConfig(mockConfig);

describe('mobile-app-banner', () => {
beforeEach(async () => {
document.body.innerHTML = await readFile({ path: './mocks/body.html' });
});
afterEach(() => {
sinon.restore();
});

it('should not call branch init if no branch-io-key.json', async () => {
sinon.stub(window, 'fetch');
const res = new window.Response('Not found', { status: 404 });
window.fetch.returns(Promise.resolve(res));

const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js');
const banner = document.body.querySelector('.mobile-app-banner.product-test');
await module.default(banner);
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent'));
await delay(0);

const scriptTags = document.querySelectorAll('head > script');
const scriptSrcs = [];
scriptTags.forEach((scriptTag) => {
scriptSrcs.push(scriptTag.getAttribute('src'));
});
expect(scriptSrcs).to.not.include('https://cdn.branch.io/branch-latest.min.js');
});

it('should not call branch init if product not found in branch-io-key file', async () => {
const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js');
const banner = document.body.querySelector('.mobile-app-banner.product-test1');
await module.default(banner);
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent'));
await delay(0);

const scriptTags = document.querySelectorAll('head > script');
const scriptSrcs = [];
scriptTags.forEach((scriptTag) => {
if (scriptTag.getAttribute('src') !== null) scriptSrcs.push(scriptTag.getAttribute('src'));
});
expect(scriptSrcs).to.not.include('https://cdn.branch.io/branch-latest.min.js');
});

it('should init by adding branchio script', async () => {
window.adobePrivacy = { hasUserProvidedConsent: () => true };
const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js');
const banner = document.body.querySelector('.mobile-app-banner.product-test');
await module.default(banner);
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent'));
await delay(0);
const scriptTags = document.querySelectorAll('head > script');
const scriptSrcs = [];
scriptTags.forEach((scriptTag) => {
if (scriptTag.getAttribute('src') !== null) scriptSrcs.push(scriptTag.getAttribute('src'));
});
expect(scriptSrcs).to.include('https://cdn.branch.io/branch-latest.min.js');
});
});
10 changes: 10 additions & 0 deletions test/blocks/mobile-app-banner/mocks/body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<header class="global-navigation" daa-im="true" daa-lh="gnav|milo"><div class="feds-curtain"></div><div class="feds-topnav-wrapper">
</header>
<div>Hello World</div>
<div>
<div class="mobile-app-banner product-test">
</div>
<div>
<div class="mobile-app-banner product-test1">
</div>
</div>
8 changes: 8 additions & 0 deletions test/blocks/mobile-app-banner/mocks/branch-io-key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"data": [
{
"product": "test",
"key": "key_test_eaNdoH8nTxeZXfOsgkELrjgpFrhm4q2m"
}
]
}
Loading