Skip to content

Commit

Permalink
fix(MWPW-155964):Lana log error type changed to info. (adobecom#2818)
Browse files Browse the repository at this point in the history
* lana log error type changed

* modified lana logs

* added a few unit tests for lana logs

* Updated tag in  utils.js

* linting error fixed

* linting error fix 2

* unit test fix

* added unit test for vimeo
  • Loading branch information
sharath-kannan authored Sep 12, 2024
1 parent 3679fd0 commit a7c31b7
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 37 deletions.
2 changes: 1 addition & 1 deletion libs/blocks/article-feed/article-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export async function loadTaxonomy() {
a.href = tax.link;
} else {
// eslint-disable-next-line no-console
window.lana.log(`Trying to get a link for an unknown topic: ${topic} (current page)`, { tags: 'errorType=warn,module=article-feed' });
window.lana.log(`Trying to get a link for an unknown topic: ${topic} (current page)`, { tags: 'article-feed' });
a.href = '#';
}
delete a.dataset.topicLink;
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/event-rich-results/event-rich-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function logNullValues(obj) {
Object.keys(obj).forEach((key) => {
const value = obj[key];
if (!value || value === '') {
window.lana.log(`Event property ${key} is not defined`, { tags: 'errorType=warn,module=event-rich-results' });
window.lana.log(`Event property ${key} is not defined`, { tags: 'event-rich-results' });
}
logNullValues(value);
});
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/faas/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const beforeSubmitCallback = () => {
}),
})
.catch((error) => {
window.lana.log(`AA Sandbox Error: ${error.reason || error.error || error.message || error}`, { tags: 'errorType=info,module=faas' });
window.lana.log(`AA Sandbox Error: ${error.reason || error.error || error.message || error}`, { tags: 'faas', errorType: 'i' });
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/library-config/lists/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function formatDom(aemDom, path) {

async function formatTemplate(path) {
const resp = await fetch(path);
if (!resp.ok) window.lana.log('Could not fetch template path', { tags: 'errorType=info,module=sidekick-templates' });
if (!resp.ok) window.lana.log('Could not fetch template path', { tags: 'sidekick-templates', errorType: 'i' });

const html = await resp.text();
const dom = new DOMParser().parseFromString(html, 'text/html');
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/mobile-app-banner/mobile-app-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function getECID() {
if (window.alloy) {
await window.alloy('getIdentity').then((data) => {
ecid = data?.identity?.ECID;
}).catch((err) => window.lana.log(`Error fetching ECID: ${err}`, { tags: 'errorType=error,module=mobile-app-banner' }));
}).catch((err) => window.lana.log(`Error fetching ECID: ${err}`, { tags: 'mobile-app-banner' }));
}
return ecid;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/path-finder/path-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function buildUi(el, path) {
async function setup(el) {
await login({ scopes: SCOPES, telemetry: TELEMETRY });
if (!account.value.username) {
window.lana.log('Could not login to MS Graph', { tags: 'errorType=info,module=path-finder' });
window.lana.log('Could not login to MS Graph', { tags: 'path-finder', errorType: 'i' });
return;
}
el.innerHTML = '';
Expand Down
4 changes: 2 additions & 2 deletions libs/blocks/preflight/panels/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async function spidyCheck(url) {
connectionError();
} catch (e) {
connectionError();
window.lana.log(`There was a problem connecting to the link check API ${url}. ${e}`, { tags: 'errorType=info,module=preflight' });
window.lana.log(`There was a problem connecting to the link check API ${url}. ${e}`, { tags: 'preflight', errorType: 'i' });
}
return false;
}
Expand All @@ -182,7 +182,7 @@ async function getSpidyResults(url, opts) {
return acc;
}, []);
} catch (e) {
window.lana.log(`There was a problem connecting to the link check API ${url}/api/url-http-status. ${e}`, { tags: 'errorType=info,module=preflight' });
window.lana.log(`There was a problem connecting to the link check API ${url}/api/url-http-status. ${e}`, { tags: 'preflight', errorType: 'i' });
return [];
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/quiz-entry/mlField.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getMLResults = async (endpoint, apiKey, threshold, input, count, va
body: JSON.stringify(params),
})
.then((response) => response.json())
.catch((error) => window.lana.log(`ERROR: Fetching fi codes ${error}`, { tags: 'errorType=info,module=quiz-entry' }));
.catch((error) => window.lana.log(`ERROR: Fetching fi codes ${error}`, { tags: 'quiz-entry', errorType: 'i' }));

let value;
let highestProb = null;
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/quiz-entry/quiz-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const App = ({
}
if (fiResults.errors) error = fiResults.errors[0].title;
if (fiResults.error_code) error = fiResults.message;
window.lana.log(`ML results error - ${error}`, { tags: 'errorType=info,module=quiz-entry' });
window.lana.log(`ML results error - ${error}`, { tags: 'quiz-entry', errorType: 'i' });
sendMLFieldAnalytics(fallback, false);
}

Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/quiz-entry/quizPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getSuggestions = async (endpoint, clientId, input, scope) => {
});

if (!response.ok) {
window.lana.log('Failed to fetch suggestions', { tags: 'errorType=info,module=quiz-entry' });
window.lana.log('Failed to fetch suggestions', { tags: 'quiz-entry', errorType: 'i' });
return '';
}

Expand Down
4 changes: 2 additions & 2 deletions libs/blocks/quiz-results/quiz-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function loadFragments(el, experiences) {

function redirectPage(quizUrl, debug, message) {
const url = quizUrl ? getLocalizedURL(quizUrl.text) : 'https://adobe.com';
window.lana.log(message, { tags: 'errorType=error,module=quiz-results' });
window.lana.log(message, { tags: 'quiz-results' });

if (debug === 'quiz-results') {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -97,7 +97,7 @@ export default async function init(el, debug = null, localStoreKey = null) {

loadFragments(el, basic);
} else {
window.lana.log(`${LOADING_ERROR} The quiz-results block is misconfigured`, { tags: 'errorType=error,module=quiz-results' });
window.lana.log(`${LOADING_ERROR} The quiz-results block is misconfigured`, { tags: 'quiz-results' });
return;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/tag-selector/tag-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const TagSelector = ({ consumerUrls = [] }) => {

const fetchCasS = async () => {
const { tags, errorMsg } = await loadCaasTags(caasTagUrl);
if (errorMsg) window.lana.log(`Tag Selector. Error fetching caas tags: ${errorMsg}`, { tags: 'errorType=info,module=tag-selector' });
if (errorMsg) window.lana.log(`Tag Selector. Error fetching caas tags: ${errorMsg}`, { tags: 'tag-selector', errorType: 'i' });

setTagSelectorTags((prevConsumerTags) => ({ CaaS: tags, ...prevConsumerTags }));
};
Expand Down
8 changes: 4 additions & 4 deletions libs/blocks/video-metadata/video-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function addBroadcastEventField(videoObj, blockKey, blockValue) {
videoObj.publication[i][camelize(key)] = blockValue;
break;
default:
window.lana.log(`VideoMetadata -- Unknown BroadcastEvent property: ${blockKey}`, { tags: 'errorType=warn,module=video-metadata' });
window.lana.log(`VideoMetadata -- Unknown BroadcastEvent property: ${blockKey}`, { tags: 'video-metadata' });
break;
}
}
Expand All @@ -45,7 +45,7 @@ function addClipField(videoObj, blockKey, blockValue) {
videoObj.hasPart[i][camelize(key)] = blockValue;
break;
default:
window.lana.log(`VideoMetadata -- Unhandled Clip property: ${blockKey}`, { tags: 'errorType=warn,module=video-metadata' });
window.lana.log(`VideoMetadata -- Unhandled Clip property: ${blockKey}`, { tags: 'video-metadata' });
break;
}
}
Expand All @@ -61,7 +61,7 @@ function addSeekToActionField(videoObj, blockKey, blockValue) {
videoObj.potentialAction['startOffset-input'] = blockValue;
break;
default:
window.lana.log(`VideoMetadata -- Unhandled SeekToAction property: ${blockKey}`, { tags: 'errorType=warn,module=video-metadata' });
window.lana.log(`VideoMetadata -- Unhandled SeekToAction property: ${blockKey}`, { tags: 'video-metadata' });
break;
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ export function createVideoObject(record) {
addSeekToActionField(video, blockKey, blockVal);
break;
default:
window.lana.log(`VideoMetadata -- Unhandled VideoObject property: ${blockKey}`, { tags: 'errorType=warn,module=video-metadata' });
window.lana.log(`VideoMetadata -- Unhandled VideoObject property: ${blockKey}`, { tags: 'video-metadata' });
break;
}
});
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/vimeo/vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LiteVimeo extends HTMLElement {
this.style.backgroundImage = `url("${thumbnailUrl}")`;
})
.catch((e) => {
window.lana.log(`Error fetching Vimeo thumbnail: ${e}`, { tags: 'errorType=info,module=vimeo' });
window.lana.log(`Error fetching Vimeo thumbnail: ${e}`, { tags: 'vimeo', errorType: 'i' });
});
}

Expand Down
2 changes: 1 addition & 1 deletion libs/features/footer-promo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function getPromoFromTaxonomy(contentRoot, doc) {
if (primaryTag) return primaryTag[FOOTER_PROMO_LINK_KEY];
} catch (error) {
/* c8 ignore next 2 */
window.lana.log(`Footer Promo - Taxonomy error: ${error}`, { tags: 'errorType=info,module=footer-promo' });
window.lana.log(`Footer Promo - Taxonomy error: ${error}`, { tags: 'footer-promo', errorType: 'i' });
}
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/martech/martech.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ export const getTargetPersonalization = async () => {
const responseStart = Date.now();
window.addEventListener(ALLOY_SEND_EVENT, () => {
const responseTime = calculateResponseTime(responseStart);
window.lana.log(`target response time: ${responseTime}`, { tags: 'errorType=info,module=martech' });
window.lana.log(`target response time: ${responseTime}`, { tags: 'martech', errorType: 'i' });
}, { once: true });

let manifests = [];
let propositions = [];
const response = await waitForEventOrTimeout(ALLOY_SEND_EVENT, timeout);
if (response.error) {
window.lana.log('target response time: ad blocker', { tags: 'errorType=info,module=martech' });
window.lana.log('target response time: ad blocker', { tags: 'martech', errorType: 'i' });
return [];
}
if (response.timeout) {
Expand Down
28 changes: 19 additions & 9 deletions test/blocks/article-header/article-header.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';

import sinon, { stub } from 'sinon';
import { setConfig, getConfig } from '../../../libs/utils/utils.js';
import { delay, waitForElement } from '../../helpers/waitfor.js';

const locales = { '': { ietf: 'en-US', tk: 'hah7vzn.css' } };
const conf = { locales, miloLibs: 'http://localhost:2000/libs' };
setConfig(conf);
const config = getConfig();
window.lana = { log: stub() };

document.body.innerHTML = await readFile({ path: './mocks/body.html' });
const { default: init } = await import('../../../libs/blocks/article-header/article-header.js');
const { loadTaxonomy } = await import('../../../libs/blocks/article-feed/article-helpers.js');

const invalidDoc = await readFile({ path: './mocks/body-invalid.html' });

Expand All @@ -20,10 +21,20 @@ describe('article header', () => {
const block = document.body.querySelector('.article-header');
config.locale.contentRoot = '/test/blocks/article-header/mocks';
config.taxonomyRoot = undefined;

await init(block);
});

it('should log unknown topic', async () => {
try {
const div = document.createElement('div');
div.setAttribute('data-topic-link', ['abcd']);
document.body.append(div);
await loadTaxonomy();
expect(window.lana.log.args[0][0]).to.equal('Trying to get a link for an unknown topic: abcd (current page)');
} catch (e) {
console.log(e);
}
});
it('creates article header block', () => {
expect(document.body.querySelector('.article-category')).to.exist;
expect(document.body.querySelector('.article-title')).to.exist;
Expand All @@ -36,16 +47,16 @@ describe('article header', () => {
it('should open link popup when share links are clicked', () => {
// first share link is twitter
const shareLink = document.querySelector('.article-byline-sharing a');
const stub = sinon.stub(window, 'open');
const windowStub = sinon.stub(window, 'open');
shareLink.click();

const url = encodeURIComponent(window.location.href);
const title = encodeURIComponent(document.querySelector('h1').textContent);
expect(stub.calledOnce).to.be.true;
expect(stub.firstCall.args[0]).to.equal(`https://www.twitter.com/share?&url=${url}&text=${title}`);
expect(stub.firstCall.args[2]).to.equal('popup,top=233,left=233,width=700,height=467');
expect(windowStub.calledOnce).to.be.true;
expect(windowStub.firstCall.args[0]).to.equal(`https://www.twitter.com/share?&url=${url}&text=${title}`);
expect(windowStub.firstCall.args[2]).to.equal('popup,top=233,left=233,width=700,height=467');

stub.restore();
windowStub.restore();
});

it('updates share text after deferred event', async () => {
Expand Down Expand Up @@ -111,7 +122,6 @@ describe('test the invalid article header', () => {

it('adds invalid-date when invalid date is provided', async () => {
await init(document.body.querySelector('.article-header'));

const date = await waitForElement('.article-date-invalid');
expect(date).to.exist;
});
Expand Down
6 changes: 3 additions & 3 deletions test/blocks/global-footer/global-footer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ describe('global footer', () => {
await createFullGlobalFooter({ waitForDecoration: false });
await clock.runAllAsync();
expect(window.lana.log.getCalls().find((c) => c.args[0].includes('Failed to fetch footer content')));
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('errorType=warn,module=global-footer')));
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('global-footer')));
});

it('should send log when could not create URL for region picker', async () => {
Expand All @@ -393,15 +393,15 @@ describe('global footer', () => {
// should throw error
}
expect(window.lana.log.getCalls().find((c) => c.args[0].includes('Could not create URL for region picker')));
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('errorType=error,module=global-footer')));
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('global-footer')));
});

it('should send log when footer cannot be instantiated ', async () => {
sinon.stub(window, 'DOMParser').callsFake(() => ({ parseFromString: sinon.stub().throws(new Error('Parsing error')) }));
await createFullGlobalFooter({ waitForDecoration: false });
await clock.runAllAsync();
expect(window.lana.log.getCalls().find((c) => c.args[0].includes('Footer could not be instantiated')));
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('errorType=error,module=global-footer')));
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('global-footer')));
});

