Skip to content

Commit 3be4534

Browse files
✅ (smpl): Update e2e tests with drawer device selection
1 parent 25595dc commit 3be4534

17 files changed

+79
-39
lines changed

apps/sample/playwright/cases/device-action_list-apps.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test.describe("device action: list apps", () => {
2525
await test.step("Given first device is connected", async () => {
2626
await whenConnectingDevice(page);
2727

28-
await thenDeviceIsConnected(page, 0);
28+
await thenDeviceIsConnected(page);
2929
});
3030

3131
await test.step("Then execute list apps via device action", async () => {

apps/sample/playwright/cases/device-action_open-app.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test.describe("device action: open bitcoin app", () => {
2424
await test.step("Given first device is connected", async () => {
2525
await whenConnectingDevice(page);
2626

27-
await thenDeviceIsConnected(page, 0);
27+
await thenDeviceIsConnected(page);
2828
});
2929

3030
await test.step("Then execute open app via device action", async () => {

apps/sample/playwright/cases/device-command_close-bitcoin-app.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test.describe("device command: close bitcoin app", () => {
2727
await test.step("Given first device is connected", async () => {
2828
await whenConnectingDevice(page);
2929

30-
await thenDeviceIsConnected(page, 0);
30+
await thenDeviceIsConnected(page);
3131
});
3232

3333
await test.step("Then execute open app via device command", async () => {

apps/sample/playwright/cases/device-command_get-app-and-version.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.describe("device command: get app and version", () => {
3838
await test.step("Given first device is connected", async () => {
3939
await whenConnectingDevice(page);
4040

41-
await thenDeviceIsConnected(page, 0);
41+
await thenDeviceIsConnected(page);
4242
});
4343

4444
await test.step("Then execute open app via device command", async () => {

apps/sample/playwright/cases/device-command_open-bitcoin-app.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test.describe("device command: open bitcoin app", () => {
2626
await test.step("Given first device is connected", async () => {
2727
await whenConnectingDevice(page);
2828

29-
await thenDeviceIsConnected(page, 0);
29+
await thenDeviceIsConnected(page);
3030
});
3131

3232
await test.step("Then execute open app via device command", async () => {
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/* eslint-disable no-restricted-imports */
22
import { test } from "@playwright/test";
33

4-
import { thenDeviceIsConnected } from "../utils/thenHandlers";
5-
import { whenConnectingDevice } from "../utils/whenHandlers";
4+
import {
5+
thenDeviceIsConnected,
6+
thenDeviceIsListedAndConnected,
7+
} from "../utils/thenHandlers";
8+
import { whenCloseDrawer, whenConnectingDevice } from "../utils/whenHandlers";
69

710
test.describe("device connection", () => {
811
test.beforeEach(async ({ page }) => {
@@ -13,21 +16,22 @@ test.describe("device connection", () => {
1316
await test.step("Given first device is connected", async () => {
1417
await whenConnectingDevice(page);
1518

16-
await thenDeviceIsConnected(page, 0);
19+
await thenDeviceIsConnected(page);
1720
});
1821
});
1922

2023
test("second device should connect", async ({ page }) => {
2124
await test.step("Given first device is connected", async () => {
2225
await whenConnectingDevice(page);
2326

24-
await thenDeviceIsConnected(page, 0);
27+
await thenDeviceIsConnected(page);
2528
});
2629

2730
await test.step("Given second device is connected", async () => {
28-
await whenConnectingDevice(page);
31+
await whenConnectingDevice(page, false);
2932

30-
await thenDeviceIsConnected(page, 1);
33+
await thenDeviceIsListedAndConnected(page, 1);
34+
await whenCloseDrawer(page);
3135
});
3236
});
3337
});

apps/sample/playwright/cases/device-disconnection.spec.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { test } from "@playwright/test";
33

44
import {
55
thenDeviceIsConnected,
6+
thenDeviceIsListedAndConnected,
67
thenNoDeviceIsConnected,
78
} from "../utils/thenHandlers";
89
import {
10+
whenCloseDrawer,
911
whenConnectingDevice,
1012
whenDisconnectDevice,
13+
whenDisconnectListedDevice,
14+
whenOpenSelectDeviceDrawer,
1115
} from "../utils/whenHandlers";
1216

1317
test.describe("device disconnection", () => {
@@ -19,7 +23,7 @@ test.describe("device disconnection", () => {
1923
await test.step("Given first device is connected", async () => {
2024
await whenConnectingDevice(page);
2125

22-
await thenDeviceIsConnected(page, 0);
26+
await thenDeviceIsConnected(page);
2327
});
2428

2529
await test.step("Then disconnect device", async () => {
@@ -33,19 +37,25 @@ test.describe("device disconnection", () => {
3337
await test.step("Given first device is connected", async () => {
3438
await whenConnectingDevice(page);
3539

36-
await thenDeviceIsConnected(page, 0);
40+
await thenDeviceIsConnected(page);
3741
});
3842

3943
await test.step("Given second device is connected", async () => {
40-
await whenConnectingDevice(page);
44+
await whenConnectingDevice(page, false);
45+
46+
await thenDeviceIsListedAndConnected(page, 1);
4147

42-
await thenDeviceIsConnected(page, 1);
48+
await whenCloseDrawer(page);
4349
});
4450

4551
await test.step("Then disconnect device", async () => {
46-
await whenDisconnectDevice(page);
52+
await whenOpenSelectDeviceDrawer(page);
4753

48-
await whenDisconnectDevice(page);
54+
await whenDisconnectListedDevice(page);
55+
56+
await whenDisconnectListedDevice(page);
57+
58+
await whenCloseDrawer(page);
4959

5060
await thenNoDeviceIsConnected(page);
5161
});

apps/sample/playwright/cases/eth_get-address_happy-paths.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test.describe("ETH Signer: get address, happy paths", () => {
3636
await test.step("Given first device is connected", async () => {
3737
await whenConnectingDevice(page);
3838

39-
await thenDeviceIsConnected(page, 0);
39+
await thenDeviceIsConnected(page);
4040
});
4141

4242
await test.step("When execute ETH: get address", async () => {
@@ -71,7 +71,7 @@ test.describe("ETH Signer: get address, happy paths", () => {
7171
await test.step("Given first device is connected", async () => {
7272
await whenConnectingDevice(page);
7373

74-
await thenDeviceIsConnected(page, 0);
74+
await thenDeviceIsConnected(page);
7575
});
7676

7777
await test.step("When execute ETH: get address with checkOnDevice on", async () => {
@@ -121,7 +121,7 @@ test.describe("ETH Signer: get address, happy paths", () => {
121121
await test.step("Given first device is connected", async () => {
122122
await whenConnectingDevice(page);
123123

124-
await thenDeviceIsConnected(page, 0);
124+
await thenDeviceIsConnected(page);
125125
});
126126

127127
await test.step("Then execute ETH: get address", async () => {

apps/sample/playwright/cases/eth_get-address_unhappy-paths.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test.describe("ETH Signer: get address, unhappy paths", () => {
3232
await test.step("Given first device is connected", async () => {
3333
await whenConnectingDevice(page);
3434

35-
await thenDeviceIsConnected(page, 0);
35+
await thenDeviceIsConnected(page);
3636
});
3737

3838
await test.step("Then execute ETH: get address with malformed derivation paths", async () => {

apps/sample/playwright/cases/eth_sign-message_happy-paths.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test.describe("ETH Signer: sign message, happy paths", () => {
3333
await test.step("Given first device is connected", async () => {
3434
await whenConnectingDevice(page);
3535

36-
await thenDeviceIsConnected(page, 0);
36+
await thenDeviceIsConnected(page);
3737
});
3838

3939
await test.step("When execute ETH: sign message", async () => {
@@ -71,7 +71,7 @@ test.describe("ETH Signer: sign message, happy paths", () => {
7171
await test.step("Given first device is connected", async () => {
7272
await whenConnectingDevice(page);
7373

74-
await thenDeviceIsConnected(page, 0);
74+
await thenDeviceIsConnected(page);
7575
});
7676

7777
await test.step("When execute ETH: sign message", async () => {
@@ -133,7 +133,7 @@ test.describe("ETH Signer: sign message, happy paths", () => {
133133
await test.step("Given first device is connected", async () => {
134134
await whenConnectingDevice(page);
135135

136-
await thenDeviceIsConnected(page, 0);
136+
await thenDeviceIsConnected(page);
137137
});
138138

139139
await test.step("When execute ETH: sign message", async () => {

apps/sample/playwright/cases/eth_sign-message_unhappy-paths.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test.describe("ETH Signer: sign message, unhappy paths", () => {
3333
await test.step("Given first device is connected", async () => {
3434
await whenConnectingDevice(page);
3535

36-
await thenDeviceIsConnected(page, 0);
36+
await thenDeviceIsConnected(page);
3737
});
3838

3939
await test.step("When execute ETH: sign message with malformed derivation paths", async () => {

apps/sample/playwright/cases/eth_sign-transaction_happy-paths.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test.describe("ETH Signer: sign transaction, happy paths", () => {
3636
await test.step("Given first device is connected", async () => {
3737
await whenConnectingDevice(page);
3838

39-
await thenDeviceIsConnected(page, 0);
39+
await thenDeviceIsConnected(page);
4040
});
4141

4242
await test.step("When execute ETH: sign transaction", async () => {
@@ -75,7 +75,7 @@ test.describe("ETH Signer: sign transaction, happy paths", () => {
7575
await test.step("Given first device is connected", async () => {
7676
await whenConnectingDevice(page);
7777

78-
await thenDeviceIsConnected(page, 0);
78+
await thenDeviceIsConnected(page);
7979
});
8080

8181
await test.step("When execute ETH: sign transaction", async () => {

apps/sample/playwright/cases/eth_sign-transaction_unhappy-paths.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test.describe("ETH Signer: sign transaction, unhappy paths", () => {
3333
await test.step("Given first device is connected", async () => {
3434
await whenConnectingDevice(page);
3535

36-
await thenDeviceIsConnected(page, 0);
36+
await thenDeviceIsConnected(page);
3737
});
3838

3939
await test.step("When execute ETH: sign transaction with malformed derivation paths", async () => {

apps/sample/playwright/cases/eth_sign-typed-message-happy-paths.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test.describe("ETH Signer: sign EIP712 message, happy paths", () => {
3333
await test.step("Given first device is connected", async () => {
3434
await whenConnectingDevice(page);
3535

36-
await thenDeviceIsConnected(page, 0);
36+
await thenDeviceIsConnected(page);
3737
});
3838

3939
await test.step("When execute ETH: sign EIP712 message", async () => {
@@ -72,7 +72,7 @@ test.describe("ETH Signer: sign EIP712 message, happy paths", () => {
7272
await test.step("Given first device is connected", async () => {
7373
await whenConnectingDevice(page);
7474

75-
await thenDeviceIsConnected(page, 0);
75+
await thenDeviceIsConnected(page);
7676
});
7777

7878
await test.step("When execute ETH: sign EIP712 message", async () => {
@@ -135,7 +135,7 @@ test.describe("ETH Signer: sign EIP712 message, happy paths", () => {
135135
await test.step("Given first device is connected", async () => {
136136
await whenConnectingDevice(page);
137137

138-
await thenDeviceIsConnected(page, 0);
138+
await thenDeviceIsConnected(page);
139139
});
140140

141141
await test.step("When execute ETH: sign EIP712 message", async () => {

apps/sample/playwright/cases/eth_sign-typed-message-unhappy-paths.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test.describe("ETH Signer: sign EIP712 message, unhappy paths", () => {
3333
await test.step("Given first device is connected", async () => {
3434
await whenConnectingDevice(page);
3535

36-
await thenDeviceIsConnected(page, 0);
36+
await thenDeviceIsConnected(page);
3737
});
3838

3939
await test.step("When execute ETH: sign typed message with malformed derivation paths", async () => {

apps/sample/playwright/utils/thenHandlers.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { expect, Locator, Page } from "@playwright/test";
22

33
import { asyncPipe } from "@/utils/pipes";
44

5-
const getDeviceLocator =
6-
(deviceIndex: number = 0) =>
5+
const getDeviceLocator = (page: Page): Page => {
6+
const targetChild = page.getByTestId("container_main-device").locator("> *");
7+
return targetChild as unknown as Page;
8+
};
9+
10+
const getListedDeviceLocator =
11+
(deviceIndex: number) =>
712
(page: Page): Page => {
813
const targetChild = page
914
.getByTestId("container_devices")
@@ -24,11 +29,14 @@ const verifyDeviceConnectedStatus = async (
2429
return locator;
2530
};
2631

27-
export const thenDeviceIsConnected = (
32+
export const thenDeviceIsConnected = (page: Page): Promise<Locator> =>
33+
asyncPipe(getDeviceLocator, verifyDeviceConnectedStatus)(page);
34+
35+
export const thenDeviceIsListedAndConnected = (
2836
page: Page,
29-
deviceIndex: number = 0,
37+
index: number,
3038
): Promise<Locator> =>
31-
asyncPipe(getDeviceLocator(deviceIndex), verifyDeviceConnectedStatus)(page);
39+
asyncPipe(getListedDeviceLocator(index), verifyDeviceConnectedStatus)(page);
3240

3341
const getAllDeviceNames = async (page: Page): Promise<string[]> => {
3442
return page

apps/sample/playwright/utils/whenHandlers.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ const fillInputFields =
4444
return page;
4545
};
4646

47-
export const whenConnectingDevice = (page: Page): Promise<Page> =>
48-
clickByTestId("CTA_select-device")(page);
47+
export const whenOpenSelectDeviceDrawer = async (page: Page): Promise<Page> =>
48+
await clickByTestId("CTA_open-select-device-drawer")(page);
49+
50+
export const whenConnectingDevice = async (
51+
page: Page,
52+
closeDrawer: boolean = true,
53+
): Promise<Page> => {
54+
await whenOpenSelectDeviceDrawer(page);
55+
const newPage = await clickByTestId("CTA_select-device")(page);
56+
if (closeDrawer) {
57+
return whenCloseDrawer(page);
58+
}
59+
return newPage;
60+
};
4961

5062
export const whenClicking = (page: Page, ctaSelector: string): Promise<Page> =>
5163
clickByTestId(ctaSelector)(page);
@@ -88,6 +100,9 @@ export const whenExecute =
88100
export const whenExecuteDeviceAction = whenExecute("device-action", true);
89101
export const whenExecuteDeviceCommand = whenExecute("device-command", true);
90102

103+
const getMainDevice = (page: Page): Locator =>
104+
page.getByTestId("container_main-device").locator("> *").first();
105+
91106
const getFirstDevice = (page: Page): Locator =>
92107
page.getByTestId("container_devices").locator("> *").first();
93108

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

100115
export const whenDisconnectDevice = (page: Page): Promise<Page> =>
116+
asyncPipe(getMainDevice, clickDeviceOptionAndDisconnect)(page);
117+
118+
export const whenDisconnectListedDevice = (page: Page): Promise<Page> =>
101119
asyncPipe(getFirstDevice, clickDeviceOptionAndDisconnect)(page);
102120

103121
const drawerCloseButtonSelector =

0 commit comments

Comments
 (0)