Files
notesnook/apps/web/__e2e__/models/settings-view.model.ts

154 lines
4.6 KiB
TypeScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
2023-01-16 13:44:52 +05:00
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2023-06-16 19:10:02 +05:00
import { Page } from "@playwright/test";
import { downloadAndReadFile, getTestId, uploadFile } from "../utils";
2023-08-07 05:47:23 +05:00
import {
confirmDialog,
fillPasswordDialog,
waitForDialog,
waitToHaveText
} from "./utils";
2023-06-16 19:10:02 +05:00
import { NavigationMenuModel } from "./navigation-menu.model";
export class SettingsViewModel {
private readonly page: Page;
2023-06-16 19:10:02 +05:00
private readonly navigation: NavigationMenuModel;
constructor(page: Page) {
this.page = page;
2023-06-16 19:10:02 +05:00
this.navigation = new NavigationMenuModel(page, "settings-navigation-menu");
}
async close() {
await this.page.locator(getTestId("settings-search")).focus();
await this.page.waitForTimeout(100);
await this.page.keyboard.press("Escape");
await this.page.waitForTimeout(1000);
}
async logout() {
2023-06-16 19:10:02 +05:00
const item = await this.navigation.findItem("Profile");
await item?.click();
const logoutButton = this.page
.locator(getTestId("setting-logout"))
.locator("button");
await logoutButton.click();
2023-11-24 15:04:10 +05:00
await confirmDialog(this.page.locator(getTestId("confirm-dialog")));
2023-06-16 19:10:02 +05:00
await this.page
.locator(getTestId("not-logged-in"))
.waitFor({ state: "visible" });
}
async getRecoveryKey(password: string) {
2023-06-16 19:10:02 +05:00
const item = await this.navigation.findItem("Profile");
await item?.click();
const backupRecoveryKeyButton = this.page
.locator(getTestId("setting-recovery-key"))
.locator("button");
await backupRecoveryKeyButton.click();
await fillPasswordDialog(this.page, password);
await waitToHaveText(this.page, "recovery-key");
const key = await this.page
.locator(getTestId("recovery-key"))
.textContent();
2023-11-24 15:04:10 +05:00
const dialog = this.page.locator(getTestId("recovery-key-dialog"));
await confirmDialog(dialog);
return key;
}
async isLoggedIn() {
2024-11-08 12:03:55 +05:00
const item = await this.navigation.findItem("Subscription details");
2023-06-16 19:10:02 +05:00
return !!(await item?.getTitle());
}
2023-09-05 17:47:28 +05:00
async isBackupEncryptionEnabled(state: boolean) {
const encyptBackups = this.page
.locator(getTestId("setting-encrypt-backups"))
.locator(
state ? `input[data-checked="true"]` : `input[data-checked="false"]`
);
await encyptBackups.waitFor({ state: "visible" });
return (await encyptBackups.getAttribute("data-checked")) === "true";
}
async toggleBackupEncryption(password?: string) {
2023-06-16 19:10:02 +05:00
const item = await this.navigation.findItem("Backup & export");
await item?.click();
2023-09-05 17:47:28 +05:00
const encyptBackups = this.page
.locator(getTestId("setting-encrypt-backups"))
.locator("label");
await encyptBackups.click();
if (password) await fillPasswordDialog(this.page, password);
}
async createBackup(password?: string) {
const item = await this.navigation.findItem("Backup & export");
await item?.click();
2023-06-16 19:10:02 +05:00
2024-07-27 09:26:18 +05:00
return await downloadAndReadFile(
this.page,
async () => {
const backupData = this.page
.locator(getTestId("setting-create-backup"))
.locator("select");
await backupData.selectOption({ value: "partial", label: "Backup" });
if (password) await fillPasswordDialog(this.page, password);
},
"utf-8"
);
}
2023-01-04 12:42:52 +05:00
async restoreData(filename: string, password?: string) {
2023-06-16 19:10:02 +05:00
const item = await this.navigation.findItem("Backup & export");
await item?.click();
const restoreBackup = this.page
.locator(getTestId("setting-restore-backup"))
.locator("button");
await uploadFile(this.page, restoreBackup, filename);
if (password) await fillPasswordDialog(this.page, password);
2023-08-07 05:47:23 +05:00
await waitForDialog(this.page, "Restoring backup");
}
async selectImageCompression(option: { value: string; label: string }) {
const item = await this.navigation.findItem("Behaviour");
await item?.click();
const imageCompressionDropdown = this.page
.locator(getTestId("setting-image-compression"))
.locator("select");
await imageCompressionDropdown.selectOption(option);
}
}