"use strict"; const assert = require("node:assert/strict"); const _ = require("lodash"); const {zrequire} = require("./lib/namespace.cjs"); const {run_test} = require("./lib/test.cjs"); const {page_params} = require("./lib/zpage_params.cjs"); // We download our translations in `page_params` (which // are for the user's chosen language), so we simulate // that here for the tests. page_params.request_language = "en"; page_params.translation_data = { "Quote message": "Citer le message", "Copy link to message": "Copier le lien vers le message", "Notification triggers": "Déclencheurs de notification", "You subscribed to channel {name}": "Vous n'êtes pas abonnés au canal {name}", "

The channel {name} does not exist.

Manage your subscriptions on your Channels page.

": "

Le canal {name} n'existe pas.

Gérez vos abonnements sur votre page canaux.

", }; // `i18n.ts` initializes FormatJS and is imported by // `templates.ts`. const {$t, $t_html, get_language_name, get_language_list_columns, initialize} = zrequire("i18n"); run_test("$t", () => { // Normally the id would be provided by babel-plugin-formatjs, but // this test file is not processed by Babel. assert.equal($t({id: "Quote message", defaultMessage: "Quote message"}), "Citer le message"); assert.equal( $t( { id: "You subscribed to channel {name}", defaultMessage: "You subscribed to channel {name}", }, {name: "l'abonnement"}, ), "Vous n'êtes pas abonnés au canal l'abonnement", ); }); run_test("$t_html", () => { assert.equal( $t_html( { id: "

The channel {name} does not exist.

Manage your subscriptions on your Channels page.

", defaultMessage: "

The channel {name} does not exist.

Manage your subscriptions on your Channels page.

", }, { name: "l'abonnement", "z-link": (content_html) => `${content_html.join("")}`, }, ), "

Le canal l'abonnement n'existe pas.

Gérez vos abonnements sur votre page canaux.

", ); }); run_test("t_tag", ({mock_template}) => { // The Quote/Forward labels reach this template already translated, so // assert on a label the template still translates itself. const args = { message_id: "99", should_display_quote_message: true, quote_message_menu_item: "Citer le message", forward_message_menu_item: "Transférer le message", show_quote_and_forward_hotkey_hints: true, editability_menu_item: "Edit message", conversation_time_url: "http://zulip.zulipdev.com/#narrow/channel/101-devel/topic/testing/near/99", }; mock_template("popovers/message_actions_popover.hbs", true, (data, html) => { assert.equal(data, args); assert.ok(html.includes("Copier le lien vers le message")); return ""; }); require("../templates/popovers/message_actions_popover.hbs")(args); }); run_test("{{#tr}} to tag for translation", ({mock_template}) => { const args = { general_settings: [], notification_settings: { desktop_notification_settings: [], mobile_notification_settings: [], email_message_notification_settings: [], other_email_settings: [], }, custom_stream_specific_notification_settings: [], email_notifications_batching_period_values: [], settings_object: { available_notification_sounds: [], }, settings_label: { desktop_icon_count_display: "Unread count badge (appears in desktop sidebar and browser tab)", realm_name_in_email_notifications_policy: "Include organization name in subject of message notification emails", automatically_follow_topics_policy: "Automatically follow topics", automatically_unmute_topics_in_muted_streams_policy: "Automatically unmute topics in muted channels", }, automatically_follow_topics_policy_values: {}, automatically_unmute_topics_in_muted_streams_policy_values: {}, resolved_topic_notice_auto_read_policy_values: {}, desktop_icon_count_display_values: {}, realm_name_in_email_notifications_policy_values: {}, }; // We're actually testing `notification_settings.hbs` here which // is imported as a partial in the file below. We want to test // the partial handling logic in `templates.ts`, that's why we // test the file below instead of directly testing // `notification_settings.hbs`. mock_template("settings/user_notification_settings.hbs", true, (data, html) => { assert.equal(data, args); assert.ok(html.includes("Déclencheurs de notification")); return ""; }); require("../templates/settings/user_notification_settings.hbs")(args); }); run_test("language_list", () => { const language_list = [ {code: "bqi", locale: "bqi", name: "Luri (Bakhtiari)", percent_translated: 5}, {code: "cy", locale: "cy", name: "Cymraeg", percent_translated: 36}, {code: "en", locale: "en", name: "English"}, {code: "en-gb", locale: "en_GB", name: "British English", percent_translated: 99}, {code: "id", locale: "id", name: "Bahasa Indonesia", percent_translated: 32}, {code: "mn", locale: "mn", name: "Mongolian", percent_translated: 53}, {code: "pt", locale: "pt", name: "Português", percent_translated: 81}, {code: "si", locale: "si", name: "Sinhala", percent_translated: 20}, {code: "zh-hans", locale: "zh_Hans", name: "简体中文", percent_translated: 86}, ]; initialize({language_list}); assert.equal(get_language_name("en"), "English"); const successful_formatted_list = [ {code: "bqi", name_with_percent: "Bakhtiari (5%)", selected: false}, {code: "cy", name_with_percent: "Cymraeg (36%)", selected: false}, {code: "en", name_with_percent: "English (United States)", selected: true}, {code: "en-gb", name_with_percent: "English (United Kingdom) (99%)", selected: false}, {code: "id", name_with_percent: "Indonesia (32%)", selected: false}, {code: "mn", name_with_percent: "Монгол (53%)", selected: false}, {code: "pt", name_with_percent: "Português (Brasil) (81%)", selected: false}, {code: "si", name_with_percent: "සිංහල (20%)", selected: false}, {code: "zh-hans", name_with_percent: "中文(简体) (86%)", selected: false}, ]; const formatted_list = get_language_list_columns("en"); for (const element of _.range(0, formatted_list.length)) { assert.equal(formatted_list[element].name, successful_formatted_list[element].name); assert.equal(formatted_list[element].code, successful_formatted_list[element].code); assert.equal( formatted_list[element].name_with_percent, successful_formatted_list[element].name_with_percent, ); assert.equal(formatted_list[element].selected, successful_formatted_list[element].selected); } });