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
This commit is contained in:
Belén Albeza 2019-08-23 09:53:19 +00:00
Родитель f3fc7c8a7b
Коммит bb1e089f66
4 изменённых файлов: 24 добавлений и 36 удалений

Просмотреть файл

@ -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 <http://mozilla.org/MPL/2.0/>. */
"use strict";
module.exports.PluralForm = {
get(num, str) {
return str;
},
};

Просмотреть файл

@ -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;

Просмотреть файл

@ -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 <http://mozilla.org/MPL/2.0/>. */
"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(),
};

Просмотреть файл

@ -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`,