uptime-kuma/test/cypress/unit/i18n.spec.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-01-10 02:18:45 -05:00
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
2023-01-10 02:18:45 -05:00
});
}
setLanguages(['en-EN']);
2023-01-10 02:18:45 -05:00
expect(currentLocale()).equal("en");
setLanguages(['zh-HK']);
2023-01-10 02:18:45 -05:00
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']);
2023-01-10 02:18:45 -05:00
expect(currentLocale()).equal("en");
setLanguages(['en-US']);
2023-01-10 02:18:45 -05:00
expect(currentLocale()).equal("en");
setLanguages(['ja-ZZ']);
2023-01-10 02:18:45 -05:00
expect(currentLocale()).equal("ja");
setLanguages(['zz-ZZ']);
2023-01-10 02:18:45 -05:00
expect(currentLocale()).equal("en");
setLanguages(['zz-ZZ']);
2023-01-10 02:18:45 -05:00
expect(currentLocale()).equal("en");
setLanguages(['en-US', 'en', 'pl', 'ja']);
2023-01-10 02:18:45 -05:00
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");
2023-01-10 02:18:45 -05:00
});
});