it('should send LANA log when icons.svg has some network issue', async () => {
Expand Down
10 changes: 10 additions & 0 deletions test/blocks/quiz-results/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,15 @@
<div>http://this-is-a-fake-redirect-url</div>
</div>
</div>
<div class="quiz-results nested-three nested">
<div>
<div>nested-fragments</div>
<div>marquee-product</div>
</div>
<div>
<div>style</div>
<div>m-spacing</div>
</div>
</div>
</div>
</main>
7 changes: 7 additions & 0 deletions test/blocks/quiz-results/quiz-results.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ describe('Quiz Results', () => {
expect(el.querySelector('.fragment > .section > .content').getAttribute('daa-lh')).to.equal('b1|content');
expect(el.querySelector('a').getAttribute('daa-ll')).to.equal('Fragment link-1--This is a basic frag');
});
it('should return misconfigured block', async () => {
const el = document.body.querySelector('.nested-three');
localStorage.setItem('misconf', JSON.stringify(mockData.mockTwo));
el.classList.remove('nested');
await init(el, 'quiz-results', 'misconf');
expect(window.lana.log.args[2][0]).to.equal(`${LOADING_ERROR} The quiz-results block is misconfigured`);
});
});
12 changes: 11 additions & 1 deletion test/blocks/vimeo/vimeo.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<script type="module">
import { runTests } from '@web/test-runner-mocha';
import { readFile } from '@web/test-runner-commands';
import sinon, { stub } from 'sinon';
import { expect } from '@esm-bundle/chai';
import init from '../../../libs/blocks/vimeo/vimeo.js';

