-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7027f68
commit 0f9e04e
Showing
3 changed files
with
55 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,27 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { WebauthnEmulator } from "./webauthn"; | ||
import { Keychain } from "./keychain"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("/"); | ||
const client = await page.context().newCDPSession(page); | ||
const webauthn = new WebauthnEmulator(client); | ||
const webauthn = new WebauthnEmulator({ client }); | ||
await webauthn.enable(); | ||
await webauthn.addVirtualAuthenticator(); | ||
}); | ||
|
||
test.describe("Sign up", () => { | ||
test("should allow user to sign up and connect to Controller", async ({ | ||
page, | ||
}) => { | ||
await page.getByText("Connect").click(); | ||
const modal = page.frameLocator("#cartridge-modal"); | ||
test("Sign up", async ({ page }) => { | ||
const keychain = new Keychain({ page }); | ||
await keychain.signup(); | ||
|
||
await expect( | ||
modal.getByText("Play with Cartridge Controller"), | ||
).toBeVisible(); | ||
await expect( | ||
modal.getByText("Create your Cartridge Controller"), | ||
).toBeVisible(); | ||
|
||
const username = `test-${Date.now()}`; | ||
await modal.getByPlaceholder("Username").fill(username); | ||
await modal.getByText("SIGN UP").click(); | ||
|
||
await expect(modal.getByText("Create Session").first()).toBeVisible(); | ||
await modal.getByRole("button", { name: "CREATE SESSION" }).click(); | ||
|
||
await expect(page.getByText(`Username: ${username}`)).toBeVisible(); | ||
}); | ||
await expect(page.getByText(`Username: ${keychain.username}`)).toBeVisible(); | ||
}); | ||
|
||
// test.describe("Log in", () => { | ||
// test("should allow me to login and connect to Controller", async ({ | ||
// page, | ||
// }) => { | ||
// await page.getByText("Connect").click(); | ||
// const modal = page.frameLocator("#cartridge-modal"); | ||
// await modal.getByText("Log In").click(); | ||
// await expect( | ||
// modal.getByText("Play with Cartridge Controller"), | ||
// ).toBeVisible(); | ||
// await modal.getByPlaceholder("Username").fill("test-1"); | ||
// await modal.getByText("LOG IN").click(); | ||
test("Log in", async ({ page }) => { | ||
const keychain = new Keychain({ page }); | ||
await keychain.signup(); | ||
await keychain.disconnect(); | ||
await keychain.login(); | ||
|
||
// await expect(page.getByText("Address: ")).toBeVisible(); | ||
// }); | ||
// }); | ||
await expect(page.getByText(`Username: ${keychain.username}`)).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { FrameLocator } from "@playwright/test"; | ||
import { Page } from "@playwright/test"; | ||
|
||
export class Keychain { | ||
private page: Page; | ||
private modal: FrameLocator; | ||
public username: string; | ||
|
||
constructor({ page, username }: { page: Page; username?: string }) { | ||
this.page = page; | ||
this.modal = page.frameLocator("#cartridge-modal"); | ||
this.username = username ?? this.randomUsername(); | ||
Check failure Code scanning / CodeQL Insecure randomness High test
This uses a cryptographically insecure random number generated at
Math.random() Error loading related location Loading |
||
} | ||
|
||
async signup() { | ||
await this.connect(); | ||
await this.modal.getByPlaceholder("Username").fill(this.username); | ||
await this.modal.getByText("SIGN UP").click(); | ||
await this.modal.getByRole("button", { name: "CREATE SESSION" }).click(); | ||
} | ||
|
||
async login() { | ||
await this.connect(); | ||
await this.modal.getByText("Log In").click(); | ||
await this.modal.getByPlaceholder("Username").fill(this.username); | ||
await this.modal.getByText("LOG IN").click(); | ||
} | ||
|
||
disconnect() { | ||
return this.page.getByText("Disconnect").click(); | ||
} | ||
|
||
private connect() { | ||
return this.page.getByText("Connect").click(); | ||
} | ||
|
||
private randomUsername() { | ||
return `test-${Math.random().toString().slice(2, -1)}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters