diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_auto_translate.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_auto_translate.js index edf906d5ded3..ceb72858cd62 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_auto_translate.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_auto_translate.js @@ -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( diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_basics.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_basics.js index 30a1e19c7e82..06d394cf3738 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_basics.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_basics.js @@ -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( diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_open_panel.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_open_panel.js index a49059f78fe9..f4744bdcd168 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_open_panel.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_open_panel.js @@ -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( diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer.js index 93ff47385163..5b47a5dae91b 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer.js @@ -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( diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer_settings.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer_settings.js index 4a2959f58ea7..785d75da448d 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer_settings.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_panel_auto_offer_settings.js @@ -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(); diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_switch_languages.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_switch_languages.js index 41183cc9cffd..5ba51751f32d 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_switch_languages.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_switch_languages.js @@ -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", + }, } ); diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_failure.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_failure.js index 7a1c1e4813d6..5558a4de8c49 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_failure.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_failure.js @@ -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", + }, } ); diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_request.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_request.js index 3ebcd0dd411b..b5ed98d9bd0e 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_request.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_translation_request.js @@ -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", + }, } ); diff --git a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_unsupported_lang.js b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_unsupported_lang.js index 838e30cb1af8..2599baae1c8f 100644 --- a/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_unsupported_lang.js +++ b/browser/components/translations/tests/browser/browser_translations_full_page_telemetry_unsupported_lang.js @@ -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(); diff --git a/browser/components/translations/tests/browser/browser_translations_select_telemetry_init_failure_ui.js b/browser/components/translations/tests/browser/browser_translations_select_telemetry_init_failure_ui.js index 14d97c82defa..18a07c625d54 100644 --- a/browser/components/translations/tests/browser/browser_translations_select_telemetry_init_failure_ui.js +++ b/browser/components/translations/tests/browser/browser_translations_select_telemetry_init_failure_ui.js @@ -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, + }, } ); diff --git a/browser/components/translations/tests/browser/browser_translations_select_telemetry_primary_ui.js b/browser/components/translations/tests/browser/browser_translations_select_telemetry_primary_ui.js index 9d913acff638..47b8bd57a28a 100644 --- a/browser/components/translations/tests/browser/browser_translations_select_telemetry_primary_ui.js +++ b/browser/components/translations/tests/browser/browser_translations_select_telemetry_primary_ui.js @@ -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, + }, } ); diff --git a/browser/components/translations/tests/browser/browser_translations_select_telemetry_settings_menu.js b/browser/components/translations/tests/browser/browser_translations_select_telemetry_settings_menu.js index 7cbbd11f9adf..4a9889365045 100644 --- a/browser/components/translations/tests/browser/browser_translations_select_telemetry_settings_menu.js +++ b/browser/components/translations/tests/browser/browser_translations_select_telemetry_settings_menu.js @@ -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, + }, } ); diff --git a/browser/components/translations/tests/browser/browser_translations_select_telemetry_translation_failure_ui.js b/browser/components/translations/tests/browser/browser_translations_select_telemetry_translation_failure_ui.js index 7c840488e3c4..359018d06d5d 100644 --- a/browser/components/translations/tests/browser/browser_translations_select_telemetry_translation_failure_ui.js +++ b/browser/components/translations/tests/browser/browser_translations_select_telemetry_translation_failure_ui.js @@ -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, + }, } ); diff --git a/browser/components/translations/tests/browser/browser_translations_select_telemetry_unsupported_language_ui.js b/browser/components/translations/tests/browser/browser_translations_select_telemetry_unsupported_language_ui.js index 06edb10e5af5..f0ad3efdd91c 100644 --- a/browser/components/translations/tests/browser/browser_translations_select_telemetry_unsupported_language_ui.js +++ b/browser/components/translations/tests/browser/browser_translations_select_telemetry_unsupported_language_ui.js @@ -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, + }, } ); diff --git a/toolkit/components/translations/tests/browser/shared-head.js b/toolkit/components/translations/tests/browser/shared-head.js index 5ebea7da4b09..66152600ac46 100644 --- a/toolkit/components/translations/tests/browser/shared-head.js +++ b/toolkit/components/translations/tests/browser/shared-head.js @@ -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} [expectations.allValuePredicates=[]] - * - An array of function predicates to assert for all event values. - * @param {Array} [expectations.finalValuePredicates=[]] - * - An array of function predicates to assert for only the final event value. + * @param {Record} [expectations.assertForAllEvents] + * - A record of key-value pairs to assert against all events in this category. + * @param {Record} [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` ); } }