summaryrefslogtreecommitdiffstats
path: root/test/e2e/util-test.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-11-26 09:28:28 +0100
committerDaniel Baumann <daniel@debian.org>2024-11-26 12:25:58 +0100
commita1882b67c41fe9901a0cd8059b5cc78a5beadec0 (patch)
tree2a24507c67aa99a15416707b2f7e645142230ed8 /test/e2e/util-test.js
parentInitial commit. (diff)
downloaduptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.tar.xz
uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.zip
Adding upstream version 2.0.0~beta.0+dfsg.upstream/2.0.0_beta.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'test/e2e/util-test.js')
-rw-r--r--test/e2e/util-test.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/e2e/util-test.js b/test/e2e/util-test.js
new file mode 100644
index 0000000..f6af3cb
--- /dev/null
+++ b/test/e2e/util-test.js
@@ -0,0 +1,62 @@
+const fs = require("fs");
+const path = require("path");
+const serverUrl = require("../../config/playwright.config.js").url;
+
+const dbPath = "./../../data/playwright-test/kuma.db";
+
+/**
+ * @param {TestInfo} testInfo Test info
+ * @param {Page} page Page
+ * @returns {Promise<void>}
+ */
+export async function screenshot(testInfo, page) {
+ const screenshot = await page.screenshot();
+ await testInfo.attach("screenshot", {
+ body: screenshot,
+ contentType: "image/png"
+ });
+}
+
+/**
+ * @param {Page} page Page
+ * @returns {Promise<void>}
+ */
+export async function login(page) {
+ // Login
+ await page.getByPlaceholder("Username").click();
+ await page.getByPlaceholder("Username").fill("admin");
+ await page.getByPlaceholder("Username").press("Tab");
+ await page.getByPlaceholder("Password").fill("admin123");
+ await page.getByLabel("Remember me").check();
+ await page.getByRole("button", { name: "Log in" }).click();
+ await page.isVisible("text=Add New Monitor");
+}
+
+/**
+ * Determines if the SQLite database has been created. This indicates setup has completed.
+ * @returns {boolean} True if exists
+ */
+export function getSqliteDatabaseExists() {
+ return fs.existsSync(path.resolve(__dirname, dbPath));
+}
+
+/**
+ * Makes a request to the server to take a snapshot of the SQLite database.
+ * @param {Page|null} page Page
+ * @returns {Promise<Response>} Promise of response from snapshot request.
+ */
+export async function takeSqliteSnapshot(page = null) {
+ if (page) {
+ return page.goto("./_e2e/take-sqlite-snapshot");
+ } else {
+ return fetch(`${serverUrl}/_e2e/take-sqlite-snapshot`);
+ }
+}
+
+/**
+ * Makes a request to the server to restore the snapshot of the SQLite database.
+ * @returns {Promise<Response>} Promise of response from restoration request.
+ */
+export async function restoreSqliteSnapshot() {
+ return fetch(`${serverUrl}/_e2e/restore-sqlite-snapshot`);
+}