Merge pull request #2581 from twiggotronix/add-frontend-unit-tests
Add frontend unit testspull/2540/head
commit
cc4ed308b0
@ -0,0 +1,10 @@
|
||||
const { defineConfig } = require("cypress");
|
||||
|
||||
module.exports = defineConfig({
|
||||
e2e: {
|
||||
supportFile: false,
|
||||
specPattern: [
|
||||
"test/cypress/unit/**/*.js"
|
||||
],
|
||||
}
|
||||
});
|
@ -0,0 +1,44 @@
|
||||
import { currentLocale } from "../../../src/i18n";
|
||||
|
||||
describe("Test i18n.js", () => {
|
||||
|
||||
it("currentLocale()", () => {
|
||||
const setLanguage = (language) => {
|
||||
Object.defineProperty(window.navigator, 'language', {
|
||||
value: language,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
setLanguage('en-EN');
|
||||
|
||||
expect(currentLocale()).equal("en");
|
||||
|
||||
setLanguage('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
|
||||
setLanguage('zh-hk');
|
||||
expect(currentLocale()).equal("en");
|
||||
|
||||
setLanguage('en-US');
|
||||
expect(currentLocale()).equal("en");
|
||||
|
||||
setLanguage('ja-ZZ');
|
||||
expect(currentLocale()).equal("ja");
|
||||
|
||||
setLanguage('zz-ZZ');
|
||||
expect(currentLocale()).equal("en");
|
||||
|
||||
setLanguage('zz-ZZ');
|
||||
expect(currentLocale()).equal("en");
|
||||
|
||||
setLanguage('en');
|
||||
localStorage.locale = "en";
|
||||
expect(currentLocale()).equal("en");
|
||||
|
||||
localStorage.locale = "zh-HK";
|
||||
expect(currentLocale()).equal("zh-HK");
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in new issue