import { delay } from '../../helpers/waitfor.js';
window.lana = { log: stub() };
runTests(() => {
describe('vimeo', () => {
it('Should load lite vimeo instead of iframe', async () => {
Expand All @@ -41,6 +43,14 @@
expect(document.querySelector('lite-vimeo')).to.be.null;
});
});

it('Should log error while fetch Vimeo thumbnail', async () => {
const fetchStub = sinon.stub(window, 'fetch');
fetchStub.returns(Promise.reject(new Error('Network Error')));
init(document.querySelector('a'));
await delay(200)
expect(window.lana.log.args[0][0]).equals('Error fetching Vimeo thumbnail: Error: Network Error');
});
});
</script>
</html>
4 changes: 2 additions & 2 deletions test/features/webapp-prompt/webapp-prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('PEP', () => {
}),
});
expect(window.lana.log.getCalls().find((c) => c.args[0].includes('Error on getting anchor state'))).to.exist;
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('errorType=error,module=pep'))).to.exist;
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('pep'))).to.exist;
});

it('should send log when cannot fetch content for prompt', async () => {
Expand All @@ -256,7 +256,7 @@ describe('PEP', () => {
});
await initPep({});
expect(window.lana.log.getCalls().find((c) => c.args[0].includes('Error fetching content for prompt'))).to.exist;
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('errorType=error,module=pep'))).to.exist;
expect(window.lana.log.getCalls().find((c) => c.args[1].tags.includes('pep'))).to.exist;
});
});
});

0 comments on commit a7c31b7

Please sign in to comment.