From 46d1247d4d326775ec00b44e774165675e705678 Mon Sep 17 00:00:00 2001 From: jdabbech-ledger Date: Fri, 4 Oct 2024 13:44:52 +0200 Subject: [PATCH] :white_check_mark: (smpl): Update e2e tests with drawer device selection --- .../cases/device-action_list-apps.spec.ts | 2 +- .../cases/device-action_open-app.spec.ts | 2 +- .../device-command_close-bitcoin-app.spec.ts | 2 +- ...device-command_get-app-and-version.spec.ts | 2 +- .../device-command_open-bitcoin-app.spec.ts | 2 +- .../cases/device-connection.spec.ts | 16 +++++++----- .../cases/device-disconnection.spec.ts | 22 +++++++++++----- .../cases/eth_get-address_happy-paths.spec.ts | 6 ++--- .../eth_get-address_unhappy-paths.spec.ts | 2 +- .../eth_sign-message_happy-paths.spec.ts | 6 ++--- .../eth_sign-message_unhappy-paths.spec.ts | 2 +- .../eth_sign-transaction_happy-paths.spec.ts | 4 +-- ...eth_sign-transaction_unhappy-paths.spec.ts | 2 +- ...eth_sign-typed-message-happy-paths.spec.ts | 6 ++--- ...h_sign-typed-message-unhappy-paths.spec.ts | 2 +- apps/sample/playwright/utils/thenHandlers.ts | 18 +++++++++---- apps/sample/playwright/utils/whenHandlers.ts | 26 ++++++++++++++++--- 17 files changed, 81 insertions(+), 41 deletions(-) diff --git a/apps/sample/playwright/cases/device-action_list-apps.spec.ts b/apps/sample/playwright/cases/device-action_list-apps.spec.ts index eef568ac8..2229075fe 100644 --- a/apps/sample/playwright/cases/device-action_list-apps.spec.ts +++ b/apps/sample/playwright/cases/device-action_list-apps.spec.ts @@ -25,7 +25,7 @@ test.describe("device action: list apps", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then execute list apps via device action", async () => { diff --git a/apps/sample/playwright/cases/device-action_open-app.spec.ts b/apps/sample/playwright/cases/device-action_open-app.spec.ts index fec1e9557..3c8823ba7 100644 --- a/apps/sample/playwright/cases/device-action_open-app.spec.ts +++ b/apps/sample/playwright/cases/device-action_open-app.spec.ts @@ -24,7 +24,7 @@ test.describe("device action: open bitcoin app", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then execute open app via device action", async () => { diff --git a/apps/sample/playwright/cases/device-command_close-bitcoin-app.spec.ts b/apps/sample/playwright/cases/device-command_close-bitcoin-app.spec.ts index f29950172..42c048067 100644 --- a/apps/sample/playwright/cases/device-command_close-bitcoin-app.spec.ts +++ b/apps/sample/playwright/cases/device-command_close-bitcoin-app.spec.ts @@ -27,7 +27,7 @@ test.describe("device command: close bitcoin app", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then execute open app via device command", async () => { diff --git a/apps/sample/playwright/cases/device-command_get-app-and-version.spec.ts b/apps/sample/playwright/cases/device-command_get-app-and-version.spec.ts index a7abe7dfd..461e7e788 100644 --- a/apps/sample/playwright/cases/device-command_get-app-and-version.spec.ts +++ b/apps/sample/playwright/cases/device-command_get-app-and-version.spec.ts @@ -38,7 +38,7 @@ test.describe("device command: get app and version", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then execute open app via device command", async () => { diff --git a/apps/sample/playwright/cases/device-command_open-bitcoin-app.spec.ts b/apps/sample/playwright/cases/device-command_open-bitcoin-app.spec.ts index ba8bce09f..f1491696f 100644 --- a/apps/sample/playwright/cases/device-command_open-bitcoin-app.spec.ts +++ b/apps/sample/playwright/cases/device-command_open-bitcoin-app.spec.ts @@ -26,7 +26,7 @@ test.describe("device command: open bitcoin app", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then execute open app via device command", async () => { diff --git a/apps/sample/playwright/cases/device-connection.spec.ts b/apps/sample/playwright/cases/device-connection.spec.ts index c9c2341ee..26d0d1cbe 100644 --- a/apps/sample/playwright/cases/device-connection.spec.ts +++ b/apps/sample/playwright/cases/device-connection.spec.ts @@ -1,8 +1,11 @@ /* eslint-disable no-restricted-imports */ import { test } from "@playwright/test"; -import { thenDeviceIsConnected } from "../utils/thenHandlers"; -import { whenConnectingDevice } from "../utils/whenHandlers"; +import { + thenDeviceIsConnected, + thenDeviceIsListedAndConnected, +} from "../utils/thenHandlers"; +import { whenCloseDrawer, whenConnectingDevice } from "../utils/whenHandlers"; test.describe("device connection", () => { test.beforeEach(async ({ page }) => { @@ -13,7 +16,7 @@ test.describe("device connection", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); }); @@ -21,13 +24,14 @@ test.describe("device connection", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Given second device is connected", async () => { - await whenConnectingDevice(page); + await whenConnectingDevice(page, false); - await thenDeviceIsConnected(page, 1); + await thenDeviceIsListedAndConnected(page, 1); + await whenCloseDrawer(page); }); }); }); diff --git a/apps/sample/playwright/cases/device-disconnection.spec.ts b/apps/sample/playwright/cases/device-disconnection.spec.ts index c4b9fbff7..bf322dec6 100644 --- a/apps/sample/playwright/cases/device-disconnection.spec.ts +++ b/apps/sample/playwright/cases/device-disconnection.spec.ts @@ -3,11 +3,15 @@ import { test } from "@playwright/test"; import { thenDeviceIsConnected, + thenDeviceIsListedAndConnected, thenNoDeviceIsConnected, } from "../utils/thenHandlers"; import { + whenCloseDrawer, whenConnectingDevice, whenDisconnectDevice, + whenDisconnectListedDevice, + whenOpenSelectDeviceDrawer, } from "../utils/whenHandlers"; test.describe("device disconnection", () => { @@ -19,7 +23,7 @@ test.describe("device disconnection", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then disconnect device", async () => { @@ -33,19 +37,25 @@ test.describe("device disconnection", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Given second device is connected", async () => { - await whenConnectingDevice(page); + await whenConnectingDevice(page, false); + + await thenDeviceIsListedAndConnected(page, 1); - await thenDeviceIsConnected(page, 1); + await whenCloseDrawer(page); }); await test.step("Then disconnect device", async () => { - await whenDisconnectDevice(page); + await whenOpenSelectDeviceDrawer(page); - await whenDisconnectDevice(page); + await whenDisconnectListedDevice(page); + + await whenDisconnectListedDevice(page); + + await whenCloseDrawer(page); await thenNoDeviceIsConnected(page); }); diff --git a/apps/sample/playwright/cases/eth_get-address_happy-paths.spec.ts b/apps/sample/playwright/cases/eth_get-address_happy-paths.spec.ts index 837944c39..60243ef93 100644 --- a/apps/sample/playwright/cases/eth_get-address_happy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_get-address_happy-paths.spec.ts @@ -36,7 +36,7 @@ test.describe("ETH Signer: get address, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: get address", async () => { @@ -71,7 +71,7 @@ test.describe("ETH Signer: get address, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: get address with checkOnDevice on", async () => { @@ -121,7 +121,7 @@ test.describe("ETH Signer: get address, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then execute ETH: get address", async () => { diff --git a/apps/sample/playwright/cases/eth_get-address_unhappy-paths.spec.ts b/apps/sample/playwright/cases/eth_get-address_unhappy-paths.spec.ts index 6176089fb..1126210fb 100644 --- a/apps/sample/playwright/cases/eth_get-address_unhappy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_get-address_unhappy-paths.spec.ts @@ -32,7 +32,7 @@ test.describe("ETH Signer: get address, unhappy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("Then execute ETH: get address with malformed derivation paths", async () => { diff --git a/apps/sample/playwright/cases/eth_sign-message_happy-paths.spec.ts b/apps/sample/playwright/cases/eth_sign-message_happy-paths.spec.ts index 7991f6e5a..9f2efd5f7 100644 --- a/apps/sample/playwright/cases/eth_sign-message_happy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_sign-message_happy-paths.spec.ts @@ -33,7 +33,7 @@ test.describe("ETH Signer: sign message, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign message", async () => { @@ -71,7 +71,7 @@ test.describe("ETH Signer: sign message, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign message", async () => { @@ -133,7 +133,7 @@ test.describe("ETH Signer: sign message, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign message", async () => { diff --git a/apps/sample/playwright/cases/eth_sign-message_unhappy-paths.spec.ts b/apps/sample/playwright/cases/eth_sign-message_unhappy-paths.spec.ts index d07afc052..5e8904cb1 100644 --- a/apps/sample/playwright/cases/eth_sign-message_unhappy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_sign-message_unhappy-paths.spec.ts @@ -33,7 +33,7 @@ test.describe("ETH Signer: sign message, unhappy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign message with malformed derivation paths", async () => { diff --git a/apps/sample/playwright/cases/eth_sign-transaction_happy-paths.spec.ts b/apps/sample/playwright/cases/eth_sign-transaction_happy-paths.spec.ts index 4769463f5..796e9d017 100644 --- a/apps/sample/playwright/cases/eth_sign-transaction_happy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_sign-transaction_happy-paths.spec.ts @@ -36,7 +36,7 @@ test.describe("ETH Signer: sign transaction, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign transaction", async () => { @@ -75,7 +75,7 @@ test.describe("ETH Signer: sign transaction, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign transaction", async () => { diff --git a/apps/sample/playwright/cases/eth_sign-transaction_unhappy-paths.spec.ts b/apps/sample/playwright/cases/eth_sign-transaction_unhappy-paths.spec.ts index 4ab5e6b47..126897a50 100644 --- a/apps/sample/playwright/cases/eth_sign-transaction_unhappy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_sign-transaction_unhappy-paths.spec.ts @@ -33,7 +33,7 @@ test.describe("ETH Signer: sign transaction, unhappy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign transaction with malformed derivation paths", async () => { diff --git a/apps/sample/playwright/cases/eth_sign-typed-message-happy-paths.spec.ts b/apps/sample/playwright/cases/eth_sign-typed-message-happy-paths.spec.ts index 624e210ae..09da5b9e6 100644 --- a/apps/sample/playwright/cases/eth_sign-typed-message-happy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_sign-typed-message-happy-paths.spec.ts @@ -33,7 +33,7 @@ test.describe("ETH Signer: sign EIP712 message, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign EIP712 message", async () => { @@ -72,7 +72,7 @@ test.describe("ETH Signer: sign EIP712 message, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign EIP712 message", async () => { @@ -135,7 +135,7 @@ test.describe("ETH Signer: sign EIP712 message, happy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign EIP712 message", async () => { diff --git a/apps/sample/playwright/cases/eth_sign-typed-message-unhappy-paths.spec.ts b/apps/sample/playwright/cases/eth_sign-typed-message-unhappy-paths.spec.ts index 4cf56a50d..74678e8fe 100644 --- a/apps/sample/playwright/cases/eth_sign-typed-message-unhappy-paths.spec.ts +++ b/apps/sample/playwright/cases/eth_sign-typed-message-unhappy-paths.spec.ts @@ -33,7 +33,7 @@ test.describe("ETH Signer: sign EIP712 message, unhappy paths", () => { await test.step("Given first device is connected", async () => { await whenConnectingDevice(page); - await thenDeviceIsConnected(page, 0); + await thenDeviceIsConnected(page); }); await test.step("When execute ETH: sign typed message with malformed derivation paths", async () => { diff --git a/apps/sample/playwright/utils/thenHandlers.ts b/apps/sample/playwright/utils/thenHandlers.ts index 5b253c2e6..5c678a570 100644 --- a/apps/sample/playwright/utils/thenHandlers.ts +++ b/apps/sample/playwright/utils/thenHandlers.ts @@ -2,8 +2,13 @@ import { expect, Locator, Page } from "@playwright/test"; import { asyncPipe } from "@/utils/pipes"; -const getDeviceLocator = - (deviceIndex: number = 0) => +const getDeviceLocator = (page: Page): Page => { + const targetChild = page.getByTestId("container_main-device").locator("> *"); + return targetChild as unknown as Page; +}; + +const getListedDeviceLocator = + (deviceIndex: number) => (page: Page): Page => { const targetChild = page .getByTestId("container_devices") @@ -24,11 +29,14 @@ const verifyDeviceConnectedStatus = async ( return locator; }; -export const thenDeviceIsConnected = ( +export const thenDeviceIsConnected = (page: Page): Promise => + asyncPipe(getDeviceLocator, verifyDeviceConnectedStatus)(page); + +export const thenDeviceIsListedAndConnected = ( page: Page, - deviceIndex: number = 0, + index: number, ): Promise => - asyncPipe(getDeviceLocator(deviceIndex), verifyDeviceConnectedStatus)(page); + asyncPipe(getListedDeviceLocator(index), verifyDeviceConnectedStatus)(page); const getAllDeviceNames = async (page: Page): Promise => { return page diff --git a/apps/sample/playwright/utils/whenHandlers.ts b/apps/sample/playwright/utils/whenHandlers.ts index 12bb20319..52daaa61f 100644 --- a/apps/sample/playwright/utils/whenHandlers.ts +++ b/apps/sample/playwright/utils/whenHandlers.ts @@ -8,9 +8,9 @@ type DeviceCommandParams = { }; const clickByTestId = - (testId: string) => + (testId: string, force: boolean = false) => async (page: Page): Promise => { - await page.getByTestId(testId).click(); + await page.getByTestId(testId).click({ force }); return page; }; @@ -44,8 +44,20 @@ const fillInputFields = return page; }; -export const whenConnectingDevice = (page: Page): Promise => - clickByTestId("CTA_select-device")(page); +export const whenOpenSelectDeviceDrawer = async (page: Page): Promise => + await clickByTestId("CTA_open-select-device-drawer")(page); + +export const whenConnectingDevice = async ( + page: Page, + closeDrawer: boolean = true, +): Promise => { + await whenOpenSelectDeviceDrawer(page); + const newPage = await clickByTestId("CTA_select-device")(page); + if (closeDrawer) { + return whenCloseDrawer(page); + } + return newPage; +}; export const whenClicking = (page: Page, ctaSelector: string): Promise => clickByTestId(ctaSelector)(page); @@ -88,6 +100,9 @@ export const whenExecute = export const whenExecuteDeviceAction = whenExecute("device-action", true); export const whenExecuteDeviceCommand = whenExecute("device-command", true); +const getMainDevice = (page: Page): Locator => + page.getByTestId("container_main-device").locator("> *").first(); + const getFirstDevice = (page: Page): Locator => page.getByTestId("container_devices").locator("> *").first(); @@ -98,6 +113,9 @@ const clickDeviceOptionAndDisconnect = async (page: Page): Promise => { }; export const whenDisconnectDevice = (page: Page): Promise => + asyncPipe(getMainDevice, clickDeviceOptionAndDisconnect)(page); + +export const whenDisconnectListedDevice = (page: Page): Promise => asyncPipe(getFirstDevice, clickDeviceOptionAndDisconnect)(page); const drawerCloseButtonSelector =