mirror of
https://github.com/gosticks/web.git
synced 2026-10-07 07:07:07 +00:00
Add i18n test
Now the util folder has 100% coverage. Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/* Pi-hole: A black hole for Internet advertisements
|
||||
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
* Network-wide ad blocking via your own hardware.
|
||||
*
|
||||
* Web Interface
|
||||
* Test internationalization setup
|
||||
*
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
import { setupI18n } from "../i18n";
|
||||
|
||||
// Mock react-i18next, as it does not properly export the i18next module during
|
||||
// testing.
|
||||
// https://github.com/i18next/react-i18next/issues/434
|
||||
jest.mock("react-i18next", () => ({
|
||||
reactI18nextModule: {
|
||||
type: "3rdParty",
|
||||
init: () => {}
|
||||
}
|
||||
}));
|
||||
|
||||
it("configures i18n successfully", async () => {
|
||||
// Provide a mock ajax function to the XHR backend
|
||||
const fakeAjax = (url: any, options: any, callback: any) => callback("", {});
|
||||
|
||||
// Make sure i18n initializes without error
|
||||
await setupI18n(fakeAjax);
|
||||
});
|
||||
+9
-3
@@ -15,8 +15,13 @@ import { reactI18nextModule } from "react-i18next";
|
||||
import config from "../config";
|
||||
import languages from "../languages.json";
|
||||
|
||||
export function setupI18n() {
|
||||
i18n
|
||||
/**
|
||||
* Set up the internationalization service
|
||||
*
|
||||
* @param ajax An optional ajax function to use when fetching translations
|
||||
*/
|
||||
export function setupI18n(ajax?: any) {
|
||||
return i18n
|
||||
.use(XHR)
|
||||
.use(LanguageDetector)
|
||||
.use(reactI18nextModule)
|
||||
@@ -46,7 +51,8 @@ export function setupI18n() {
|
||||
escapeValue: false
|
||||
},
|
||||
backend: {
|
||||
loadPath: process.env.PUBLIC_URL + "/i18n/{{lng}}/{{ns}}.json"
|
||||
loadPath: process.env.PUBLIC_URL + "/i18n/{{lng}}/{{ns}}.json",
|
||||
ajax
|
||||
},
|
||||
react: {
|
||||
// Wait until translations are loaded before rendering
|
||||
|
||||
Reference in New Issue
Block a user