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.
251 lines
7.6 KiB
251 lines
7.6 KiB
3 years ago
|
// eslint-disable-next-line no-unused-vars
|
||
3 years ago
|
const { Page, Browser } = require("puppeteer");
|
||
3 years ago
|
const { sleep } = require("../src/util");
|
||
3 years ago
|
const axios = require("axios");
|
||
3 years ago
|
|
||
|
/**
|
||
|
* Set back the correct data type for page object
|
||
|
* @type {Page}
|
||
|
*/
|
||
|
page;
|
||
3 years ago
|
|
||
3 years ago
|
/**
|
||
|
* @type {Browser}
|
||
|
*/
|
||
|
browser;
|
||
3 years ago
|
|
||
3 years ago
|
beforeAll(async () => {
|
||
|
await page.setViewport({
|
||
|
width: 1280,
|
||
|
height: 720,
|
||
|
deviceScaleFactor: 1,
|
||
|
});
|
||
3 years ago
|
});
|
||
|
|
||
|
afterAll(() => {
|
||
3 years ago
|
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
const baseURL = "http://127.0.0.1:3002";
|
||
|
|
||
3 years ago
|
describe("Init", () => {
|
||
3 years ago
|
const title = "Uptime Kuma";
|
||
|
|
||
|
beforeAll(async () => {
|
||
3 years ago
|
await page.goto(baseURL);
|
||
3 years ago
|
});
|
||
|
|
||
|
it(`should be titled "${title}"`, async () => {
|
||
3 years ago
|
await expect(page.title()).resolves.toEqual(title);
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
// Setup Page
|
||
3 years ago
|
it("Setup", async () => {
|
||
|
// Create an Admin
|
||
|
await page.waitForSelector("#floatingInput");
|
||
|
await page.waitForSelector("#repeat");
|
||
|
await page.click("#floatingInput");
|
||
|
await page.type("#floatingInput", "admin");
|
||
|
await page.type("#floatingPassword", "admin123");
|
||
|
await page.type("#repeat", "admin123");
|
||
|
await page.click(".btn-primary[type=submit]");
|
||
3 years ago
|
await sleep(3000);
|
||
3 years ago
|
|
||
|
// Go to /setup again
|
||
3 years ago
|
await page.goto(baseURL + "/setup");
|
||
|
await sleep(3000);
|
||
3 years ago
|
let pathname = await page.evaluate(() => location.pathname);
|
||
3 years ago
|
expect(pathname).toEqual("/dashboard");
|
||
|
|
||
|
// Go to /
|
||
3 years ago
|
await page.goto(baseURL);
|
||
3 years ago
|
await sleep(3000);
|
||
|
pathname = await page.evaluate(() => location.pathname);
|
||
3 years ago
|
expect(pathname).toEqual("/dashboard");
|
||
|
});
|
||
|
|
||
3 years ago
|
// Settings Page
|
||
3 years ago
|
describe("Settings", () => {
|
||
|
beforeAll(async () => {
|
||
|
await page.goto(baseURL + "/settings");
|
||
|
});
|
||
3 years ago
|
|
||
3 years ago
|
it("Change Language", async () => {
|
||
3 years ago
|
await page.waitForSelector("#language");
|
||
|
|
||
3 years ago
|
await page.select("#language", "zh-HK");
|
||
|
let languageTitle = await page.evaluate(() => document.querySelector("[for=language]").innerText);
|
||
3 years ago
|
expect(languageTitle).toEqual("語言");
|
||
3 years ago
|
|
||
3 years ago
|
await page.select("#language", "en");
|
||
|
languageTitle = await page.evaluate(() => document.querySelector("[for=language]").innerText);
|
||
3 years ago
|
expect(languageTitle).toEqual("Language");
|
||
3 years ago
|
});
|
||
|
|
||
|
it("Change Theme", async () => {
|
||
3 years ago
|
await sleep(1000);
|
||
|
|
||
|
// Dark
|
||
|
await click(page, ".btn[for=btncheck2]");
|
||
|
await page.waitForSelector("div.dark");
|
||
|
|
||
|
await sleep(1000);
|
||
|
|
||
3 years ago
|
// Light
|
||
3 years ago
|
await click(page, ".btn[for=btncheck1]");
|
||
3 years ago
|
await page.waitForSelector("div.light");
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
// TODO: Heartbeat Bar Style
|
||
|
|
||
|
// TODO: Timezone
|
||
|
|
||
|
it("Search Engine Visibility", async () => {
|
||
|
// Default
|
||
|
let res = await axios.get(baseURL + "/robots.txt");
|
||
3 years ago
|
expect(res.data).toContain("Disallow: /");
|
||
3 years ago
|
|
||
|
// Yes
|
||
|
await click(page, "#searchEngineIndexYes");
|
||
|
await click(page, "form > div > .btn[type=submit]");
|
||
|
await sleep(2000);
|
||
|
res = await axios.get(baseURL + "/robots.txt");
|
||
3 years ago
|
expect(res.data).not.toContain("Disallow: /");
|
||
3 years ago
|
|
||
|
// No
|
||
|
await click(page, "#searchEngineIndexNo");
|
||
|
await click(page, "form > div > .btn[type=submit]");
|
||
|
await sleep(2000);
|
||
|
res = await axios.get(baseURL + "/robots.txt");
|
||
3 years ago
|
expect(res.data).toContain("Disallow: /");
|
||
3 years ago
|
});
|
||
|
|
||
|
it("Entry Page", async () => {
|
||
|
const newPage = await browser.newPage();
|
||
|
|
||
|
// Default
|
||
|
await newPage.goto(baseURL);
|
||
|
await sleep(3000);
|
||
|
let pathname = await newPage.evaluate(() => location.pathname);
|
||
|
expect(pathname).toEqual("/dashboard");
|
||
|
|
||
|
// Status Page
|
||
|
await click(page, "#entryPageNo");
|
||
|
await click(page, "form > div > .btn[type=submit]");
|
||
3 years ago
|
await sleep(4000);
|
||
3 years ago
|
await newPage.goto(baseURL);
|
||
3 years ago
|
await sleep(4000);
|
||
3 years ago
|
pathname = await newPage.evaluate(() => location.pathname);
|
||
|
expect(pathname).toEqual("/status");
|
||
|
|
||
|
// Back to Dashboard
|
||
|
await click(page, "#entryPageYes");
|
||
|
await click(page, "form > div > .btn[type=submit]");
|
||
3 years ago
|
await sleep(4000);
|
||
3 years ago
|
await newPage.goto(baseURL);
|
||
3 years ago
|
await sleep(4000);
|
||
3 years ago
|
pathname = await newPage.evaluate(() => location.pathname);
|
||
|
expect(pathname).toEqual("/dashboard");
|
||
|
|
||
|
await newPage.close();
|
||
|
});
|
||
|
|
||
|
it("Change Password (wrong current password)", async () => {
|
||
3 years ago
|
await page.goto(baseURL + "/settings");
|
||
|
await page.waitForSelector("#current-password");
|
||
|
|
||
3 years ago
|
await page.type("#current-password", "wrong_passw$$d");
|
||
|
await page.type("#new-password", "new_password123");
|
||
|
await page.type("#repeat-new-password", "new_password123");
|
||
3 years ago
|
|
||
|
// Save
|
||
3 years ago
|
await click(page, "form > div > .btn[type=submit]", 1);
|
||
3 years ago
|
await sleep(4000);
|
||
|
|
||
3 years ago
|
await click(page, ".btn-danger.btn.me-2");
|
||
3 years ago
|
await login("admin", "new_password123");
|
||
|
let elementCount = await page.evaluate(() => document.querySelectorAll("#floatingPassword").length);
|
||
|
expect(elementCount).toEqual(1);
|
||
|
|
||
|
await login("admin", "admin123");
|
||
|
});
|
||
|
|
||
|
it("Change Password (wrong repeat)", async () => {
|
||
3 years ago
|
await page.goto(baseURL + "/settings");
|
||
|
await page.waitForSelector("#current-password");
|
||
|
|
||
3 years ago
|
await page.type("#current-password", "admin123");
|
||
|
await page.type("#new-password", "new_password123");
|
||
|
await page.type("#repeat-new-password", "new_password1234567898797898");
|
||
3 years ago
|
|
||
3 years ago
|
await click(page, "form > div > .btn[type=submit]", 1);
|
||
3 years ago
|
await sleep(4000);
|
||
|
|
||
3 years ago
|
await click(page, ".btn-danger.btn.me-2");
|
||
3 years ago
|
await login("admin", "new_password123");
|
||
3 years ago
|
|
||
3 years ago
|
let elementCount = await page.evaluate(() => document.querySelectorAll("#floatingPassword").length);
|
||
|
expect(elementCount).toEqual(1);
|
||
|
|
||
|
await login("admin", "admin123");
|
||
|
await sleep(3000);
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
|
// TODO: 2FA
|
||
|
|
||
|
// TODO: Export Backup
|
||
|
|
||
|
// TODO: Import Backup
|
||
|
|
||
|
// TODO: Disable Auth
|
||
|
|
||
|
// TODO: Clear Stats
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
/*
|
||
|
* TODO
|
||
|
* Create Monitor - All type
|
||
|
* Edit Monitor
|
||
|
* Delete Monitor
|
||
|
*
|
||
|
* Create Notification (token problem, maybe hard to test)
|
||
|
*
|
||
|
*/
|
||
|
|
||
3 years ago
|
describe("Status Page", () => {
|
||
|
const title = "Uptime Kuma";
|
||
|
beforeAll(async () => {
|
||
|
await page.goto(baseURL + "/status");
|
||
|
});
|
||
|
it(`should be titled "${title}"`, async () => {
|
||
3 years ago
|
await expect(page.title()).resolves.toEqual(title);
|
||
3 years ago
|
});
|
||
3 years ago
|
});
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
async function login(username, password) {
|
||
|
await input(page, "#floatingInput", username);
|
||
|
await input(page, "#floatingPassword", password);
|
||
|
await page.click(".btn-primary[type=submit]");
|
||
3 years ago
|
await sleep(5000);
|
||
3 years ago
|
}
|
||
|
|
||
|
async function click(page, selector, elementIndex = 0) {
|
||
3 years ago
|
await page.waitForSelector(selector, {
|
||
|
timeout: 5000,
|
||
|
});
|
||
3 years ago
|
return await page.evaluate((s, i) => {
|
||
|
return document.querySelectorAll(s)[i].click();
|
||
|
}, selector, elementIndex);
|
||
|
}
|
||
|
|
||
|
async function input(page, selector, text) {
|
||
3 years ago
|
await page.waitForSelector(selector, {
|
||
|
timeout: 5000,
|
||
|
});
|
||
3 years ago
|
const element = await page.$(selector);
|
||
|
await element.click({ clickCount: 3 });
|
||
|
await page.keyboard.press("Backspace");
|
||
|
await page.type(selector, text);
|
||
|
}
|