Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Don’t mock i18n.
Anders Kaseorgb61de3102426
diff --git a/web/tests/alert_words_ui.test.cjs b/web/tests/alert_words_ui.test.cjsindex cd3a9d94e25..376ea439026 100644--- a/web/tests/alert_words_ui.test.cjs+++ b/web/tests/alert_words_ui.test.cjs@@ -91,7 +91,7 @@ run_test("remove_alert_word", ({override_rewire}) => {assert.ok($alert_word_status_banner.hasClass("banner-danger"));assert.equal($alert_word_status_banner_label.text(),- `translated HTML: Error removing alert word <b>translated: zot</b>!`,+ `translated: Error removing alert word <b>translated: zot</b>!`,);// test success@@ -99,6 +99,6 @@ run_test("remove_alert_word", ({override_rewire}) => {assert.ok($alert_word_status_banner.hasClass("banner-success"));assert.equal($alert_word_status_banner_label.text(),- `translated HTML: Alert word <b>translated: zot</b> removed successfully!`,+ `translated: Alert word <b>translated: zot</b> removed successfully!`,);});diff --git a/web/tests/compose.test.cjs b/web/tests/compose.test.cjsindex 76eb8d64313..ec1c9a88155 100644--- a/web/tests/compose.test.cjs+++ b/web/tests/compose.test.cjs@@ -745,7 +745,7 @@ test_ui("on_events", ({override, override_rewire}) => {error_callback();assert.equal(fake_compose_box.preview_content_html(),- "translated HTML: Failed to generate preview",+ "translated: Failed to generate preview",);}@@ -782,10 +782,7 @@ test_ui("on_events", ({override, override_rewire}) => {stopPropagation: noop,});- assert.equal(- fake_compose_box.preview_content_html(),- "translated HTML: Nothing to preview",- );+ assert.equal(fake_compose_box.preview_content_html(), "translated: Nothing to preview");fake_compose_box.assert_preview_mode_is_on();let make_indicator_called = false;diff --git a/web/tests/compose_closed_ui.test.cjs b/web/tests/compose_closed_ui.test.cjsindex 1a5e3739008..ec3550b3e57 100644--- a/web/tests/compose_closed_ui.test.cjs+++ b/web/tests/compose_closed_ui.test.cjs@@ -60,13 +60,11 @@ set_realm(make_realm({realm_empty_topic_display_name: REALM_EMPTY_TOPIC_DISPLAY_// Helper test functionfunction test_reply_label(expected_label) {- const label = $("#left_bar_compose_reply_button_big").html();- const prepend_text_length = "Message ".length;assert.equal(- label.slice(prepend_text_length),+ $("#left_bar_compose_reply_button_big")+ .html()+ .replace(/^(translated: )?Message /, ""),expected_label,- "'" + label.slice(prepend_text_length),- Number("' did not match '") + expected_label + "'",);}@@ -188,8 +186,8 @@ run_test("reply_label", () => {list.select_id(list.next());const label_html = $("#left_bar_compose_reply_button_big").html();assert.equal(- `Message #second_stream > <span class="empty-topic-display">translated: ${REALM_EMPTY_TOPIC_DISPLAY_NAME}</span>`,label_html,+ `translated: Message #second_stream > <span class="empty-topic-display">translated: ${REALM_EMPTY_TOPIC_DISPLAY_NAME}</span>`,);});@@ -222,7 +220,7 @@ run_test("test_non_message_list_input", () => {user_ids: [current_user.user_id],});let label = $("#left_bar_compose_reply_button_big").html();- assert.equal(label, "Write yourself a note");+ assert.equal(label, "translated: Write yourself a note");// Invalid data for a the reply button text.compose_closed_ui.update_recipient_text_for_reply_button({diff --git a/web/tests/deprecated_feature_notice.test.cjs b/web/tests/deprecated_feature_notice.test.cjsindex ae5f03a7557..ba3f9b24d14 100644--- a/web/tests/deprecated_feature_notice.test.cjs+++ b/web/tests/deprecated_feature_notice.test.cjs@@ -13,7 +13,7 @@ const deprecated_feature_notice = zrequire("deprecated_feature_notice");run_test("get_hotkey_deprecation_notice", () => {const expected =- 'translated HTML: We\'ve replaced the "Shift + C" hotkey with "X" to make this common shortcut easier to trigger.';+ 'translated: We\'ve replaced the "Shift + C" hotkey with "X" to make this common shortcut easier to trigger.';const actual = deprecated_feature_notice.get_hotkey_deprecation_notice("Shift + C", "X");assert.equal(actual, expected);});diff --git a/web/tests/i18n.test.cjs b/web/tests/i18n.test.cjsindex d8c90eec0d5..6e7befce2d9 100644--- a/web/tests/i18n.test.cjs+++ b/web/tests/i18n.test.cjs@@ -4,7 +4,7 @@ const assert = require("node:assert/strict");const _ = require("lodash");-const {unmock_module, zrequire} = require("./lib/namespace.cjs");+const {zrequire} = require("./lib/namespace.cjs");const {run_test} = require("./lib/test.cjs");const {page_params} = require("./lib/zpage_params.cjs");@@ -20,11 +20,8 @@ page_params.translation_data = {"<p>Le canal <b>{name}</b> n'existe pas.</p><p>Gérez vos abonnements <z-link>sur votre page canaux</z-link>.</p>",};-// All of our other tests stub out i18n activity;-// here we do a quick sanity check on the engine itself.// `i18n.ts` initializes FormatJS and is imported by// `templates.ts`.-unmock_module("../src/i18n");const {$t, $t_html, get_language_name, get_language_list_columns, initialize} = zrequire("i18n");run_test("$t", () => {diff --git a/web/tests/lib/i18n.cjs b/web/tests/lib/i18n.cjsindex c3793e47543..86b18b60303 100644--- a/web/tests/lib/i18n.cjs+++ b/web/tests/lib/i18n.cjs@@ -1,55 +1,14 @@"use strict";-const {createIntl, createIntlCache} = require("@formatjs/intl");-const _ = require("lodash");+const {zrequire} = require("./namespace.cjs");-const cache = createIntlCache();+const i18n = zrequire("i18n");-exports.intl = createIntl(- {- locale: "en",- defaultLocale: "en",- defaultRichTextElements: Object.fromEntries(- ["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [- tag,- /* istanbul ignore next */- (content_html) => `<${tag}>${content_html.join("")}</${tag}>`,- ]),- ),- },- cache,-);+Object.assign(exports, i18n);-exports.$t = (descriptor, values) => {- descriptor = {- id: `${descriptor.defaultMessage}#${descriptor.description}`,- ...descriptor,- };- return "translated: " + exports.intl.formatMessage(descriptor, values);-};+exports.$t = (descriptor, values, opts) =>+ i18n.$t({id: descriptor.defaultMessage, descriptor}, values, opts);-const default_html_elements = Object.fromEntries(- ["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [- tag,- (content_html) => `<${tag}>${content_html.join("")}</${tag}>`,- ]),-);--exports.$t_html = (descriptor, values) => {- descriptor = {- id: `${descriptor.defaultMessage}#${descriptor.description}`,- ...descriptor,- };- return (- "translated HTML: " +- exports.intl.formatMessage(descriptor, {- ...default_html_elements,- ...Object.fromEntries(- Object.entries(values ?? {}).map(([key, value]) => [- key,- typeof value === "function" ? value : _.escape(value),- ]),- ),- })- );-};+/* istanbul ignore next */+exports.$t_html = (descriptor, values, opts) =>+ i18n.$t_html({id: descriptor.defaultMessage, descriptor}, values, opts);diff --git a/web/tests/lib/index.cjs b/web/tests/lib/index.cjsindex 6027ed37ebc..36ebe1a8dd4 100644--- a/web/tests/lib/index.cjs+++ b/web/tests/lib/index.cjs@@ -10,7 +10,6 @@ const {JSDOM} = require("jsdom");const _ = require("lodash");const handlebars = require("./handlebars.cjs");-const stub_i18n = require("./i18n.cjs");const namespace = require("./namespace.cjs");const test = require("./test.cjs");const blueslip = require("./zblueslip.cjs");@@ -121,8 +120,6 @@ process.exitCode = 1;namespace.mock_esm("../../src/blueslip", blueslip);require("../../src/blueslip.ts");- namespace.mock_esm("../../src/i18n", stub_i18n);- require("../../src/i18n.ts");namespace.mock_esm("../../src/base_page_params", zpage_params);require("../../src/base_page_params.ts");namespace.mock_esm("../../src/billing/page_params", zpage_billing_params);diff --git a/web/tests/lib/namespace.cjs b/web/tests/lib/namespace.cjsindex f739ae29f64..a9be57fb098 100644--- a/web/tests/lib/namespace.cjs+++ b/web/tests/lib/namespace.cjs@@ -173,6 +173,7 @@ exports.mock_esm = (module_path, obj = {}, {callsite = callsites()[1]} = {}) =>return exports.mock_cjs(module_path, {...obj, __esModule: true}, {callsite});};+/* istanbul ignore next */exports.unmock_module = (module_path, {callsite = callsites()[1]} = {}) => {const filename = Module._resolveFilename(module_path,diff --git a/web/tests/lib/zpage_params.cjs b/web/tests/lib/zpage_params.cjsindex 98c588c1260..5db56f11e96 100644--- a/web/tests/lib/zpage_params.cjs+++ b/web/tests/lib/zpage_params.cjs@@ -9,4 +9,14 @@ exports.reset = () => {delete exports.page_params[field];}}+ exports.page_params.request_language = "en";+ exports.page_params.translation_data = new Proxy(+ {},+ {+ get: (_target, key) => `translated: ${key}`,+ getOwnPropertyDescriptor: (_target, _key) => ({configurable: true}),+ },+ );};++exports.reset();diff --git a/web/tests/message_view.test.cjs b/web/tests/message_view.test.cjsindex 56987a353e8..803f8b9f345 100644--- a/web/tests/message_view.test.cjs+++ b/web/tests/message_view.test.cjs@@ -151,7 +151,7 @@ run_test("empty_narrow_html", ({mock_template}) => {`<div class="empty_feed_notice"><h4 class="empty-feed-notice-title"> This is a title </h4><div class="empty-feed-notice-description">- Common words were excluded from your search: <br/>+ translated: Common words were excluded from your search: <br/><del>a</del><span class="search-query-word">search</span></div>@@ -174,7 +174,7 @@ run_test("empty_narrow_html", ({mock_template}) => {`<div class="empty_feed_notice"><h4 class="empty-feed-notice-title"> This is a title </h4><div class="empty-feed-notice-description">- Common words were excluded from your search: <br/>+ translated: Common words were excluded from your search: <br/><del>a</del><span class="search-query-word">search</span><del>and</del>@@ -237,7 +237,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: There are no messages in your combined feed.",- 'translated HTML: Would you like to <a href="#narrow/channels/public">view messages in all public channels</a>?',+ 'translated: Would you like to <a href="#narrow/channels/public">view messages in all public channels</a>?',),);@@ -273,7 +273,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: There are no messages here.",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_stream">start the conversation</a>?',+ 'translated: Why not <a href="#" class="empty_feed_compose_stream">start the conversation</a>?',),);@@ -285,7 +285,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("",- 'translated HTML: This is not a <a target="_blank" rel="noopener noreferrer" href="/help/public-access-option">publicly accessible</a> conversation.',+ 'translated: This is not a <a target="_blank" rel="noopener noreferrer" href="/help/public-access-option">publicly accessible</a> conversation.',),);@@ -298,7 +298,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("",- 'translated HTML: This is not a <a target="_blank" rel="noopener noreferrer" href="/help/public-access-option">publicly accessible</a> conversation.',+ 'translated: This is not a <a target="_blank" rel="noopener noreferrer" href="/help/public-access-option">publicly accessible</a> conversation.',),);@@ -326,7 +326,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: You have no starred messages.",- 'translated HTML: Starring messages is a good way to keep track of important messages, such as tasks you need to go back to, or useful references. To star a message, hover over a message and click the <i class="zulip-icon zulip-icon-star" aria-hidden="true"></i>. <a target="_blank" rel="noopener noreferrer" href="/help/star-a-message">Learn more</a>',+ 'translated: Starring messages is a good way to keep track of important messages, such as tasks you need to go back to, or useful references. To star a message, hover over a message and click the <i class="zulip-icon zulip-icon-star" aria-hidden="true"></i>. <a target="_blank" rel="noopener noreferrer" href="/help/star-a-message">Learn more</a>',),);@@ -336,7 +336,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: This view will show messages where you are mentioned.",- 'translated HTML: To call attention to a message, you can mention a user, a group, topic participants, or all subscribers to a channel. Type @ in the compose box, and choose who you\'d like to mention from the list of suggestions. <a target="_blank" rel="noopener noreferrer" href="/help/mention-a-user-or-group">Learn more</a>',+ 'translated: To call attention to a message, you can mention a user, a group, topic participants, or all subscribers to a channel. Type @ in the compose box, and choose who you\'d like to mention from the list of suggestions. <a target="_blank" rel="noopener noreferrer" href="/help/mention-a-user-or-group">Learn more</a>',),);@@ -348,7 +348,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: You have no direct messages yet!",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',+ 'translated: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',),);@@ -403,7 +403,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: Direct messages are disabled in this organization.",- 'translated HTML: <a target="_blank" rel="noopener noreferrer" href="/help/restrict-direct-messages">Learn more.</a>',+ 'translated: <a target="_blank" rel="noopener noreferrer" href="/help/restrict-direct-messages">Learn more.</a>',),);@@ -416,7 +416,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: You have no direct messages with Example Bot yet.",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',+ 'translated: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',),);@@ -428,7 +428,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: Direct messages are disabled in this organization.",- 'translated HTML: <a target="_blank" rel="noopener noreferrer" href="/help/restrict-direct-messages">Learn more.</a>',+ 'translated: <a target="_blank" rel="noopener noreferrer" href="/help/restrict-direct-messages">Learn more.</a>',),);@@ -440,7 +440,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: You have no direct messages with Alice Smith yet.",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',+ 'translated: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',),);@@ -463,7 +463,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: You haven't sent yourself any notes yet!",- "translated HTML: Use this space for personal notes, or to test out Zulip features.",+ "translated: Use this space for personal notes, or to test out Zulip features.",),);@@ -473,7 +473,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: You have no direct messages with these users yet.",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',+ 'translated: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',),);@@ -511,7 +511,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: Direct messages are disabled in this organization.",- 'translated HTML: <a target="_blank" rel="noopener noreferrer" href="/help/restrict-direct-messages">Learn more.</a>',+ 'translated: <a target="_blank" rel="noopener noreferrer" href="/help/restrict-direct-messages">Learn more.</a>',),);@@ -573,7 +573,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: There are no messages here.",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_stream">start the conversation</a>?',+ 'translated: Why not <a href="#" class="empty_feed_compose_stream">start the conversation</a>?',),);@@ -601,7 +601,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: You have muted all the topics in this channel.",- 'translated HTML: To view a muted topic, click <b>show all topics</b> in the left sidebar, and select one from the list. <a target="_blank" rel="noopener noreferrer" href="/help/mute-a-topic">Learn more</a>',+ 'translated: To view a muted topic, click <b>show all topics</b> in the left sidebar, and select one from the list. <a target="_blank" rel="noopener noreferrer" href="/help/mute-a-topic">Learn more</a>',),);// There are no muted topics in the channel.@@ -611,7 +611,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: There are no messages here.",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_stream">start the conversation</a>?',+ 'translated: Why not <a href="#" class="empty_feed_compose_stream">start the conversation</a>?',),);// The channel does not exist.@@ -633,7 +633,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: None of your messages have emoji reactions yet.",- 'translated HTML: Learn more about emoji reactions <a target="_blank" rel="noopener noreferrer" href="/help/emoji-reactions">here</a>.',+ 'translated: Learn more about emoji reactions <a target="_blank" rel="noopener noreferrer" href="/help/emoji-reactions">here</a>.',),);@@ -736,7 +736,7 @@ run_test("show_invalid_narrow_message", ({mock_template}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: No search results.",- "translated HTML: <p>You are searching for messages that belong to more than one channel, which is not possible.</p>",+ "translated: <p>You are searching for messages that belong to more than one channel, which is not possible.</p>",),);@@ -749,7 +749,7 @@ run_test("show_invalid_narrow_message", ({mock_template}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: No search results.",- "translated HTML: <p>You are searching for messages that belong to more than one topic, which is not possible.</p>",+ "translated: <p>You are searching for messages that belong to more than one topic, which is not possible.</p>",),);@@ -765,7 +765,7 @@ run_test("show_invalid_narrow_message", ({mock_template}) => {$(".empty_feed_notice_main").html(),empty_narrow_html("translated: No search results.",- "translated HTML: <p>You are searching for messages that are sent by more than one person, which is not possible.</p>",+ "translated: <p>You are searching for messages that are sent by more than one person, which is not possible.</p>",),);});diff --git a/web/tests/realm_playground.test.cjs b/web/tests/realm_playground.test.cjsindex 3890a98de32..cb23b193f07 100644--- a/web/tests/realm_playground.test.cjs+++ b/web/tests/realm_playground.test.cjs@@ -2,10 +2,10 @@const assert = require("node:assert/strict");+const {$t} = require("./lib/i18n.cjs");const {zrequire} = require("./lib/namespace.cjs");const {run_test} = require("./lib/test.cjs");-const {$t} = zrequire("i18n");const pygments_data = zrequire("pygments_data");const realm_playground = zrequire("realm_playground");const typeahead_helper = zrequire("typeahead_helper");diff --git a/web/tests/rendered_markdown.test.cjs b/web/tests/rendered_markdown.test.cjsindex 45196e5e8d3..2a9892f69d6 100644--- a/web/tests/rendered_markdown.test.cjs+++ b/web/tests/rendered_markdown.test.cjs@@ -565,7 +565,7 @@ run_test("audio", ({mock_template}) => {'<span class="media-audio-wrapper">\n' +' <audio controls="" preload="metadata" src="http://zulip.zulipdev.com/user_uploads/w/ha/tever/inline.mp3" title="inline.mp3" class="media-audio-element"></audio>\n' +' <a class="media-audio-download icon-button icon-button-square icon-button-neutral"\n' +- ' aria-label="Download" href="http://zulip.zulipdev.com/user_uploads/w/ha/tever/inline.mp3" download>\n' ++ ' aria-label="translated: Download" href="http://zulip.zulipdev.com/user_uploads/w/ha/tever/inline.mp3" download>\n' +' <i class="media-download-icon zulip-icon zulip-icon-download"></i>\n' +" </a>\n" +"</span>",diff --git a/web/tests/settings_realm_domains.test.cjs b/web/tests/settings_realm_domains.test.cjsindex 74804edb23c..fe73e1ed91e 100644--- a/web/tests/settings_realm_domains.test.cjs+++ b/web/tests/settings_realm_domains.test.cjs@@ -48,10 +48,10 @@ function test_realms_domain_modal(override, add_realm_domain) {assert.ok(posted);success_callback();- assert.equal($info.val(), "translated HTML: Added successfully!");+ assert.equal($info.val(), "translated: Added successfully!");error_callback({});- assert.equal($info.val(), "translated HTML: Failed");+ assert.equal($info.val(), "translated: Failed");}function test_change_allow_subdomains(change_allow_subdomains) {@@ -87,13 +87,10 @@ function test_change_allow_subdomains(change_allow_subdomains) {change_allow_subdomains.call(elem_obj, ev);success_callback();- assert.equal(- $info.val(),- "translated HTML: Update successful: Subdomains allowed for example.com",- );+ assert.equal($info.val(), "translated: Update successful: Subdomains allowed for example.com");error_callback({});- assert.equal($info.val(), "translated HTML: Failed");+ assert.equal($info.val(), "translated: Failed");allow = false;elem_obj.checked = allow;@@ -101,7 +98,7 @@ function test_change_allow_subdomains(change_allow_subdomains) {success_callback();assert.equal($info.val(),- "translated HTML: Update successful: Subdomains no longer allowed for example.com",+ "translated: Update successful: Subdomains no longer allowed for example.com",);}