Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ’„ (smpl) [DSDK-518]: Update device selection according to figma #356

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-humans-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-sdk-sample": patch
---

Select device in a drawer
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
22 changes: 20 additions & 2 deletions apps/sample/playwright/utils/whenHandlers.ts
Original file line number Diff line number Diff line change
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
13 changes: 8 additions & 5 deletions apps/sample/src/app/client-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SdkProvider } from "@/providers/DeviceSdkProvider";
import { DeviceSessionsProvider } from "@/providers/DeviceSessionsProvider";
import { SdkConfigProvider } from "@/providers/SdkConfig";
import { GlobalStyle } from "@/styles/globalstyles";
import { DeviceSelectionProvider } from "@/providers/DeviceSelectionProvider";

const Root = styled(Flex)`
flex-direction: row;
Expand All @@ -44,11 +45,13 @@ const ClientRootLayout: React.FC<PropsWithChildren> = ({ children }) => {
<body>
<Root>
<DeviceSessionsProvider>
<Sidebar />
<PageContainer>
<Header />
{children}
</PageContainer>
<DeviceSelectionProvider>
<Sidebar />
<PageContainer>
<Header />
{children}
</PageContainer>
</DeviceSelectionProvider>
</DeviceSessionsProvider>
</Root>
</body>
Expand Down
Loading
Loading