2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-06-15 22:37:07 +02:00
|
|
|
const _ = require("lodash");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {unmock_module, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
node tests: Actually test `translations.js`.
Before this test, we were validating the behavior
of `i18next`, but we weren't validating our light
layer that sits on top of `i18next`, which currently
resides in the slightly misnamed `translations.js`
file.
The translations module is now so small that I'll
just quote it verbatim here:
import i18next from 'i18next';
i18next.init({
lng: 'lang',
resources: {
lang: {
translation: page_params.translation_data,
},
},
nsSeparator: false,
keySeparator: false,
interpolation: {
prefix: "__",
suffix: "__",
},
returnEmptyString: false, // Empty string is not a valid translation.
});
window.i18n = i18next;
We now just do `zrequire('translations')` to initialize
the `i18next` library, which allows us to have simpler
test setup and to actually exercise the above call to
`i18next.init`.
This change now gives us 100% line coverage of `translations.js`,
which of course isn't that hard to acheive (see above).
2020-02-29 12:59:56 +01:00
|
|
|
// We download our translations in `page_params` (which
|
|
|
|
// are for the user's chosen language), so we simulate
|
|
|
|
// that here for the tests.
|
2021-04-27 20:17:26 +02:00
|
|
|
page_params.request_language = "en";
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.translation_data = {
|
2023-05-15 20:55:42 +02:00
|
|
|
"Quote and reply": "Citer et répondre",
|
2021-04-10 03:11:59 +02:00
|
|
|
"Notification triggers": "Déclencheurs de notification",
|
2024-04-19 17:53:34 +02:00
|
|
|
"You subscribed to channel {name}": "Vous n'êtes pas abonnés au canal {name}",
|
|
|
|
"<p>The channel <b>{name}</b> does not exist.</p><p>Manage your subscriptions <z-link>on your Channels page</z-link>.</p>":
|
|
|
|
"<p>Le canal <b>{name}</b> n'existe pas.</p><p>Gérez vos abonnements <z-link>sur votre page canaux</z-link>.</p>",
|
2021-03-25 22:35:45 +01:00
|
|
|
};
|
2016-05-13 12:44:03 +02:00
|
|
|
|
2021-10-13 09:41:02 +02:00
|
|
|
// Re-register Zulip extensions so extensions registered previously with
|
2022-02-08 00:13:33 +01:00
|
|
|
// mocked i18n.ts do not interfere with following tests.
|
2023-02-22 23:04:10 +01:00
|
|
|
require("../src/templates");
|
2021-10-13 09:41:02 +02:00
|
|
|
|
node tests: Actually test `translations.js`.
Before this test, we were validating the behavior
of `i18next`, but we weren't validating our light
layer that sits on top of `i18next`, which currently
resides in the slightly misnamed `translations.js`
file.
The translations module is now so small that I'll
just quote it verbatim here:
import i18next from 'i18next';
i18next.init({
lng: 'lang',
resources: {
lang: {
translation: page_params.translation_data,
},
},
nsSeparator: false,
keySeparator: false,
interpolation: {
prefix: "__",
suffix: "__",
},
returnEmptyString: false, // Empty string is not a valid translation.
});
window.i18n = i18next;
We now just do `zrequire('translations')` to initialize
the `i18next` library, which allows us to have simpler
test setup and to actually exercise the above call to
`i18next.init`.
This change now gives us 100% line coverage of `translations.js`,
which of course isn't that hard to acheive (see above).
2020-02-29 12:59:56 +01:00
|
|
|
// All of our other tests stub out i18n activity;
|
|
|
|
// here we do a quick sanity check on the engine itself.
|
2023-03-11 08:13:37 +01:00
|
|
|
// `i18n.ts` initializes FormatJS and is imported by
|
2021-04-10 09:38:17 +02:00
|
|
|
// `templates.js`.
|
2023-02-22 23:04:10 +01:00
|
|
|
unmock_module("../src/i18n");
|
2021-06-18 02:16:48 +02:00
|
|
|
const {$t, $t_html, get_language_name, get_language_list_columns, initialize} = zrequire("i18n");
|
node tests: Actually test `translations.js`.
Before this test, we were validating the behavior
of `i18next`, but we weren't validating our light
layer that sits on top of `i18next`, which currently
resides in the slightly misnamed `translations.js`
file.
The translations module is now so small that I'll
just quote it verbatim here:
import i18next from 'i18next';
i18next.init({
lng: 'lang',
resources: {
lang: {
translation: page_params.translation_data,
},
},
nsSeparator: false,
keySeparator: false,
interpolation: {
prefix: "__",
suffix: "__",
},
returnEmptyString: false, // Empty string is not a valid translation.
});
window.i18n = i18next;
We now just do `zrequire('translations')` to initialize
the `i18next` library, which allows us to have simpler
test setup and to actually exercise the above call to
`i18next.init`.
This change now gives us 100% line coverage of `translations.js`,
which of course isn't that hard to acheive (see above).
2020-02-29 12:59:56 +01:00
|
|
|
|
2021-04-10 03:11:59 +02:00
|
|
|
run_test("$t", () => {
|
|
|
|
// Normally the id would be provided by babel-plugin-formatjs, but
|
|
|
|
// this test file is not processed by Babel.
|
|
|
|
assert.equal(
|
2023-05-15 20:55:42 +02:00
|
|
|
$t({id: "Quote and reply", defaultMessage: "Quote and reply"}),
|
|
|
|
"Citer et répondre",
|
2021-04-10 03:11:59 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
$t(
|
|
|
|
{
|
2024-04-19 17:53:34 +02:00
|
|
|
id: "You subscribed to channel {name}",
|
|
|
|
defaultMessage: "You subscribed to channel {name}",
|
2021-04-10 03:11:59 +02:00
|
|
|
},
|
2024-04-19 17:53:34 +02:00
|
|
|
{name: "l'abonnement"},
|
2021-04-10 03:11:59 +02:00
|
|
|
),
|
|
|
|
"Vous n'êtes pas abonnés au canal l'abonnement",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("$tr", () => {
|
|
|
|
assert.equal(
|
|
|
|
$t_html(
|
|
|
|
{
|
2024-04-19 17:53:34 +02:00
|
|
|
id: "<p>The channel <b>{name}</b> does not exist.</p><p>Manage your subscriptions <z-link>on your Channels page</z-link>.</p>",
|
2021-04-10 03:11:59 +02:00
|
|
|
defaultMessage:
|
2024-04-19 17:53:34 +02:00
|
|
|
"<p>The channel <b>{name}</b> does not exist.</p><p>Manage your subscriptions <z-link>on your Channels page</z-link>.</p>",
|
2021-04-10 03:11:59 +02:00
|
|
|
},
|
|
|
|
{
|
2024-04-19 17:53:34 +02:00
|
|
|
name: "l'abonnement",
|
|
|
|
"z-link": (content_html) => `<a href='#channels/all'>${content_html.join("")}</a>`,
|
2021-04-10 03:11:59 +02:00
|
|
|
},
|
|
|
|
),
|
2024-04-19 17:53:34 +02:00
|
|
|
"<p>Le canal <b>l'abonnement</b> n'existe pas.</p><p>Gérez vos abonnements <a href='#channels/all'>sur votre page canaux</a>.</p>",
|
2021-04-10 03:11:59 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
run_test("t_tag", ({mock_template}) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = {
|
2023-03-22 10:12:58 +01:00
|
|
|
message_id: "99",
|
2018-03-28 00:28:57 +02:00
|
|
|
should_display_quote_and_reply: true,
|
2023-03-22 10:12:58 +01:00
|
|
|
editability_menu_item: true,
|
|
|
|
should_display_hide_option: true,
|
2023-04-09 05:22:23 +02:00
|
|
|
conversation_time_url:
|
2023-03-22 10:12:58 +01:00
|
|
|
"http://zulip.zulipdev.com/#narrow/stream/101-devel/topic/testing/near/99",
|
2016-05-13 12:44:03 +02:00
|
|
|
};
|
|
|
|
|
2024-05-18 08:36:20 +02:00
|
|
|
mock_template("popovers/message_actions_popover.hbs", true, (data, html) => {
|
2021-06-27 19:11:11 +02:00
|
|
|
assert.equal(data, args);
|
2024-04-03 23:52:49 +02:00
|
|
|
assert.ok(html.includes("Citer et répondre"));
|
2021-06-27 19:11:11 +02:00
|
|
|
});
|
|
|
|
|
2024-05-18 08:36:20 +02:00
|
|
|
require("../templates/popovers/message_actions_popover.hbs")(args);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2016-05-13 12:44:03 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
run_test("tr_tag", ({mock_template}) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = {
|
2023-03-22 10:12:58 +01:00
|
|
|
botserverrc: "botserverrc",
|
|
|
|
date_joined_text: "Mar 21, 2022",
|
2024-03-06 17:25:31 +01:00
|
|
|
information_density_settings: {
|
|
|
|
settings: {},
|
|
|
|
},
|
2023-03-22 10:12:58 +01:00
|
|
|
display_settings: {
|
|
|
|
settings: {},
|
|
|
|
},
|
|
|
|
notification_settings: {},
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user: {
|
2017-04-27 00:26:49 +02:00
|
|
|
full_name: "John Doe",
|
2023-03-22 10:12:58 +01:00
|
|
|
delivery_email: "john@zulip.com",
|
2021-07-28 16:00:58 +02:00
|
|
|
},
|
2024-02-13 02:08:16 +01:00
|
|
|
page_params: {},
|
2024-02-13 02:08:24 +01:00
|
|
|
realm: {},
|
2023-03-22 10:12:58 +01:00
|
|
|
settings_object: {},
|
|
|
|
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",
|
|
|
|
twenty_four_hour_time: "Time format",
|
2023-08-20 01:28:15 +02:00
|
|
|
automatically_follow_topics_policy: "Automatically follow topics",
|
|
|
|
automatically_unmute_topics_in_muted_streams_policy:
|
2024-04-18 18:36:57 +02:00
|
|
|
"Automatically unmute topics in muted channels",
|
2023-12-10 14:53:52 +01:00
|
|
|
automatically_follow_topics_where_mentioned:
|
|
|
|
"Automatically follow topics where I'm mentioned",
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2023-03-22 10:12:58 +01:00
|
|
|
show_push_notifications_tooltip: false,
|
|
|
|
user_role_text: "Member",
|
2016-05-13 12:44:03 +02:00
|
|
|
};
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("settings_tab.hbs", true, (data, html) => {
|
2021-06-27 19:11:11 +02:00
|
|
|
assert.equal(data, args);
|
2024-04-03 23:52:49 +02:00
|
|
|
assert.ok(html.includes("Déclencheurs de notification"));
|
2021-06-27 19:11:11 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
require("../templates/settings_tab.hbs")(args);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2021-06-15 22:37:07 +02:00
|
|
|
|
|
|
|
run_test("language_list", () => {
|
2021-06-18 02:16:48 +02:00
|
|
|
const language_list = [
|
2021-06-15 22:37:07 +02:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
];
|
2021-06-18 02:16:48 +02:00
|
|
|
initialize({language_list});
|
|
|
|
assert.equal(get_language_name("en"), "English");
|
2021-06-15 22:37:07 +02:00
|
|
|
|
|
|
|
const successful_formatted_list = [
|
|
|
|
{
|
2022-06-06 15:38:17 +02:00
|
|
|
name: "English",
|
|
|
|
code: "en",
|
|
|
|
name_with_percent: "English",
|
|
|
|
selected: true,
|
2021-06-15 22:37:07 +02:00
|
|
|
},
|
|
|
|
{
|
2022-06-06 15:38:17 +02:00
|
|
|
name: "British English",
|
|
|
|
code: "en-gb",
|
|
|
|
name_with_percent: "British English (99%)",
|
|
|
|
selected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Bahasa Indonesia",
|
|
|
|
code: "id",
|
|
|
|
name_with_percent: "Bahasa Indonesia (32%)",
|
|
|
|
selected: false,
|
2021-06-15 22:37:07 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const formatted_list = get_language_list_columns("en");
|
|
|
|
|
2022-06-06 15:38:17 +02:00
|
|
|
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);
|
2021-06-15 22:37:07 +02:00
|
|
|
assert.equal(
|
2022-06-06 15:38:17 +02:00
|
|
|
formatted_list[element].name_with_percent,
|
|
|
|
successful_formatted_list[element].name_with_percent,
|
2021-06-15 22:37:07 +02:00
|
|
|
);
|
2022-06-06 15:38:17 +02:00
|
|
|
assert.equal(formatted_list[element].selected, successful_formatted_list[element].selected);
|
2021-06-15 22:37:07 +02:00
|
|
|
}
|
|
|
|
});
|