web: update login tests

This commit is contained in:
Abdullah Atta
2022-12-16 12:03:44 +05:00
committed by Abdullah Atta
parent 04fe4a7217
commit e43ee80fdb
4 changed files with 525 additions and 363 deletions

View File

@@ -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"))

View File

@@ -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
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -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",