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

117 lines
3.5 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";
import { confirmDialog, fillPasswordDialog, 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();
await confirmDialog(this.page);
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();
await confirmDialog(this.page);
return key;
}
async isLoggedIn() {
2023-06-16 19:10:02 +05:00
const item = await this.navigation.findItem("Subscription");
return !!(await item?.getTitle());
}
async createBackup(password?: string) {
2023-06-16 19:10:02 +05:00
const item = await this.navigation.findItem("Backup & export");
await item?.click();
if (password) {
const encyptBackups = this.page
.locator(getTestId("setting-encrypt-backups"))
.locator("label");
await encyptBackups.click();
}
const backupData = this.page
.locator(getTestId("setting-create-backup"))
.locator("button");
if (password) {
await backupData.click();
await fillPasswordDialog(this.page, password);
}
return await downloadAndReadFile(this.page, backupData, "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);
}
}