You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
import { currentLocale } from "../../../src/i18n";
|
|
|
|
describe("Test i18n.js", () => {
|
|
|
|
it("currentLocale()", () => {
|
|
const setLanguages = (languages) => {
|
|
Object.defineProperty(navigator, 'language', {
|
|
value: languages[0],
|
|
writable: true
|
|
});
|
|
Object.defineProperty(navigator, 'languages', {
|
|
value: languages,
|
|
writable: true
|
|
});
|
|
}
|
|
|
|
setLanguages(['en-EN']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['zh-HK']);
|
|
expect(currentLocale()).equal("zh-HK");
|
|
|
|
// Note that in Safari on iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
|
|
setLanguages(['zh-hk']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['en-US']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['ja-ZZ']);
|
|
expect(currentLocale()).equal("ja");
|
|
|
|
setLanguages(['zz-ZZ']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['zz-ZZ']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['en-US', 'en', 'pl', 'ja']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['en-US', 'pl', 'ja']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['abc', 'en-US', 'pl', 'ja']);
|
|
expect(currentLocale()).equal("en");
|
|
|
|
setLanguages(['fil-PH', 'pl']);
|
|
expect(currentLocale()).equal("pl");
|
|
|
|
setLanguages(['shi-Latn-MA', 'pl']);
|
|
expect(currentLocale()).equal("pl");
|
|
|
|
setLanguages(['pl']);
|
|
localStorage.locale = "ja-ZZ";
|
|
expect(currentLocale()).equal("ja");
|
|
|
|
setLanguages(['pl']);
|
|
localStorage.locale = "invalid-lang";
|
|
expect(currentLocale()).equal("pl");
|
|
});
|
|
|
|
});
|