Skip to content

Commit

Permalink
feat: 7702 e2e tests (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobChangCA authored Feb 18, 2025
1 parent c16b0d5 commit 5e09e3b
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 79 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ account-kit/rn-signer/lib/*
**/build/*
**/.cxx/*

**/vendor/*
**/vendor/*
**/test-results/*
**/playwright-report/*
24 changes: 24 additions & 0 deletions examples/ui-demo/e2e/7702.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test, expect } from "@playwright/test";
import { mintWithGoogleAuthWorkflow } from "./helpers/mintWorkflow";
const googleEmail = process.env.PLAYWRIGHT_GOOGLE_EMAIL;
const googlePassword = process.env.PLAYWRIGHT_GOOGLE_PASSWORD;

test.beforeEach(async ({ page, baseURL }) => {
await page.goto(baseURL!);
});
test("Google sign in", async ({ page }) => {
if (!googleEmail || !googlePassword) {
throw new Error(
"PLAYWRIGHT_GOOGLE_EMAIL and PLAYWRIGHT_GOOGLE_PASSWORD must be set"
);
}
await expect(page).toHaveTitle(/Account Kit/);
// Fast way to initialize the page and ensure config is loaded
await page.getByRole("switch", { name: "Email" }).click();
await page.getByRole("switch", { name: "Email" }).click();
const walletSwitch = await page.locator("#wallet-switch");
if ((await walletSwitch.getAttribute("aria-checked")) === "false") {
await walletSwitch.click();
}
await mintWithGoogleAuthWorkflow(page, googleEmail, googlePassword);
});
55 changes: 55 additions & 0 deletions examples/ui-demo/e2e/helpers/mintWorkflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// sharedWorkflow.ts
import { Page, expect } from "@playwright/test";

export async function mintWithGoogleAuthWorkflow(
page: Page,
googleEmail: string,
googlePassword: string
) {
// Google sign in
await page.locator("button[aria-label='Google sign in']").click();
const popup = await page.waitForEvent("popup");
await popup.waitForLoadState("networkidle");

const emailInput = popup.getByRole("textbox");
await emailInput.fill(googleEmail);
await popup.getByRole("button", { name: /Next/i }).click();
await expect(popup.getByText(/Enter your password/i)).toBeVisible();

const passwordInput = popup.locator("input[type='password']:visible");
await passwordInput.fill(googlePassword);
await popup.getByRole("button", { name: /Next/i }).click();

// Wait for page to load after sign in
await expect(page.getByText(/Gasless transactions/i)).toBeVisible();
const avatar = page.getByRole("button", { name: `Hello, ${googleEmail}` });
await expect(avatar).toBeVisible();
await page.locator("img[alt='An NFT']");

// Collect NFT
await page.getByRole("button", { name: "Collect NFT" }).click();
await expect(page.getByText("Success", { exact: true })).toBeVisible({
timeout: 30000,
});

// Create session key
await page.getByRole("button", { name: "Create session key" }).click();
await expect(page.getByText("Bought 1 ETH")).toBeVisible({
timeout: 30000,
});

// Check external links
await expect(page.locator("a[aria-label='View transaction']")).toBeVisible();
await expect(page.getByRole("link", { name: "Quickstart" })).toHaveAttribute(
"href",
"https://accountkit.alchemy.com/react/quickstart"
);
await expect(page.locator("a[aria-label='GitHub']")).toHaveAttribute(
"href",
"https://github.com/alchemyplatform/aa-sdk/tree/v4.x.x"
);
await expect(page.getByRole("link", { name: "CSS" })).toHaveAttribute(
"href",
"https://github.com/alchemyplatform/aa-sdk/blob/v4.x.x/account-kit/react/src/tailwind/types.ts#L6"
);
}
74 changes: 0 additions & 74 deletions examples/ui-demo/e2e/smart-contract-mint.spec.ts

This file was deleted.

26 changes: 26 additions & 0 deletions examples/ui-demo/e2e/smart-contract.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect } from "@playwright/test";
import { mintWithGoogleAuthWorkflow } from "./helpers/mintWorkflow";
const googleEmail = process.env.PLAYWRIGHT_GOOGLE_EMAIL;
const googlePassword = process.env.PLAYWRIGHT_GOOGLE_PASSWORD;

test.beforeEach(async ({ page, baseURL }) => {
await page.goto(baseURL!);
});
test("Google sign in", async ({ page }) => {
if (!googleEmail || !googlePassword) {
throw new Error(
"PLAYWRIGHT_GOOGLE_EMAIL and PLAYWRIGHT_GOOGLE_PASSWORD must be set"
);
}
await expect(page).toHaveTitle(/Account Kit/);
// Fast way to initialize the page and ensure config is loaded
await page.getByRole("switch", { name: "Email" }).click();
await page.getByRole("switch", { name: "Email" }).click();

const walletSwitch = await page.locator("#wallet-switch");
if ((await walletSwitch.getAttribute("aria-checked")) === "true") {
await walletSwitch.click();
}

await mintWithGoogleAuthWorkflow(page, googleEmail, googlePassword);
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ export const Configuration = ({ className }: { className?: string }) => {
<span className="font-semibold">Configuration</span>
</div>
<div className="flex flex-row items-center gap-2 pb-2">
<h4 className="font-normal text-sm text-secondary-foreground">
<label
className="font-normal text-sm text-secondary-foreground"
htmlFor="wallet-switch"
>
Embedded wallet type
</h4>
</label>
{/* <HelpTooltip text="An account powered by a smart contract to enable more features. Not an EOA. Recommended for new wallets." /> */}
</div>
<WalletTypeSwitch
id="theme-switch"
id="wallet-switch"
checked={walletType === WalletTypes.hybrid7702}
onCheckedChange={onSwitchWalletType}
/>
Expand Down
7 changes: 6 additions & 1 deletion examples/ui-demo/src/components/small-cards/MintStages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export const MintStages = ({
<span className="flex gap-3 justify-between">
Deploying your smart account...
{status.batch === "success" && transactionUrl && (
<a href={transactionUrl} target="_blank" rel="noreferrer">
<a
href={transactionUrl}
target="_blank"
rel="noreferrer"
aria-label="View transaction"
>
<ExternalLinkIcon className="stroke-fg-secondary w-4 h-4" />
</a>
)}
Expand Down

0 comments on commit 5e09e3b

Please sign in to comment.