element-web/__mocks__/browser-request.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-17 11:24:37 +00:00
const en = require("../src/i18n/strings/en_EN");
const de = require("../src/i18n/strings/de_DE");
const lv = {
"Save": "Saglabāt",
};
2019-12-17 11:24:37 +00:00
// Mock the browser-request for the languageHandler tests to return
// Fake languages.json containing references to en_EN, de_DE and lv
// en_EN.json
// de_DE.json
// lv.json - mock version with few translations, used to test fallback translation
2019-12-17 11:24:37 +00:00
module.exports = jest.fn((opts, cb) => {
2020-01-16 14:01:15 +00:00
const url = opts.url || opts.uri;
if (url && url.endsWith("languages.json")) {
2019-12-17 11:24:37 +00:00
cb(undefined, {status: 200}, JSON.stringify({
"en": {
"fileName": "en_EN.json",
"label": "English",
},
"de": {
"fileName": "de_DE.json",
"label": "German",
},
"lv": {
"fileName": "lv.json",
"label": "Latvian"
}
2019-12-17 11:24:37 +00:00
}));
2020-01-16 14:01:15 +00:00
} else if (url && url.endsWith("en_EN.json")) {
2019-12-17 11:24:37 +00:00
cb(undefined, {status: 200}, JSON.stringify(en));
} else if (url && url.endsWith("de_DE.json")) {
cb(undefined, {status: 200}, JSON.stringify(de));
} else if (url && url.endsWith("lv.json")) {
cb(undefined, {status: 200}, JSON.stringify(lv));
2019-12-17 11:24:37 +00:00
} else {
cb(true, {status: 404}, "");
2019-12-17 11:24:37 +00:00
}
});