From bb1e089f667fa15154e66b63759edd9d6e7b6ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Fri, 23 Aug 2019 09:53:19 +0000 Subject: [PATCH] Bug 1575823 - Enable support for l10n.getString in tests r=Ola - This creates a mock for fluent-l10n module, so we can use `l10n.getString()` in our code and test for it. - This patch also removes unused files `test/fixtures/l10n.js` and `test/fixtures/PluralForm.js` In order to double check the mock works, these two lines can be added to any test: ``` const { l10n } = require("devtools/client/application/src/modules/l10n"); expect(l10n.getString("foo")).toBe("foo"); ``` Differential Revision: https://phabricator.services.mozilla.com/D43050 --HG-- rename : devtools/client/application/test/components/fixtures/l10n.js => devtools/client/application/test/components/fixtures/fluent-l10n.js extra : moz-landing-system : lando --- .../test/components/fixtures/PluralForm.js | 11 --------- .../test/components/fixtures/fluent-l10n.js | 23 +++++++++++++++++++ .../test/components/fixtures/l10n.js | 23 ------------------- .../test/components/jest.config.js | 3 +-- 4 files changed, 24 insertions(+), 36 deletions(-) delete mode 100644 devtools/client/application/test/components/fixtures/PluralForm.js create mode 100644 devtools/client/application/test/components/fixtures/fluent-l10n.js delete mode 100644 devtools/client/application/test/components/fixtures/l10n.js diff --git a/devtools/client/application/test/components/fixtures/PluralForm.js b/devtools/client/application/test/components/fixtures/PluralForm.js deleted file mode 100644 index d629820a9158..000000000000 --- a/devtools/client/application/test/components/fixtures/PluralForm.js +++ /dev/null @@ -1,11 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at . */ - -"use strict"; - -module.exports.PluralForm = { - get(num, str) { - return str; - }, -}; diff --git a/devtools/client/application/test/components/fixtures/fluent-l10n.js b/devtools/client/application/test/components/fixtures/fluent-l10n.js new file mode 100644 index 000000000000..186ca003422a --- /dev/null +++ b/devtools/client/application/test/components/fixtures/fluent-l10n.js @@ -0,0 +1,23 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Mock for devtools/client/shared/modules/fluent-l10n/fluent-l10n + */ +class FluentL10n { + async init() {} + + getBundles() { + return []; + } + + getString(id, args) { + return args ? `${id}__${JSON.stringify(args)}` : id; + } +} + +// Export the class +exports.FluentL10n = FluentL10n; diff --git a/devtools/client/application/test/components/fixtures/l10n.js b/devtools/client/application/test/components/fixtures/l10n.js deleted file mode 100644 index e071465364a6..000000000000 --- a/devtools/client/application/test/components/fixtures/l10n.js +++ /dev/null @@ -1,23 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at . */ - -"use strict"; - -// @TODO Load the actual strings from instead. -class L10N { - getStr(str) { - switch (str) { - default: - return str; - } - } - - getFormatStr(str) { - return this.getStr(str); - } -} - -module.exports = { - L10N: new L10N(), -}; diff --git a/devtools/client/application/test/components/jest.config.js b/devtools/client/application/test/components/jest.config.js index 7a6ba0a327a5..c2814f249f0c 100644 --- a/devtools/client/application/test/components/jest.config.js +++ b/devtools/client/application/test/components/jest.config.js @@ -9,11 +9,10 @@ module.exports = { verbose: true, moduleNameMapper: { // Custom name mappers for modules that require m-c specific API. - "^../utils/l10n": `${__dirname}/fixtures/l10n`, "^devtools/client/shared/link": `${__dirname}/fixtures/stub`, - "^devtools/shared/plural-form": `${__dirname}/fixtures/plural-form`, "^chrome": `${__dirname}/fixtures/Chrome`, "^Services": `${__dirname}/fixtures/Services`, + "^devtools/client/shared/fluent-l10n/fluent-l10n$": `${__dirname}/fixtures/fluent-l10n`, "^devtools/client/shared/unicode-url": `${__dirname}/fixtures/unicode-url`, // Map all require("devtools/...") to the real devtools root. "^devtools\\/(.*)": `${__dirname}/../../../../$1`,