Skip to content

Commit

Permalink
Merge branch 'stage' into methomas/search-exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
meganthecoder authored Mar 12, 2024
2 parents c2069f8 + e3fd0e5 commit 407e72b
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 44 deletions.
36 changes: 19 additions & 17 deletions libs/blocks/caas-marquee/caas-marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,28 @@ const SEGMENTS_MAP = {
},
},
prod: {
'b446a9cf-a45c-40a7-ae67-33c2cf7f0bf7': 'acrobat',
'389deb08-1522-46e5-ba26-1df898934f4f': 'adobecom',
'079734f3-b593-4c58-8805-592d71f88d95': 'apro-cart-abandoner',
'295bea12-8443-41c9-9da1-8f75df77dd80': 'business',
'235a97a1-bf2e-4e92-bf18-13a9bfcf6ec9': 'cc-lapsed',
'f6553238-548f-4e39-bfa4-b299caaca62e': 'commerce',
'f569e4f9-f20a-4d6e-ba95-2abe4facdd1b': 'creative-cloud',
'5114ecd1-d1ac-4caa-869c-5652ab83afed': 'express',
'1d33382e-0c2c-4d24-8b1f-08be98cee22a': 'firefly',
'3f27d856-bbdd-431b-9e8f-44f6fe0cfbd0': 'helpx',
'5b88bec0-99f2-4736-b2d8-4809463b7fbd': 'illustrator',
'3822c05b-8074-4629-b493-59cc12a78650': 'lightroom',
'5b5c991e-2633-4390-8ee4-e58931da088e': 'photoshop',
'395264bb-b584-45fa-af53-a4396e64838b': 'premiere',
'c02e9190-cc42-47cd-85c0-421924c47f2b': 'sign',
'9aba8c9e-dce9-427e-8122-a6c796ee2d03': 'stock',
source: {
'b446a9cf-a45c-40a7-ae67-33c2cf7f0bf7': 'acrobat',
'389deb08-1522-46e5-ba26-1df898934f4f': 'adobecom',
'079734f3-b593-4c58-8805-592d71f88d95': 'apro-cart-abandoner',
'295bea12-8443-41c9-9da1-8f75df77dd80': 'business',
'235a97a1-bf2e-4e92-bf18-13a9bfcf6ec9': 'cc-lapsed',
'f6553238-548f-4e39-bfa4-b299caaca62e': 'commerce',
'f569e4f9-f20a-4d6e-ba95-2abe4facdd1b': 'creative-cloud',
'5114ecd1-d1ac-4caa-869c-5652ab83afed': 'express',
'1d33382e-0c2c-4d24-8b1f-08be98cee22a': 'firefly',
'3f27d856-bbdd-431b-9e8f-44f6fe0cfbd0': 'helpx',
'5b88bec0-99f2-4736-b2d8-4809463b7fbd': 'illustrator',
'3822c05b-8074-4629-b493-59cc12a78650': 'lightroom',
'5b5c991e-2633-4390-8ee4-e58931da088e': 'photoshop',
'395264bb-b584-45fa-af53-a4396e64838b': 'premiere',
'c02e9190-cc42-47cd-85c0-421924c47f2b': 'sign',
'9aba8c9e-dce9-427e-8122-a6c796ee2d03': 'stock',
},
},
};

const ALLOY_TIMEOUT = 500;
const ALLOY_TIMEOUT = 750;

