Commit bb1e089f authored by Belén Albeza's avatar Belén Albeza
Browse files

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
parent f3fc7c8a
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
/* 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";

module.exports.PluralForm = {
  get(num, str) {
    return str;
  },
};
+23 −0
Original line number Diff line number Diff line
/* 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/>. */
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

// @TODO Load the actual strings from instead.
class L10N {
  getStr(str) {
    switch (str) {
      default:
        return str;
    }
/**
 * Mock for devtools/client/shared/modules/fluent-l10n/fluent-l10n
 */
class FluentL10n {
  async init() {}

  getBundles() {
    return [];
  }

  getFormatStr(str) {
    return this.getStr(str);
  getString(id, args) {
    return args ? `${id}__${JSON.stringify(args)}` : id;
  }
}

module.exports = {
  L10N: new L10N(),
};
// Export the class
exports.FluentL10n = FluentL10n;
+1 −2
Original line number Diff line number Diff line
@@ -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`,