Skip to content

Commit

Permalink
✅ (smpl): Update e2e tests with drawer device selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabbech-ledger committed Oct 4, 2024
1 parent 9258f6e commit 46d1247
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
16 changes: 10 additions & 6 deletions apps/sample/playwright/cases/device-connection.spec.ts
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -13,21 +16,22 @@ test.describe("device connection", () => {
await test.step("Given first device is connected", async () => {
await whenConnectingDevice(page);

await thenDeviceIsConnected(page, 0);
await thenDeviceIsConnected(page);
});
});

test("second device should connect", async ({ page }) => {
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);
});
});
});
22 changes: 16 additions & 6 deletions apps/sample/playwright/cases/device-disconnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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 () => {
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
18 changes: 13 additions & 5 deletions apps/sample/playwright/utils/thenHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -24,11 +29,14 @@ const verifyDeviceConnectedStatus = async (
return locator;
};

export const thenDeviceIsConnected = (
export const thenDeviceIsConnected = (page: Page): Promise<Locator> =>
asyncPipe(getDeviceLocator, verifyDeviceConnectedStatus)(page);

export const thenDeviceIsListedAndConnected = (
page: Page,
deviceIndex: number = 0,
index: number,
): Promise<Locator> =>
asyncPipe(getDeviceLocator(deviceIndex), verifyDeviceConnectedStatus)(page);
asyncPipe(getListedDeviceLocator(index), verifyDeviceConnectedStatus)(page);

const getAllDeviceNames = async (page: Page): Promise<string[]> => {
return page
Expand Down
26 changes: 22 additions & 4 deletions apps/sample/playwright/utils/whenHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type DeviceCommandParams = {
};

const clickByTestId =
(testId: string) =>
(testId: string, force: boolean = false) =>
async (page: Page): Promise<Page> => {
await page.getByTestId(testId).click();
await page.getByTestId(testId).click({ force });
return page;
};

Expand Down Expand Up @@ -44,8 +44,20 @@ const fillInputFields =
return page;
};

export const whenConnectingDevice = (page: Page): Promise<Page> =>
clickByTestId("CTA_select-device")(page);
export const whenOpenSelectDeviceDrawer = async (page: Page): Promise<Page> =>
await clickByTestId("CTA_open-select-device-drawer")(page);

export const whenConnectingDevice = async (
page: Page,
closeDrawer: boolean = true,
): Promise<Page> => {
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<Page> =>
clickByTestId(ctaSelector)(page);
Expand Down Expand Up @@ -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();

Expand All @@ -98,6 +113,9 @@ const clickDeviceOptionAndDisconnect = async (page: Page): Promise<Page> => {
};

export const whenDisconnectDevice = (page: Page): Promise<Page> =>
asyncPipe(getMainDevice, clickDeviceOptionAndDisconnect)(page);

export const whenDisconnectListedDevice = (page: Page): Promise<Page> =>
asyncPipe(getFirstDevice, clickDeviceOptionAndDisconnect)(page);

const drawerCloseButtonSelector =
Expand Down

0 comments on commit 46d1247

Please sign in to comment.