mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-08 06:29:57 +08:00
[test] add test for i18n currentLocale
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
const { Page, Browser } = require("puppeteer");
|
||||
const { sleep } = require("../src/util");
|
||||
const axios = require("axios");
|
||||
const { currentLocale } = require("../src/i18n");
|
||||
|
||||
/**
|
||||
* Set back the correct data type for page object
|
||||
@@ -37,7 +36,7 @@ describe("Init", () => {
|
||||
});
|
||||
|
||||
it(`should be titled "${title}"`, async () => {
|
||||
await expect(page.title()).resolves.toMatch(title);
|
||||
await expect(page.title()).resolves.toEqual(title);
|
||||
});
|
||||
|
||||
// Setup Page
|
||||
@@ -76,11 +75,11 @@ describe("Init", () => {
|
||||
|
||||
await page.select("#language", "zh-HK");
|
||||
let languageTitle = await page.evaluate(() => document.querySelector("[for=language]").innerText);
|
||||
expect(languageTitle).toMatch("語言");
|
||||
expect(languageTitle).toEqual("語言");
|
||||
|
||||
await page.select("#language", "en");
|
||||
languageTitle = await page.evaluate(() => document.querySelector("[for=language]").innerText);
|
||||
expect(languageTitle).toMatch("Language");
|
||||
expect(languageTitle).toEqual("Language");
|
||||
});
|
||||
|
||||
it("Change Theme", async () => {
|
||||
@@ -104,21 +103,21 @@ describe("Init", () => {
|
||||
it("Search Engine Visibility", async () => {
|
||||
// Default
|
||||
let res = await axios.get(baseURL + "/robots.txt");
|
||||
expect(res.data).toMatch("Disallow: /");
|
||||
expect(res.data).toContain("Disallow: /");
|
||||
|
||||
// Yes
|
||||
await click(page, "#searchEngineIndexYes");
|
||||
await click(page, "form > div > .btn[type=submit]");
|
||||
await sleep(2000);
|
||||
res = await axios.get(baseURL + "/robots.txt");
|
||||
expect(res.data).not.toMatch("Disallow: /");
|
||||
expect(res.data).not.toContain("Disallow: /");
|
||||
|
||||
// No
|
||||
await click(page, "#searchEngineIndexNo");
|
||||
await click(page, "form > div > .btn[type=submit]");
|
||||
await sleep(2000);
|
||||
res = await axios.get(baseURL + "/robots.txt");
|
||||
expect(res.data).toMatch("Disallow: /");
|
||||
expect(res.data).toContain("Disallow: /");
|
||||
});
|
||||
|
||||
it("Entry Page", async () => {
|
||||
@@ -219,19 +218,11 @@ describe("Init", () => {
|
||||
await page.goto(baseURL + "/status");
|
||||
});
|
||||
it(`should be titled "${title}"`, async () => {
|
||||
await expect(page.title()).resolves.toMatch(title);
|
||||
await expect(page.title()).resolves.toEqual(title);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Test i18n.js", () => {
|
||||
|
||||
it("currentLocale()", () => {
|
||||
expect(currentLocale()).toMatch("");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
async function login(username, password) {
|
||||
await input(page, "#floatingInput", username);
|
||||
await input(page, "#floatingPassword", password);
|
42
test/frontend.spec.js
Normal file
42
test/frontend.spec.js
Normal file
@@ -0,0 +1,42 @@
|
||||
// eslint-disable-next-line no-global-assign
|
||||
global.localStorage = {};
|
||||
global.navigator = {
|
||||
language: "en"
|
||||
};
|
||||
|
||||
const { currentLocale } = require("../src/i18n");
|
||||
|
||||
describe("Test i18n.js", () => {
|
||||
|
||||
it("currentLocale()", () => {
|
||||
expect(currentLocale()).toEqual("en");
|
||||
|
||||
navigator.language = "zh-HK";
|
||||
expect(currentLocale()).toEqual("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
|
||||
navigator.language = "zh-hk";
|
||||
expect(currentLocale()).toEqual("en");
|
||||
|
||||
navigator.language = "en-US";
|
||||
expect(currentLocale()).toEqual("en");
|
||||
|
||||
navigator.language = "ja-ZZ";
|
||||
expect(currentLocale()).toEqual("ja");
|
||||
|
||||
navigator.language = "zz";
|
||||
expect(currentLocale()).toEqual("en");
|
||||
|
||||
navigator.language = "zz-ZZ";
|
||||
expect(currentLocale()).toEqual("en");
|
||||
|
||||
localStorage.locale = "en";
|
||||
expect(currentLocale()).toEqual("en");
|
||||
|
||||
localStorage.locale = "zh-HK";
|
||||
expect(currentLocale()).toEqual("zh-HK");
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user