From d9a5545618f1c82e75a8dc0fed053911aee3b1aa Mon Sep 17 00:00:00 2001 From: Katherine Patenio Date: Thu, 26 Oct 2023 20:04:09 +0000 Subject: [PATCH] Bug 1855970 - Add test for review quality explainer link glean event r=perry.mcmanis Differential Revision: https://phabricator.services.mozilla.com/D192006 --- .../shopping/content/analysis-explainer.mjs | 7 +++ .../tests/browser/browser_ui_telemetry.js | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/browser/components/shopping/content/analysis-explainer.mjs b/browser/components/shopping/content/analysis-explainer.mjs index f46cbf56ef58..a32c64dfebc6 100644 --- a/browser/components/shopping/content/analysis-explainer.mjs +++ b/browser/components/shopping/content/analysis-explainer.mjs @@ -27,6 +27,12 @@ class AnalysisExplainer extends MozLitElement { productUrl: { type: String, reflect: true }, }; + static get queries() { + return { + reviewQualityExplainerLink: "#review-quality-url", + }; + } + getGradesDescriptionTemplate() { return html`
@@ -134,6 +140,7 @@ class AnalysisExplainer extends MozLitElement { @click=${this.handleReviewQualityUrlClicked} > { + await clickReviewQualityExplainerLink( + browser, + MOCK_ANALYZED_PRODUCT_RESPONSE + ); + } + ); + + await Services.fog.testFlushAllChildren(); + + let qualityExplainerEvents = + Glean.shopping.surfaceShowQualityExplainerUrlClicked.testGetValue(); + assertEventMatches(qualityExplainerEvents[0], { + category: "shopping", + name: "surface_show_quality_explainer_url_clicked", + }); +}); + function clickReAnalyzeLink(browser, data) { return SpecialPowers.spawn(browser, [data], async mockData => { let shoppingContainer = @@ -415,3 +442,22 @@ function clickPoweredByFakespotLink(browser, data) { fakespotLink.click(); }); } + +function clickReviewQualityExplainerLink(browser, data) { + return SpecialPowers.spawn(browser, [data], async mockData => { + let shoppingContainer = + content.document.querySelector("shopping-container").wrappedJSObject; + shoppingContainer.data = Cu.cloneInto(mockData, content); + await shoppingContainer.updateComplete; + + let analysisExplainerEl = shoppingContainer.analysisExplainerEl; + await analysisExplainerEl.updateComplete; + let reviewQualityLink = analysisExplainerEl.reviewQualityExplainerLink; + + // Prevent link navigation for test. + reviewQualityLink.href = undefined; + await reviewQualityLink.updateComplete; + + reviewQualityLink.click(); + }); +}