mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
web: update login tests
This commit is contained in:
committed by
Abdullah Atta
parent
04fe4a7217
commit
e43ee80fdb
@@ -19,23 +19,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { Locator, Page } from "@playwright/test";
|
||||
import { getTestId } from "../utils";
|
||||
import { authenticator } from "otplib";
|
||||
|
||||
type User = {
|
||||
email: string;
|
||||
password: string;
|
||||
key?: string;
|
||||
totpSecret: string;
|
||||
};
|
||||
|
||||
export class AuthModel {
|
||||
private readonly page: Page;
|
||||
private readonly emailInput: Locator;
|
||||
private readonly passwordInput: Locator;
|
||||
private readonly codeInput: Locator;
|
||||
private readonly submitButton: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.emailInput = page.locator(getTestId("email"));
|
||||
this.passwordInput = page.locator(getTestId("password"));
|
||||
this.codeInput = page.locator(getTestId("code"));
|
||||
this.submitButton = page.locator(getTestId("submitButton"));
|
||||
}
|
||||
|
||||
@@ -52,10 +56,21 @@ export class AuthModel {
|
||||
async login(user: Partial<User>) {
|
||||
if (!user.email && !user.password) return;
|
||||
|
||||
if (user.email) await this.emailInput.fill(user.email);
|
||||
if (user.password) await this.passwordInput.fill(user.password);
|
||||
if (user.email) {
|
||||
await this.emailInput.fill(user.email);
|
||||
await this.submitButton.click();
|
||||
}
|
||||
|
||||
await this.submitButton.click();
|
||||
if (user.totpSecret) {
|
||||
const token = authenticator.generate(user.totpSecret);
|
||||
await this.codeInput.fill(token);
|
||||
|
||||
await this.submitButton.click();
|
||||
}
|
||||
|
||||
if (user.password) {
|
||||
await this.passwordInput.fill(user.password);
|
||||
}
|
||||
|
||||
await this.page
|
||||
.locator(getTestId("sync-status-syncing"))
|
||||
|
||||
@@ -34,12 +34,14 @@ const USER = {
|
||||
NEW: {
|
||||
email: process.env.USER_EMAIL,
|
||||
password: process.env.NEW_USER_PASSWORD,
|
||||
key: process.env.NEW_USER_KEY
|
||||
key: process.env.NEW_USER_KEY,
|
||||
totpSecret: process.env.USER_TOTP_SECRET
|
||||
},
|
||||
CURRENT: {
|
||||
email: process.env.USER_EMAIL,
|
||||
password: process.env.CURRENT_USER_PASSWORD,
|
||||
key: process.env.CURRENT_USER_KEY
|
||||
key: process.env.CURRENT_USER_KEY,
|
||||
totpSecret: process.env.USER_TOTP_SECRET
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
858
apps/web/package-lock.json
generated
858
apps/web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,12 +20,12 @@
|
||||
"@notesnook/core": "*",
|
||||
"@notesnook/crypto": "*",
|
||||
"@notesnook/crypto-worker": "*",
|
||||
"@notesnook/web-clipper": "*",
|
||||
"@notesnook/desktop": "file:desktop",
|
||||
"@notesnook/editor": "*",
|
||||
"@notesnook/logger": "*",
|
||||
"@notesnook/streamable-fs": "*",
|
||||
"@notesnook/theme": "*",
|
||||
"@notesnook/web-clipper": "*",
|
||||
"@tanstack/react-virtual": "^3.0.0-beta.18",
|
||||
"@theme-ui/components": "^0.14.7",
|
||||
"@theme-ui/core": "^0.14.7",
|
||||
@@ -86,6 +86,7 @@
|
||||
"find-process": "^1.4.4",
|
||||
"ip": "^1.1.8",
|
||||
"lorem-ipsum": "^2.0.4",
|
||||
"otplib": "^12.0.1",
|
||||
"patch-package": "^6.4.7",
|
||||
"progress-bar-webpack-plugin": "^2.1.0",
|
||||
"react": "17.0.2",
|
||||
|
||||
Reference in New Issue
Block a user