From 34a12cdd2a807373e0146375a0cb981b3645d924 Mon Sep 17 00:00:00 2001 From: Mohammed-Mamoun98 Date: Tue, 10 Dec 2024 00:13:02 +0200 Subject: [PATCH] updating tests connection and query functions --- apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts | 15 +++++--- apps/idos-sdk-e2e/tests/02-data.spec.ts | 36 +++++++++++-------- apps/idos-sdk-e2e/tests/03-enclave.spec.ts | 40 +++++++++++---------- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts b/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts index 017443230..b1b62615f 100644 --- a/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts +++ b/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts @@ -19,10 +19,14 @@ test("should login successfully with an EVM wallet", async ({ }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); await page.goto("/"); + await page.getByRole("button", { name: "Connect a wallet" }).click(); - await page.getByRole("button", { name: "Metamask" }).click(); - await metamask.connectToDapp(["Pristine"]); + await page.getByRole("button", { name: "Metamask" }).first().click(); + + await metamask.connectToDapp(); await page.waitForTimeout(2000); + await metamask.confirmSignature(); + await expect(page.locator("#disconnect-wallet-btn")).toBeVisible(); }); @@ -34,10 +38,11 @@ test("should set successfully an EVM signer", async ({ }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); await page.goto("/"); + await page.getByRole("button", { name: "Connect a wallet" }).click(); - await page.getByRole("button", { name: "Metamask" }).click(); - await metamask.switchAccount("Account 1"); - await metamask.connectToDapp(["Account 1"]); + await page.getByRole("button", { name: "Metamask" }).first().click(); + + await metamask.connectToDapp(); await page.waitForTimeout(2000); await metamask.confirmSignature(); diff --git a/apps/idos-sdk-e2e/tests/02-data.spec.ts b/apps/idos-sdk-e2e/tests/02-data.spec.ts index 1ffbcbd57..9c706f715 100644 --- a/apps/idos-sdk-e2e/tests/02-data.spec.ts +++ b/apps/idos-sdk-e2e/tests/02-data.spec.ts @@ -21,26 +21,31 @@ test("should fetch credentials successfully", async ({ extensionId, }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); + await page.goto("/"); + await page.getByRole("button", { name: "Connect a wallet" }).click(); - await page.getByRole("button", { name: "Metamask" }).click(); - await metamask.switchAccount("Account 1"); - await metamask.connectToDapp(["Account 1"]); + await page.getByRole("button", { name: "Metamask" }).first().click(); + + await metamask.connectToDapp(); await page.waitForTimeout(2000); await metamask.confirmSignature(); + const list = page.locator("#credentials-list"); - await expect(list.getByRole("listitem")).toHaveCount(3); + await expect(list.getByRole("listitem")).toHaveCount(2); }); test("should fetch wallets successfully", async ({ context, page, metamaskPage, extensionId }) => { await page.goto("/wallets"); const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); + await page.getByRole("button", { name: "Connect a wallet" }).click(); - await page.getByRole("button", { name: "Metamask" }).click(); - await metamask.switchAccount("Account 1"); - await metamask.connectToDapp(["Account 1"]); - await page.waitForTimeout(3000); + await page.getByRole("button", { name: "Metamask" }).first().click(); + + await metamask.connectToDapp(); + await page.waitForTimeout(2000); await metamask.confirmSignature(); - const list = page.locator("#wallets-list"); + + const list = await page.locator("#wallets-list"); await expect(list.getByRole("listitem")).toHaveCount(1); const address = await metamask.getAccountAddress(); await expect(list.getByRole("listitem").first().locator("p").last()).toHaveText( @@ -56,12 +61,16 @@ test("should add / delete a wallet successfully", async ({ }) => { await page.goto("/wallets"); const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); + await page.getByRole("button", { name: "Connect a wallet" }).click(); - await page.getByRole("button", { name: "Metamask" }).click(); - await metamask.switchAccount("Account 1"); - await metamask.connectToDapp(["Account 1"]); - await page.waitForTimeout(3000); + await page.getByRole("button", { name: "Metamask" }).first().click(); + + await metamask.connectToDapp(); + await page.waitForTimeout(2000); await metamask.confirmSignature(); + + const list = await page.locator("#wallets-list"); + // Testing wallet addition const addWalletButton = page.locator("#add-wallet-button"); await addWalletButton.click(); @@ -69,7 +78,6 @@ test("should add / delete a wallet successfully", async ({ await page.locator("#add-wallet-form-submit").click(); await metamask.confirmSignature(); await page.waitForTimeout(5000); - const list = page.locator("#wallets-list"); await expect(list.getByRole("listitem")).toHaveCount(2); // Testing wallet deletion diff --git a/apps/idos-sdk-e2e/tests/03-enclave.spec.ts b/apps/idos-sdk-e2e/tests/03-enclave.spec.ts index 7c4413c0c..5e57709fa 100644 --- a/apps/idos-sdk-e2e/tests/03-enclave.spec.ts +++ b/apps/idos-sdk-e2e/tests/03-enclave.spec.ts @@ -22,24 +22,28 @@ test("should decrypt a credential successfully", async ({ }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); await page.getByRole("button", { name: "Connect a wallet" }).click(); - await page.getByRole("button", { name: "Metamask" }).click(); - await metamask.switchAccount("Account 1"); - await metamask.connectToDapp(["Account 1"]); + await page.getByRole("button", { name: "Metamask" }).first().click(); + + await metamask.connectToDapp(); await page.waitForTimeout(2000); await metamask.confirmSignature(); - const popupPromise = page.waitForEvent("popup"); + await page.waitForTimeout(2000); + await page.getByRole("button", { name: "View details" }).first().click(); - const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock"); + const idOSButton = await page.frameLocator("#idos-enclave-iframe").locator("#unlock"); await idOSButton.click(); + const popupPromise = await page.waitForEvent("popup"); const idOSPopup = await popupPromise; await page.waitForTimeout(2000); - await (await idOSPopup.waitForSelector("#auth-method-password")).click(); - const passwordInput = idOSPopup.locator("#idos-password-input"); + + await idOSPopup.locator("#auth-method-password").click(); + const passwordInput = await idOSPopup.locator("#idos-password-input"); + await passwordInput.fill("qwerty"); await idOSPopup.getByRole("button", { name: "Unlock" }).click(); - const code = page.locator("#credential-details"); - await expect(code).toHaveText(credentialContent); + const code = await page.locator("#credential-details"); + expect(code).toHaveText(credentialContent); }); test("should filter credentials by country successfully", async ({ @@ -51,21 +55,21 @@ test("should filter credentials by country successfully", async ({ const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); await page.goto("e2e/credential-filtering-by-country"); - await page.getByRole("button", { name: "Connect a wallet" }).click(); - await page.getByRole("button", { name: "Metamask" }).click(); - await metamask.switchAccount("Account 1"); - await metamask.connectToDapp(["Account 1"]); + await metamask.connectToDapp(); await page.waitForTimeout(2000); await metamask.confirmSignature(); + await page.waitForTimeout(2000); - const popupPromise = page.waitForEvent("popup"); - - const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock"); + await page.getByRole("button", { name: "View details" }).first().click(); + const idOSButton = await page.frameLocator("#idos-enclave-iframe").locator("#unlock"); await idOSButton.click(); + const popupPromise = await page.waitForEvent("popup"); const idOSPopup = await popupPromise; await page.waitForTimeout(2000); - await (await idOSPopup.waitForSelector("#auth-method-password")).click(); - const passwordInput = idOSPopup.locator("#idos-password-input"); + + await idOSPopup.locator("#auth-method-password").click(); + const passwordInput = await idOSPopup.locator("#idos-password-input"); + await passwordInput.fill("qwerty"); await idOSPopup.getByRole("button", { name: "Unlock" }).click();