Bug 1870368 - Rework TranslationsTelemetry event assertions r=translations-reviewers,gregtatum

Reworks the telemetry event assertions in the Translations
test suite to show the contents of which values did not match
the expectations in the error message logs, instead of just reporting
`true` or `false` that the value did not match.

Depends on D210959

Differential Revision: https://phabricator.services.mozilla.com/D211054
This commit is contained in:
Erik Nordin 2024-05-23 17:56:38 +00:00
parent 36d5e08f35
commit 670903ed10
15 changed files with 430 additions and 418 deletions

View File

@ -38,19 +38,21 @@ add_task(async function test_translations_telemetry_auto_translate() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
Glean.translationsPanel.alwaysTranslateLanguage,
{
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [value => value.extra.language === "es"],
assertForMostRecentEvent: {
language: "es",
},
}
);
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.close, {
@ -66,9 +68,9 @@ add_task(async function test_translations_telemetry_auto_translate() {
{
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.request_target === "full-page",
],
assertForMostRecentEvent: {
request_target: "full-page",
},
}
);
@ -81,12 +83,12 @@ add_task(async function test_translations_telemetry_auto_translate() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 2,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "revisitView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "revisitView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(

View File

@ -31,12 +31,12 @@ add_task(async function test_translations_telemetry_basics() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
@ -61,12 +61,12 @@ add_task(async function test_translations_telemetry_basics() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 2,
expectNewFlowId: true,
allValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForAllEvents: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(

View File

@ -30,12 +30,12 @@ add_task(async function test_translations_telemetry_open_panel() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
@ -60,12 +60,12 @@ add_task(async function test_translations_telemetry_open_panel() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 2,
expectNewFlowId: true,
allValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForAllEvents: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(

View File

@ -18,12 +18,12 @@ add_task(async function test_translations_panel_auto_offer() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
allValuePredicates: [
value => value.extra.auto_show === "true",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForAllEvents: {
auto_show: true,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
@ -58,12 +58,12 @@ add_task(async function test_translations_panel_auto_offer() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 2,
expectNewFlowId: true,
allValuePredicates: [
value => value.extra.auto_show === "true",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForAllEvents: {
auto_show: true,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(

View File

@ -35,12 +35,12 @@ add_task(async function test_translations_panel_auto_offer_settings() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
allValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForAllEvents: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await FullPageTranslationsTestUtils.clickAlwaysOfferTranslations();
@ -50,7 +50,9 @@ add_task(async function test_translations_panel_auto_offer_settings() {
{
expectedEventCount: 1,
expectNewFlowId: false,
allValuePredicates: [value => value.extra.toggled_on === "true"],
assertForAllEvents: {
toggled_on: true,
},
}
);
@ -66,12 +68,12 @@ add_task(async function test_translations_panel_auto_offer_settings() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 2,
expectNewFlowId: true,
allValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForAllEvents: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
@ -98,12 +100,12 @@ add_task(async function test_translations_panel_auto_offer_settings() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 3,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "true",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: true,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await cleanup();

View File

@ -29,19 +29,21 @@ add_task(async function test_translations_telemetry_switch_from_language() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
Glean.translationsPanel.changeFromLanguage,
{
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [value => value.extra.language === "en"],
assertForMostRecentEvent: {
language: "en",
},
}
);
@ -52,7 +54,9 @@ add_task(async function test_translations_telemetry_switch_from_language() {
{
expectedEventCount: 2,
expectNewFlowId: false,
finalValuePredicates: [value => value.extra.language === "es"],
assertForMostRecentEvent: {
language: "es",
},
}
);
@ -72,7 +76,9 @@ add_task(async function test_translations_telemetry_switch_from_language() {
{
expectedEventCount: 3,
expectNewFlowId: false,
finalValuePredicates: [value => value.extra.language === "en"],
assertForMostRecentEvent: {
language: "en",
},
}
);
@ -105,19 +111,21 @@ add_task(async function test_translations_telemetry_switch_to_language() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
Glean.translationsPanel.changeToLanguage,
{
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [value => value.extra.language === "fr"],
assertForMostRecentEvent: {
language: "fr",
},
}
);
@ -128,7 +136,9 @@ add_task(async function test_translations_telemetry_switch_to_language() {
{
expectedEventCount: 2,
expectNewFlowId: false,
finalValuePredicates: [value => value.extra.language === "en"],
assertForMostRecentEvent: {
language: "en",
},
}
);
@ -148,7 +158,9 @@ add_task(async function test_translations_telemetry_switch_to_language() {
{
expectedEventCount: 3,
expectNewFlowId: false,
finalValuePredicates: [value => value.extra.language === "en"],
assertForMostRecentEvent: {
language: "en",
},
}
);

View File

@ -51,12 +51,12 @@ add_task(
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await FullPageTranslationsTestUtils.clickTranslateButton({
@ -69,12 +69,12 @@ add_task(
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 2,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.auto_show === "true",
value => value.extra.view_name === "errorView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: true,
view_name: "errorView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
Glean.translationsPanel.translateButton,
@ -103,24 +103,23 @@ add_task(
await TestTranslationsTelemetry.assertEvent(Glean.translations.error, {
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [
value =>
value.extra.reason === "Error: Intentionally rejecting downloads.",
],
assertForMostRecentEvent: {
reason: "Error: Intentionally rejecting downloads.",
},
});
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.auto_translate === "false",
value => value.extra.document_language === "es",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "full-page",
],
assertForMostRecentEvent: {
from_language: "es",
to_language: "en",
auto_translate: false,
document_language: "es",
top_preferred_language: "en",
request_target: "full-page",
},
}
);
@ -162,12 +161,12 @@ add_task(async function test_translations_telemetry_auto_translation_failure() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "true",
value => value.extra.view_name === "errorView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: true,
view_name: "errorView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.close, {
expectedEventCount: 0,
@ -176,24 +175,23 @@ add_task(async function test_translations_telemetry_auto_translation_failure() {
await TestTranslationsTelemetry.assertEvent(Glean.translations.error, {
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [
value =>
value.extra.reason === "Error: Intentionally rejecting downloads.",
],
assertForMostRecentEvent: {
reason: "Error: Intentionally rejecting downloads.",
},
});
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.auto_translate === "true",
value => value.extra.document_language === "es",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "full-page",
],
assertForMostRecentEvent: {
from_language: "es",
to_language: "en",
auto_translate: true,
document_language: "es",
top_preferred_language: "en",
request_target: "full-page",
},
}
);

View File

@ -69,12 +69,12 @@ add_task(async function test_translations_telemetry_manual_translation() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "translationsButton",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "translationsButton",
document_language: "es",
},
});
await TestTranslationsTelemetry.assertEvent(
Glean.translationsPanel.translateButton,
@ -92,14 +92,14 @@ add_task(async function test_translations_telemetry_manual_translation() {
{
expectedEventCount: 1,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.auto_translate === "false",
value => value.extra.document_language === "es",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "full-page",
],
assertForMostRecentEvent: {
from_language: "es",
to_language: "en",
auto_translate: false,
document_language: "es",
top_preferred_language: "en",
request_target: "full-page",
},
}
);
@ -157,14 +157,14 @@ add_task(async function test_translations_telemetry_auto_translation() {
{
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.auto_translate === "true",
value => value.extra.document_language === "es",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "full-page",
],
assertForMostRecentEvent: {
from_language: "es",
to_language: "en",
auto_translate: true,
document_language: "es",
top_preferred_language: "en",
request_target: "full-page",
},
}
);

View File

@ -26,12 +26,12 @@ add_task(async function test_translations_telemetry_unsupported_lang() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "appMenu",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "appMenu",
document_language: "es",
},
});
await FullPageTranslationsTestUtils.clickChangeSourceLanguageButton({
@ -52,12 +52,12 @@ add_task(async function test_translations_telemetry_unsupported_lang() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 2,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "appMenu",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "appMenu",
document_language: "es",
},
});
await FullPageTranslationsTestUtils.clickCancelButton();
@ -84,12 +84,12 @@ add_task(async function test_translations_telemetry_unsupported_lang() {
await TestTranslationsTelemetry.assertEvent(Glean.translationsPanel.open, {
expectedEventCount: 3,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.auto_show === "false",
value => value.extra.view_name === "defaultView",
value => value.extra.opened_from === "appMenu",
value => value.extra.document_language === "es",
],
assertForMostRecentEvent: {
auto_show: false,
view_name: "defaultView",
opened_from: "appMenu",
document_language: "es",
},
});
await FullPageTranslationsTestUtils.clickDismissErrorButton();

View File

@ -26,12 +26,12 @@ add_task(
{
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
@ -64,12 +64,12 @@ add_task(
{
expectedEventCount: 2,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
@ -104,12 +104,12 @@ add_task(
{
expectedEventCount: 3,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
@ -140,32 +140,31 @@ add_task(
{
expectedEventCount: 4,
expectNewFlowId: false,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 1,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value =>
value.extra.source_text_code_units ===
(AppConstants.platform === "win"
? "2064" // With carriage returns
: "2041"), // No carriage returns
value => value.extra.source_text_word_count === "358",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units:
AppConstants.platform === "win"
? 2064 // With carriage returns
: 2041, // No carriage returns
source_text_word_count: 358,
},
}
);

View File

@ -41,28 +41,28 @@ add_task(
{
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 1,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value => value.extra.source_text_code_units === "165",
value => value.extra.source_text_word_count === "28",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units: 165,
source_text_word_count: 28,
},
}
);
@ -83,16 +83,16 @@ add_task(
Glean.translations.translationRequest,
{
expectedEventCount: 2,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fi",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value => value.extra.source_text_code_units === "165",
value => value.extra.source_text_word_count === "28",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fi",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units: 165,
source_text_word_count: 28,
},
}
);
@ -131,28 +131,28 @@ add_task(
{
expectedEventCount: 2,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 3,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value => value.extra.source_text_code_units === "165",
value => value.extra.source_text_word_count === "28",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units: 165,
source_text_word_count: 28,
},
}
);
@ -166,16 +166,16 @@ add_task(
Glean.translations.translationRequest,
{
expectedEventCount: 4,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "fa",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value => value.extra.source_text_code_units === "165",
value => value.extra.source_text_word_count === "28",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "fa",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units: 165,
source_text_word_count: 28,
},
}
);
@ -204,14 +204,14 @@ add_task(
Glean.translations.translationRequest,
{
expectedEventCount: 5,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "fa",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "full-page",
value => value.extra.auto_translate === "false",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "fa",
top_preferred_language: "en",
request_target: "full-page",
auto_translate: false,
},
}
);

View File

@ -28,28 +28,28 @@ add_task(
{
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 1,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value => value.extra.source_text_code_units == "56",
value => value.extra.source_text_word_count === "9",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units: 56,
source_text_word_count: 9,
},
}
);

View File

@ -30,42 +30,41 @@ add_task(
{
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 1,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value =>
value.extra.source_text_code_units ===
(AppConstants.platform === "win"
? "1616" // With carriage returns
: "1607"), // No carriage returns
value => value.extra.source_text_word_count === "257",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units:
AppConstants.platform === "win"
? 1616 // With carriage returns
: 1607, // No carriage returns
source_text_word_count: 257,
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translationsSelectTranslationsPanel.translationFailureMessage,
{
expectedEventCount: 1,
finalValuePredicates: [
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
],
assertForMostRecentEvent: {
from_language: "fr",
to_language: "en",
},
}
);
@ -84,30 +83,29 @@ add_task(
Glean.translations.translationRequest,
{
expectedEventCount: 2,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value =>
value.extra.source_text_code_units ===
(AppConstants.platform === "win"
? "1616" // With carriage returns
: "1607"), // No carriage returns
value => value.extra.source_text_word_count === "257",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units:
AppConstants.platform === "win"
? 1616 // With carriage returns
: 1607, // No carriage returns
source_text_word_count: 257,
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translationsSelectTranslationsPanel.translationFailureMessage,
{
expectedEventCount: 2,
finalValuePredicates: [
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
],
assertForMostRecentEvent: {
from_language: "fr",
to_language: "en",
},
}
);
@ -139,42 +137,41 @@ add_task(
{
expectedEventCount: 2,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translations.translationRequest,
{
expectedEventCount: 3,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value =>
value.extra.source_text_code_units ===
(AppConstants.platform === "win"
? "1616" // With carriage returns
: "1607"), // No carriage returns
value => value.extra.source_text_word_count === "257",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units:
AppConstants.platform === "win"
? 1616 // With carriage returns
: 1607, // No carriage returns
source_text_word_count: 257,
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translationsSelectTranslationsPanel.translationFailureMessage,
{
expectedEventCount: 3,
finalValuePredicates: [
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
],
assertForMostRecentEvent: {
from_language: "fr",
to_language: "en",
},
}
);
@ -192,20 +189,19 @@ add_task(
Glean.translations.translationRequest,
{
expectedEventCount: 4,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value =>
value.extra.source_text_code_units ===
(AppConstants.platform === "win"
? "1616" // With carriage returns
: "1607"), // No carriage returns
value => value.extra.source_text_word_count === "257",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units:
AppConstants.platform === "win"
? 1616 // With carriage returns
: 1607, // No carriage returns
source_text_word_count: 257,
},
}
);

View File

@ -30,22 +30,22 @@ add_task(
{
expectedEventCount: 1,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translationsSelectTranslationsPanel.unsupportedLanguageMessage,
{
expectedEventCount: 1,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.detected_language === "es",
],
assertForMostRecentEvent: {
document_language: "es",
detected_language: "es",
},
}
);
@ -73,22 +73,22 @@ add_task(
{
expectedEventCount: 2,
expectNewFlowId: true,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "es",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "es",
to_language: "en",
top_preferred_language: "en",
},
}
);
await TestTranslationsTelemetry.assertEvent(
Glean.translationsSelectTranslationsPanel.unsupportedLanguageMessage,
{
expectedEventCount: 2,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.detected_language === "es",
],
assertForMostRecentEvent: {
document_language: "es",
detected_language: "es",
},
}
);
@ -109,20 +109,19 @@ add_task(
Glean.translations.translationRequest,
{
expectedEventCount: 1,
finalValuePredicates: [
value => value.extra.document_language === "es",
value => value.extra.from_language === "fr",
value => value.extra.to_language === "en",
value => value.extra.top_preferred_language === "en",
value => value.extra.request_target === "select",
value => value.extra.auto_translate === "false",
value =>
value.extra.source_text_code_units ===
(AppConstants.platform === "win"
? "2064" // With carriage returns
: "2041"), // No carriage returns
value => value.extra.source_text_word_count === "358",
],
assertForMostRecentEvent: {
document_language: "es",
from_language: "fr",
to_language: "en",
top_preferred_language: "en",
request_target: "select",
auto_translate: false,
source_text_code_units:
AppConstants.platform === "win"
? 2064 // With carriage returns
: 2041, // No carriage returns
source_text_word_count: 358,
},
}
);

View File

@ -1215,18 +1215,18 @@ class TestTranslationsTelemetry {
* @param {object} expectations - The test expectations.
* @param {number} expectations.expectedEventCount - The expected count of events.
* @param {boolean} expectations.expectNewFlowId
* @param {Array<Function>} [expectations.allValuePredicates=[]]
* - An array of function predicates to assert for all event values.
* @param {Array<Function>} [expectations.finalValuePredicates=[]]
* - An array of function predicates to assert for only the final event value.
* @param {Record<string, string | boolean | number>} [expectations.assertForAllEvents]
* - A record of key-value pairs to assert against all events in this category.
* @param {Record<string, string | boolean | number>} [expectations.assertForMostRecentEvent]
* - A record of key-value pairs to assert against the most recently recorded event in this category.
*/
static async assertEvent(
event,
{
expectedEventCount,
expectNewFlowId = null,
allValuePredicates = [],
finalValuePredicates = [],
assertForAllEvents = {},
assertForMostRecentEvent = {},
}
) {
// Ensures that glean metrics are collected from all child processes
@ -1277,34 +1277,38 @@ class TestTranslationsTelemetry {
`There should be ${expectedEventCount} telemetry events of type ${name}`
);
if (allValuePredicates.length !== 0) {
if (Object.keys(assertForAllEvents).length !== 0) {
is(
eventCount > 0,
true,
`Telemetry event ${name} should contain values if allPredicates are specified`
`Telemetry event ${name} should contain values if assertForMostRecentEvent are specified`
);
for (const value of events) {
for (const predicate of allValuePredicates) {
for (const [key, expectedEntry] of Object.entries(
assertForMostRecentEvent
)) {
for (const event of events) {
is(
predicate(value),
true,
`Telemetry event ${name} allPredicate { ${predicate.toString()} } should pass for each value`
event.extra[key],
String(expectedEntry),
`Telemetry event ${name} value for ${key} should match the expected entry`
);
}
}
}
if (finalValuePredicates.length !== 0) {
if (Object.keys(assertForMostRecentEvent).length !== 0) {
is(
eventCount > 0,
true,
`Telemetry event ${name} should contain values if finalPredicates are specified`
`Telemetry event ${name} should contain values if assertForMostRecentEvent are specified`
);
for (const predicate of finalValuePredicates) {
for (const [key, expectedEntry] of Object.entries(
assertForMostRecentEvent
)) {
is(
predicate(events[eventCount - 1]),
true,
`Telemetry event ${name} finalPredicate { ${predicate.toString()} } should pass for final value`
events[eventCount - 1].extra[key],
String(expectedEntry),
`Telemetry event ${name} value for ${key} should match the expected entry`
);
}
}