Skip to content

Commit

Permalink
Moved the assertions to the modal pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedzitouni committed Aug 21, 2024
1 parent f67cece commit 693f264
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 120 deletions.
2 changes: 2 additions & 0 deletions apps/ledger-live-desktop/tests/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SpeculosPage } from "tests/page/speculos.page";
import { SendModal } from "tests/page/modal/send.modal";
import { Drawer } from "tests/page/drawer/drawer";
import { SettingsPage } from "tests/page/settings.page";
import { LedgerSyncPage } from "tests/page/ledgerSync.page";

export class Application extends PageHolder {
public account = new AccountPage(this.page);
Expand All @@ -23,4 +24,5 @@ export class Application extends PageHolder {
public speculos = new SpeculosPage(this.page);
public send = new SendModal(this.page);
public settings = new SettingsPage(this.page);
public ledgerSync= new LedgerSyncPage(this.page);

Check failure on line 27 in apps/ledger-live-desktop/tests/page/index.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Insert `·`

Check failure on line 27 in apps/ledger-live-desktop/tests/page/index.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Insert `·`
}
102 changes: 102 additions & 0 deletions apps/ledger-live-desktop/tests/page/ledgerSync.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { AppPage } from "tests/page/abstractClasses";
import { step } from "tests/misc/reporters/step";
import { expect } from '@playwright/test';

Check failure on line 3 in apps/ledger-live-desktop/tests/page/ledgerSync.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Replace `'@playwright/test';·` with `"@playwright/test";`

Check failure on line 3 in apps/ledger-live-desktop/tests/page/ledgerSync.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Replace `'@playwright/test';·` with `"@playwright/test";`

export class LedgerSyncPage extends AppPage {
private syncAccountsButton = this.page.getByRole("button", { name: "Sync your accounts" });
private closeLedgerSyncButton = this.page.getByRole("button", { name: "Close" });
private manageInstancesButton = this.page
.getByTestId("walletSync-manage-instances")
.getByText("Manage");
private manageBackupButton = this.page.getByTestId("walletSync-manage-backup");
private deleteBackupButton = this.page.getByTestId("walletSync-manage-backup-delete");
private confirmBackupDeletionButton = this.page.getByRole("button", { name: "Delete" });
private successTextElement = this.page.locator("span", { hasText: "Success" }).first();
private closeLSDrawerButton = this.page.getByTestId("drawer-close-button");
private backupDeletionSuccessText = this.page.getByText(
"Your devices have been unsynchronized and your key has been deleted",
);

async SyncAccounts() {
await this.syncAccountsButton.click();
}

async doesSyncAccountsButtonExist(): Promise<boolean> {
return this.syncAccountsButton.isVisible();
}

async closeLedgerSync() {
await this.closeLedgerSyncButton.click();
}

async openManageInstances() {
await this.manageInstancesButton.click();
}

async manageBackup() {
await this.manageBackupButton.click();
}

async deleteBackup() {
await this.deleteBackupButton.click();
}

async confirmBackupDeletion() {
await this.confirmBackupDeletionButton.click();
}

async destroyTrustchain() {
await this.manageBackup();
await this.deleteBackup();
await this.confirmBackupDeletion();
}

async checkSynchronizationSuccess(): Promise<boolean> {
await this.successTextElement.waitFor({ state: "visible" });
return this.successTextElement.isVisible();
}

async backupDeletionSuccess(): Promise<boolean> {
await this.backupDeletionSuccessText.waitFor({ state: "visible" });
return this.backupDeletionSuccessText.isVisible();
}

async countSyncedInstances(): Promise<number> {
const countInstancesText = await this.page.getByText("Synchronized instance").textContent();
const instanceCount = extractNumberFromText(countInstancesText || "");
return instanceCount;
}

async closeLSManagerDrawer() {
await this.closeLSDrawerButton.nth(0).click();
}

@step("Check if sync entry point exists")
async expectSyncAccountsButtonExist() {
const isSyncButtonVisible = await this.doesSyncAccountsButtonExist();
expect(isSyncButtonVisible).toBe(true);
}

@step("Perform synchronization and validate success")
async expectSynchronizationSuccess() {
const success = await this.checkSynchronizationSuccess();
expect(success).toBe(true);
}

@step("Validate number of synchronized instances")
async expectNbSyncedInstances(nb: number) {
const nbInstances = await this.countSyncedInstances();
expect(nbInstances).toBe(nb);
}

@step("Trustchain destroyed")
async expectBackupDeletion() {
const deletionsuccess = await this.backupDeletionSuccess();
expect(deletionsuccess).toBe(true);
}
}

async function extractNumberFromText(text: string): Promise<number> {
const match = text.match(/\d+/);
return match ? parseInt(match[0], 10) : 0;
}
70 changes: 0 additions & 70 deletions apps/ledger-live-desktop/tests/page/settings.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,13 @@ export class SettingsPage extends AppPage {
private settingsTab=this.page.getByTestId('topbar-settings-button');

Check failure on line 5 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Replace `=this.page.getByTestId('topbar-settings-button'` with `·=·this.page.getByTestId("topbar-settings-button"`

Check failure on line 5 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Replace `=this.page.getByTestId('topbar-settings-button'` with `·=·this.page.getByTestId("topbar-settings-button"`
private generalSettingsTab = this.page.getByTestId("settings-display-tab");
private manageLedgerSyncButton = this.page.getByRole('button', { name: 'Manage' });

Check failure on line 7 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Replace `'button',·{·name:·'Manage'` with `"button",·{·name:·"Manage"`

Check failure on line 7 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Replace `'button',·{·name:·'Manage'` with `"button",·{·name:·"Manage"`
private syncAccountsButton=this.page.getByRole('button', { name: 'Sync your accounts' });
private accountsTab = this.page.getByTestId("settings-accounts-tab");
private aboutTab = this.page.getByTestId("settings-about-tab");
private helpTab = this.page.getByTestId("settings-help-tab");
readonly experimentalTab = this.page.getByTestId("settings-experimental-tab");
private developerTab = this.page.getByTestId("settings-developer-tab");
private experimentalDevModeToggle = this.page.getByTestId("MANAGER_DEV_MODE-button");
private closeLedgerSyncButton= this.page.getByRole('button',{name:'Close'});
private manageInstancesButton=this.page.getByTestId('walletSync-manage-instances').getByText('Manage');
private manageBackupButton = this.page.getByTestId('walletSync-manage-backup');
private deleteBackupButton = this.page.getByTestId('walletSync-manage-backup-delete');
private confirmBackupDeletionButton = this.page.getByRole('button', { name: 'Delete' });
private successTextElement = this.page.locator('span', { hasText: 'Success' }).first();
private closeLSDrawerButton = this.page.getByTestId('drawer-close-button');
private backupDeletionSuccessText = this.page.getByText('Your devices have been unsynchronized and your key has been deleted');

Check failure on line 14 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Delete `······`

Check failure on line 14 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Delete `······`


readonly counterValueSelector = this.page.locator(
"[data-testid='setting-countervalue-dropDown'] .select__value-container",
);
Expand Down Expand Up @@ -111,64 +100,5 @@ export class SettingsPage extends AppPage {
await this.settingsTab.click();
}

async SyncAccounts() {
await this.syncAccountsButton.click();
}

async doesSyncAccountsButtonExist(): Promise<boolean> {
return this.syncAccountsButton.isVisible();
}

async closeLedgerSync() {
await this.closeLedgerSyncButton.click();
}

async openManageInstances() {
await this.manageInstancesButton.click();
}

async manageBackup() {
await this.manageBackupButton.click();
}

async deleteBackup(){
await this.deleteBackupButton.click();
}

async confirmBackupDeletion(){
await this.confirmBackupDeletionButton.click();
}

async destroyTrustchain(){
await this.manageBackup();
await this.deleteBackup();
await this.confirmBackupDeletion();
}

async checkSynchronizationSuccess(): Promise<boolean> {
await this.successTextElement.waitFor({ state: 'visible' });
return this.successTextElement.isVisible();
}

async backupDeletionSuccess(): Promise<boolean> {
await this.backupDeletionSuccessText.waitFor({ state: 'visible' });
return this.backupDeletionSuccessText.isVisible();
}


async countSyncedInstances():Promise<number>{
const countInstancesText = await this.page.getByText("Synchronized instance").textContent();
const instanceCount = extractNumberFromText(countInstancesText || "");
return instanceCount;
}

Check failure on line 103 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Delete `⏎`

Check failure on line 103 in apps/ledger-live-desktop/tests/page/settings.page.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

prettier/prettier

Delete `⏎`

async closeLSManagerDrawer(){
await this.closeLSDrawerButton.nth(0).click();
}

}

async function extractNumberFromText(text: string): Promise<number> {
const match = text.match(/\d+/);
return match ? parseInt(match[0], 10) : 0;
}
Original file line number Diff line number Diff line change
@@ -1,58 +1,43 @@
import { test } from "../../fixtures/common";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { expect } from '@playwright/test';
import { AppInfos } from "tests/enum/AppInfos";

const apps: AppInfos[] = [AppInfos.LS];
// Use a single value instead of an array
const app: AppInfos = AppInfos.LS;

for (const myapp of apps) {
test.describe(`[${myapp.name}] Add Accounts`, () => {
test.use({
userdata: "ledgerSync",
speculosApp: myapp,

});

test("Synchronize one instance then delete the backup", async ({ app, page }) => {
const description = getDescription(test.info().annotations).split(", ");
await addTmsLink(description);

// Step 1: Validate the presence of the sync entry point
await test.step("Check if sync entry point exists", async () => {
await app.settings.goToSettings();
await app.settings.goToGeneralSettings();
await app.settings.openManageLedgerSync();
const isSyncButtonVisible = await app.settings.doesSyncAccountsButtonExist();
expect(isSyncButtonVisible).toBe(true);
});

// Step 2: Perform synchronization and validate the process
await test.step("Perform synchronization and validate success", async () => {
await app.settings.SyncAccounts();
await app.speculos.confirmOperationOnDevice("Log in to");
await app.speculos.confirmOperationOnDevice("Enable");
const success = await app.settings.checkSynchronizationSuccess();
expect(success).toBe(true);
await app.settings.closeLedgerSync();
});

// Step 3: Validate the number of synchronized instances
await test.step("Validate number of synchronized instances", async () => {
await app.settings.openManageLedgerSync();
const nbInstances = await app.settings.countSyncedInstances();
expect(nbInstances).toBe(1);
await app.settings.closeLSManagerDrawer();
});
test.describe(`[${app.name}] Sync Accounts`, () => {
test.use({
userdata: "ledgerSync",
speculosApp: app,
});

// Step 4: Delete backup
await test.step("Delete backup and validate", async () => {
await app.settings.openManageLedgerSync();
await app.settings.destroyTrustchain();
const deletionsuccess = await app.settings.backupDeletionSuccess();
expect(deletionsuccess).toBe(true);
await app.settings.closeLSManagerDrawer();
});
});
test("Synchronize one instance then delete the backup", async ({ app, page }) => {

Check failure on line 15 in apps/ledger-live-desktop/tests/specs/speculos/manage.ledgersync.spec.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

@typescript-eslint/no-unused-vars

'page' is defined but never used. Allowed unused args must match /^_/u.

Check failure on line 15 in apps/ledger-live-desktop/tests/specs/speculos/manage.ledgersync.spec.ts

View check run for this annotation

live-github-bot / @Desktop • Test App

@typescript-eslint/no-unused-vars

'page' is defined but never used. Allowed unused args must match /^_/u.
const description = getDescription(test.info().annotations).split(", ");
await addTmsLink(description);

// Step 1: Validate the presence of the sync entry point
await app.settings.goToSettings();
await app.settings.goToGeneralSettings();
await app.settings.openManageLedgerSync();
await app.ledgerSync.expectSyncAccountsButtonExist();

// Step 2: Perform synchronization and validate the process
await app.ledgerSync.SyncAccounts();
await app.speculos.confirmOperationOnDevice("Log in to");
await app.speculos.confirmOperationOnDevice("Enable");
await app.ledgerSync.expectSynchronizationSuccess();
await app.ledgerSync.closeLedgerSync();

// Step 3: Validate the number of synchronized instances
await app.settings.openManageLedgerSync();
await app.ledgerSync.expectNbSyncedInstances(1);
await app.ledgerSync.closeLSManagerDrawer();

// Step 4: Delete backup
await app.settings.openManageLedgerSync();
await app.ledgerSync.destroyTrustchain();
await app.ledgerSync.expectBackupDeletion();
await app.ledgerSync.closeLSManagerDrawer();
});
}
});

0 comments on commit 693f264

Please sign in to comment.