const WIDTHS = {
split: 1199,
Expand Down
4 changes: 3 additions & 1 deletion libs/blocks/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export function processMarkData(series, xUnit) {
}

export async function fetchData(link) {
const resp = await fetch(link.href.toLowerCase());
const { customFetch } = await import('../../utils/helpers.js');
const resp = await customFetch({ resource: link.href.toLowerCase(), withCacheRules: true })
.catch(() => ({}));

if (!resp.ok) return {};

Expand Down
4 changes: 3 additions & 1 deletion libs/blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export default async function init(a) {
return;
}

const resp = await fetch(`${a.href}.plain.html`);
const { customFetch } = await import('../../utils/helpers.js');
const resp = await customFetch({ resource: `${a.href}.plain.html`, withCacheRules: true })
.catch(() => ({}));

if (!resp.ok) {
window.lana?.log(`Could not get fragment: ${a.href}.plain.html`);
Expand Down
5 changes: 4 additions & 1 deletion libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export const getFederatedContentRoot = () => {
: 'https://www.adobe.com';

if (origin.includes('localhost') || origin.includes('.hlx.')) {
federatedContentRoot = `https://main--federal--adobecom.hlx.${origin.includes('hlx.live') ? 'live' : 'page'}`;
// Akamai as proxy to avoid 401s, given AEM-EDS MS auth cross project limitations
federatedContentRoot = origin.includes('.hlx.live')
? 'https://main--federal--adobecom.hlx.live'
: 'https://www.stage.adobe.com';
}

return federatedContentRoot;
Expand Down
6 changes: 6 additions & 0 deletions libs/blocks/library-container-end/library-container-end.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

.library-container-end,
.section.masonry-layout .library-container-end[class*='grid-'] {
display: none;
}

.library-container-end::before {
display: block;
content: 'Library Container End';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.library-container-start,
.section.masonry-layout .library-container-start[class*='grid-'] {
display: none;
}

.library-container-start::before {
display: block;
content: 'Library Container Start';
Expand Down
9 changes: 4 additions & 5 deletions libs/blocks/library-metadata/library-metadata.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.library-metadata {
margin: 24px auto;
display: block;
}

.library-metadata::before {
Expand All @@ -10,18 +11,16 @@
border-radius: 6px;
text-transform: uppercase;
font-weight: 700;
font-size: smaller;
color: #293c51;
padding: 6px 12px;
}

.library-meta-row {
background-color: #EFEFEF;
display: grid;
grid-template-columns: 1fr 1fr;
margin-top: 4px;
border-radius: 6px;
}

.library-meta-row {
background-color: #EFEFEF;
padding: 6px 12px;
border-radius: 6px;
}
12 changes: 12 additions & 0 deletions libs/blocks/library-metadata/library-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ export default function init(el) {
row.classList.add('library-meta-row');
row.firstElementChild.classList.add('library-meta-key');
});
// Fixes layout issue for groups of blocks using a grid layout
const section = el.closest('.section');
if (section.querySelector('.library-container-end')) {
const content = section.querySelector('.content');
section.insertAdjacentElement('afterend', el);

if (!content) return;
const reflowSection = document.createElement('div');
reflowSection.classList.add('section');
reflowSection.append(content);
section.insertAdjacentElement('beforebegin', reflowSection);
}
}
6 changes: 5 additions & 1 deletion libs/features/footer-promo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createTag, getConfig } from '../utils/utils.js';
import { decorateSectionAnalytics } from '../martech/attributes.js';

async function getPromoFromTaxonomy(contentRoot) {
const NAME_KEY = 'Name';
Expand All @@ -25,7 +26,8 @@ async function getPromoFromTaxonomy(contentRoot) {
}

export default async function initFooterPromo(footerPromoTag, footerPromoType) {
const { locale: { contentRoot } } = getConfig();
const config = getConfig();
const { locale: { contentRoot } } = config;
let href = footerPromoTag && `${contentRoot}/fragments/footer-promos/${footerPromoTag}`;

if (footerPromoType === 'taxonomy') {
Expand All @@ -42,4 +44,6 @@ export default async function initFooterPromo(footerPromoTag, footerPromoType) {
document.querySelector('main > div:last-of-type').insertAdjacentElement('afterend', section);
await loadFragment(a);
section.classList.add('section');
const sections = document.querySelectorAll('main > div');
decorateSectionAnalytics(section, sections.length - 1, config);
}
4 changes: 3 additions & 1 deletion libs/features/icons/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ let fetched = false;
async function getSVGsfromFile(path) {
/* c8 ignore next */
if (!path) return null;
const resp = await fetch(path);
const { customFetch } = await import('../../utils/helpers.js');
const resp = await customFetch({ resource: path, withCacheRules: true })
.catch(() => ({}));
/* c8 ignore next */
if (!resp.ok) return null;
const miloIcons = {};
Expand Down
6 changes: 4 additions & 2 deletions libs/features/placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const getPlaceholdersPath = (config, sheet) => {
return `${path}${query}`;
};

const fetchPlaceholders = (config, sheet) => {
const fetchPlaceholders = async (config, sheet) => {
const placeholdersPath = getPlaceholdersPath(config, sheet);
const { customFetch } = await import('../utils/helpers.js');

fetchedPlaceholders[placeholdersPath] = fetchedPlaceholders[placeholdersPath]
// eslint-disable-next-line no-async-promise-executor
|| new Promise(async (resolve) => {
const resp = await fetch(placeholdersPath).catch(() => ({}));
const resp = await customFetch({ resource: placeholdersPath, withCacheRules: true })
.catch(() => ({}));
const json = resp.ok ? await resp.json() : { data: [] };
if (json.data.length === 0) { resolve({}); return; }
const placeholders = {};
Expand Down
9 changes: 9 additions & 0 deletions libs/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ export function updateLinkWithLangRoot(link) {
return link;
}
}

export async function customFetch({ resource, withCacheRules }) {
const options = {};
if (withCacheRules) {
const params = new URLSearchParams(window.location.search);
options.cache = params.get('cache') === 'off' ? 'reload' : 'default';
}
return fetch(resource, options);
}
13 changes: 13 additions & 0 deletions test/blocks/chart/chart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ setConfig(config);

describe('chart', () => {
let fetch;
let paramsGetStub;

before(() => {
fetch = sinon.stub(window, 'fetch');
paramsGetStub = sinon.stub(URLSearchParams.prototype, 'get');
paramsGetStub.withArgs('cache').returns('off');
});

after(() => {
Expand Down Expand Up @@ -466,6 +469,16 @@ describe('chart', () => {
expect(typeof options.yAxis[0].axisLabel.formatter()).to.equal('string');
});

it('fetchData functions as expected with cache control enabled', async () => {
const link = document.createElement('a');
const linkRel = '/drafts/data-viz/line.json';
link.href = `${linkRel}`;
const goodResponse = { ok: true, json: () => true };
fetch.withArgs(link.href, { cache: 'reload' }).resolves(goodResponse);
const response = await fetchData(link);
expect(response).to.be.true;
});

it('fetchData returns json given an anchor tag', async () => {
const link = document.createElement('a');
const linkRel = '/drafts/data-viz/line.json';
Expand Down
18 changes: 18 additions & 0 deletions test/blocks/fragment/fragment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,31 @@ document.body.innerHTML = await readFile({ path: './mocks/body.html' });
const { default: getFragment } = await import('../../../libs/blocks/fragment/fragment.js');

describe('Fragments', () => {
let paramsGetStub;

before(() => {
paramsGetStub = stub(URLSearchParams.prototype, 'get');
paramsGetStub.withArgs('cache').returns('off');
});

after(() => {
paramsGetStub.restore();
});

it('Loads a fragment', async () => {
const a = document.querySelector('a');
await getFragment(a);
const h1 = document.querySelector('h1');
expect(h1).to.exist;
});

it('Loads a fragment with cache control', async () => {
const a = document.querySelector('a.cache');
await getFragment(a);
const h1 = document.querySelector('h1.frag-cache');
expect(h1).to.exist;
});

it('Doesnt load a fragment', async () => {
const a = document.querySelector('a.bad');
await getFragment(a);
Expand Down
1 change: 1 addition & 0 deletions test/blocks/fragment/mocks/body.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div>
<a href="/test/blocks/fragment/mocks/fragments/fragment">Fragment</a>
<a class="cache" href="/test/blocks/fragment/mocks/fragments/frag-cache">Fragment</a>
<a class="bad" href="/test/blocks/fragment/mocks/fragments/bad">Fragment</a>
<a class="malformed" href="/test/blocks/fragment/mocks/fragments/malform">Fragment</a>
<a class="parent-link" href="/test/blocks/fragment/mocks/fragments/fragment">Fragment</a>
Expand Down
3 changes: 3 additions & 0 deletions test/blocks/fragment/mocks/fragments/frag-cache.plain.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<h1 class="frag-cache">Hello World</1h>
</div>
4 changes: 2 additions & 2 deletions test/blocks/global-navigation/global-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ describe('global navigation', () => {
document.body.replaceChildren(toFragment`<header class="global-navigation"></header>`);
await initGnav(document.body.querySelector('header'));
expect(
fetchStub.calledOnceWith('https://main--federal--adobecom.hlx.page/federal/path/to/gnav.plain.html'),
fetchStub.calledOnceWith('https://www.stage.adobe.com/federal/path/to/gnav.plain.html'),
).to.be.true;
});

Expand All @@ -1403,7 +1403,7 @@ describe('global navigation', () => {
document.body.replaceChildren(toFragment`<header class="global-navigation"></header>`);
await initGnav(document.body.querySelector('header'));
expect(
fetchStub.calledOnceWith('https://main--federal--adobecom.hlx.page/federal/path/to/gnav.plain.html'),
fetchStub.calledOnceWith('https://www.stage.adobe.com/federal/path/to/gnav.plain.html'),
).to.be.true;
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/blocks/global-navigation/test-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const createFullGlobalNavigation = async ({
if (url.endsWith('large-menu-cross-cloud.plain.html')) { return mockRes({ payload: largeMenuCrossCloud }); }
if (url.endsWith('large-menu-active.plain.html')) { return mockRes({ payload: largeMenuActiveMock }); }
if (url.endsWith('large-menu-wide-column.plain.html')) { return mockRes({ payload: largeMenuWideColumnMock }); }
if (url.includes('main--federal--adobecom.hlx.page')
if (url.includes('https://www.stage.adobe.com')
&& url.endsWith('feds-menu.plain.html')) { return mockRes({ payload: largeMenuMock }); }
if (url.includes('gnav')) { return mockRes({ payload: globalNavigation || globalNavigationMock }); }
if (url.includes('correct-promo-fragment')) { return mockRes({ payload: correctPromoFragmentMock }); }
Expand Down
Loading

0 comments on commit 407e72b

Please sign in to comment.