Skip to content

Commit

Permalink
add(test): add more tests for import export accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
luisecm committed Dec 19, 2024
1 parent 7146fbe commit 746e4d2
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 33 deletions.
21 changes: 16 additions & 5 deletions playwright/PageObjects/ImportAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ImportAccountPage extends MainPage {

async importAccountFromFile(
phraseType: "file" | "manual",
importFilePath: string,
backUpFile: string,
seedPhrasePath?: string,
seedPhrase?: string[],
) {
Expand All @@ -101,7 +101,7 @@ export class ImportAccountPage extends MainPage {
} else {
throw new Error("Invalid passphrase type");
}
await this.uploadImportedFile(importFilePath);
await this.uploadImportedFile(backUpFile);
}

async importAccountFromRemote(
Expand All @@ -126,20 +126,31 @@ export class ImportAccountPage extends MainPage {
}

async uploadImportedFile(filePath: string) {
await expect(this.buttonImportAccountFromFile).toHaveClass("enabled");
const fileChooserPromise = this.page.waitForEvent("filechooser");
await this.clickOnImportAccountFromFile();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(filePath);
}

async uploadSeedPhraseFile(filePath: string) {
await expect(this.buttonImportAccountFromFile).toHaveClass("disabled");
const fileChooserPromise = this.page.waitForEvent("filechooser");
await this.clickOnUploadPassphrase();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(filePath);
await expect(this.buttonImportAccountFromFile).toHaveClass("enabled");
}

async validateToastInvalidPhrase() {
await this.toastNotificationText.waitFor({ state: "attached" });
await expect(this.toastNotificationText).toHaveText(
"Invalid word in phrase",
);
}

async validateToastUnkwnownError() {
await this.toastNotificationText.waitFor({ state: "attached" });
await expect(this.toastNotificationText).toHaveText(
"An unknown error occurred",
);
}

async validatePageIsLoaded() {
Expand Down
7 changes: 7 additions & 0 deletions playwright/PageObjects/MainPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, type Locator, type Page } from "@playwright/test";
import { readFile } from "fs/promises";
const fs = require("fs");
const path = require("path");
export default class MainPage {
Expand Down Expand Up @@ -288,6 +289,12 @@ export default class MainPage {
});
}

async readRecoveryPhraseFile(filePath: string) {
const fileContent = await readFile(filePath, "utf-8");
const fileSeedPhraseArray = fileContent.split(/\s+/).filter(Boolean);
return fileSeedPhraseArray;
}

async validateNoFavoritesAreVisible() {
await this.clickOnShowSidebarIfClosed();
await this.favoriteCircle.waitFor({ state: "detached" });
Expand Down
9 changes: 1 addition & 8 deletions playwright/PageObjects/SaveRecoverySeed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import MainPage from "./MainPage";
import { expect, type Locator, type Page } from "@playwright/test";
import { readFile } from "fs/promises";
import { type Locator, type Page } from "@playwright/test";

export class SaveRecoverySeedPage extends MainPage {
readonly buttonDownloadPhrase: Locator;
Expand Down Expand Up @@ -58,12 +57,6 @@ export class SaveRecoverySeedPage extends MainPage {
return count;
}

async readRecoveryPhraseFile(filePath: string) {
const fileContent = await readFile(filePath, "utf-8");
const fileSeedPhraseArray = fileContent.split(/\s+/).filter(Boolean);
return fileSeedPhraseArray;
}

async saveRecoverySeed() {
// Wait for the download event
const filename = "seed-phrase.txt";
Expand Down
60 changes: 58 additions & 2 deletions playwright/PageObjects/Settings/SettingsProfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, type Locator, type Page } from "@playwright/test";
import { SettingsBase } from "./SettingsBase";
const fs = require("fs");
const path = require("path");

export class SettingsProfile extends SettingsBase {
readonly accountIntegrations: Locator;
Expand Down Expand Up @@ -37,6 +39,11 @@ export class SettingsProfile extends SettingsBase {
readonly deleteAccountSectionButton: Locator;
readonly deleteAccountSectionLabel: Locator;
readonly deleteAccountSectionText: Locator;
readonly exportAccountSection: Locator;
readonly exportAccountSectionLabel: Locator;
readonly exportAccountSectionText: Locator;
readonly exportAccountSectionFileButton: Locator;
readonly exportAccountSectionRemoteButton: Locator;
readonly identiconSettingsProfile: Locator;
readonly inputSettingsProfileShortID: Locator;
readonly inputSettingsProfileShortIDGroup: Locator;
Expand Down Expand Up @@ -201,6 +208,18 @@ export class SettingsProfile extends SettingsBase {
this.deleteAccountSectionText = this.deleteAccountSection.getByTestId(
"setting-section-text",
);
this.exportAccountSection = this.page.getByTestId("export-account");
this.exportAccountSectionLabel = this.exportAccountSection.getByTestId(
"setting-section-label",
);
this.exportAccountSectionText = this.exportAccountSection.getByTestId(
"setting-section-text",
);
this.exportAccountSectionFileButton = this.exportAccountSection.getByTestId(
"export-account-file",
);
this.exportAccountSectionRemoteButton =
this.exportAccountSection.getByTestId("export-account-remote");
this.identiconSettingsProfile = this.page
.locator(".identicon")
.locator("img");
Expand Down Expand Up @@ -329,12 +348,39 @@ export class SettingsProfile extends SettingsBase {
);
}

// Rewrite everything here in playwright

async copyShortID() {
await this.inputSettingsProfileShortIDGroup.click();
}

async deleteAccount() {
await this.deleteAccountSectionButton.click();
}

async exportAccountToFile() {
const downloadPath = path.join(__dirname, "downloads");
if (!fs.existsSync(downloadPath)) {
fs.mkdirSync(downloadPath);
}

const downloadPromise = this.page.waitForEvent("download");
await this.exportAccountSectionFileButton.click();
const download = await downloadPromise;

const fileName = download.suggestedFilename(); // Get the suggested filename
const filePath = path.join(downloadPath, fileName);
await download.saveAs(filePath); // Save the file to the designated path

// Validate the downloaded file
expect(fs.existsSync(filePath)).toBeTruthy(); // Check file exists
expect([".upk"]).toContain(path.extname(fileName)); // Validate file extension
}

async exportAccountToRemote() {
await this.exportAccountSectionRemoteButton.click();
await this.validateToastSuccessRemoteExport();
await this.waitForToastNotificationToDisappear();
}

async getProfileIdenticonSource() {
const source = await this.identiconSettingsProfile.getAttribute("src");
return source;
Expand Down Expand Up @@ -517,6 +563,16 @@ export class SettingsProfile extends SettingsBase {
await expect(this.toastNotificationText).toHaveText("Profile Updated!");
}

async validateToastSuccessRemoteExport() {
await this.toastNotification.waitFor({ state: "attached" });
const textToast = this.toastNotification.getByText(
"Successfully exported account to remote",
);
await expect(textToast).toHaveText(
"Successfully exported account to remote",
);
}

async uploadProfileBanner(file: string) {
await this.profileBanner.click();
await this.profileBannerInput.setInputFiles(file);
Expand Down
Binary file added playwright/PageObjects/Settings/downloads/export.upk
Binary file not shown.
Binary file added playwright/assets/export.upk
Binary file not shown.
1 change: 1 addition & 0 deletions playwright/assets/seed-phrase.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shoe enough industry soft unit dilemma slight venture mirror man nice motion
Loading

0 comments on commit 746e4d2

Please sign in to comment.