Skip to content

Commit

Permalink
fix: removed workflow to reduce confusion, improved naming of validat…
Browse files Browse the repository at this point in the history
…or functions, fixed gitignore, added a seperate script for playwright for future modiciation
  • Loading branch information
JonathanConn committed Jul 31, 2023
1 parent 7c58986 commit 47d4834
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 101 deletions.
27 changes: 0 additions & 27 deletions laboratory/.github/workflows/playwright.yml

This file was deleted.

7 changes: 1 addition & 6 deletions laboratory/.gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
/test-results/
/playwright-report/
/playwright/.cache/
/tests/shared/data/
!/tests/shared/data/extension.txt
/playwright/.cache/
1 change: 1 addition & 0 deletions laboratory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"dev": "rm -rf .next; next dev",
"build": "next build",
"playwright:start": "next dev",
"playwright:install": "playwright install --with-deps",
"playwright:test": "playwright test",
"playwright:debug": "playwright test --debug"
Expand Down
18 changes: 2 additions & 16 deletions laboratory/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ export default defineConfig({
name: 'webkit',
use: { ...devices['Desktop Safari'] }
}

/* Test against other browsers. */
/*
* {
* name: 'firefox',
* use: { ...devices['Desktop Firefox'] }
* },
*
* {
* name: 'webkit',
* use: { ...devices['Desktop Safari'] }
* }
*/
/* Test against mobile viewports. */
/*
* {
Expand Down Expand Up @@ -81,8 +68,7 @@ export default defineConfig({

/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run dev',
url: LOCAL_LAB_URL,
reuseExistingServer: true
command: 'npm run playwright:start',
url: LOCAL_LAB_URL
}
})
8 changes: 8 additions & 0 deletions laboratory/tests/basic-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { testM, expect } from './shared/fixtures/w3m-fixture'

testM.describe('Modal only tests', () => {
testM('Should be able to open modal', async ({ modalPage }) => {
await modalPage.page.getByTestId('partial-core-connect-button').click()
await expect(modalPage.page.getByTestId('component-header-action-button')).toBeVisible()
})
})
24 changes: 12 additions & 12 deletions laboratory/tests/shared/pages/WalletPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import { LOCAL_WALLET_URL } from '../constants'
export class WalletPage {
private readonly baseURL = LOCAL_WALLET_URL

private readonly goToAccounts: Locator
private readonly gotoAccounts: Locator

private readonly goToSessions: Locator
private readonly gotoSessions: Locator

private readonly goToHome: Locator
private readonly gotoHome: Locator

private readonly goToPairings: Locator
private readonly gotoPairings: Locator

private readonly goToSettings: Locator
private readonly gotoSettings: Locator

constructor(public readonly page: Page) {
this.goToAccounts = this.page.getByTestId('accounts')
this.goToSessions = this.page.getByTestId('sessions')
this.goToHome = this.page.getByTestId('wc-connect')
this.goToPairings = this.page.getByTestId('pairings')
this.goToSettings = this.page.getByTestId('settings')
this.gotoAccounts = this.page.getByTestId('accounts')
this.gotoSessions = this.page.getByTestId('sessions')
this.gotoHome = this.page.getByTestId('wc-connect')
this.gotoPairings = this.page.getByTestId('pairings')
this.gotoSettings = this.page.getByTestId('settings')
}

async load() {
await this.page.goto(this.baseURL)
}

async connect() {
await this.goToHome.click()
await this.gotoHome.click()

await this.page.getByTestId('uri-input').click()

Expand All @@ -42,7 +42,7 @@ export class WalletPage {
}

async disconnect() {
await this.goToSessions.click()
await this.gotoSessions.click()
const sessionCard = this.page.getByTestId('session-card').first()
await sessionCard.getByTestId('session-icon').click()
await this.page.getByTestId('session-delete-button').click()
Expand Down
12 changes: 6 additions & 6 deletions laboratory/tests/shared/validators/ModalValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ export class ModalValidator {

constructor(public readonly page: Page) {}

async isConnected() {
async expectConnected() {
if (this.page.url() !== this.baseURL) {
await this.page.goto(this.baseURL)
}
await expect(this.page.getByTestId('partial-account-address')).toBeVisible()
}

async isDisconnected() {
async expectDisconnected() {
if (this.page.url() !== this.baseURL) {
await this.page.goto(this.baseURL)
}
await expect(this.page.getByTestId('partial-account-address')).not.toBeVisible()
}

async acceptedSign() {
async expectAcceptedSign() {
await expect(this.page.getByText('Sign Message')).toBeVisible()
await expect(this.page.getByText('0x')).toBeVisible()
}

async rejectedSign() {
async expectRejectedSign() {
await expect(this.page.getByText('Sign Message')).toBeVisible()
await expect(this.page.getByText(/User rejected/u)).toBeVisible()
}

async acceptedSignTyped() {
async expectAcceptedSignTyped() {
await expect(this.page.getByText('Sign Typed Data')).toBeVisible()
await expect(this.page.getByText('0x')).toBeVisible()
}

async rejectedSignTyped() {
async expectRejectedSignTyped() {
await expect(this.page.getByText('Sign Typed Data')).toBeVisible()
await expect(this.page.getByText(/User rejected/u)).toBeVisible()
}
Expand Down
32 changes: 16 additions & 16 deletions laboratory/tests/shared/validators/WalletValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ import { LOCAL_WALLET_URL } from '../constants'
export class WalletValidator {
private readonly baseURL = LOCAL_WALLET_URL

private readonly goToAccounts: Locator
private readonly gotoAccounts: Locator

private readonly goToSessions: Locator
private readonly gotoSessions: Locator

private readonly goToHome: Locator
private readonly gotoHome: Locator

private readonly goToPairings: Locator
private readonly gotoPairings: Locator

private readonly goToSettings: Locator
private readonly gotoSettings: Locator

constructor(public readonly page: Page) {
this.goToAccounts = this.page.getByTestId('accounts')
this.goToSessions = this.page.getByTestId('sessions')
this.goToHome = this.page.getByTestId('wc-connect')
this.goToPairings = this.page.getByTestId('pairings')
this.goToSettings = this.page.getByTestId('settings')
this.gotoAccounts = this.page.getByTestId('accounts')
this.gotoSessions = this.page.getByTestId('sessions')
this.gotoHome = this.page.getByTestId('wc-connect')
this.gotoPairings = this.page.getByTestId('pairings')
this.gotoSettings = this.page.getByTestId('settings')
}

async isConnected() {
async expectConnected() {
await this.page.reload()
await this.goToSessions.click()
await this.gotoSessions.click()
await expect(this.page.getByTestId('session-card')).toBeVisible()
}

async isDisconnected() {
async expectDisconnected() {
await this.page.reload()
await this.goToSessions.click()
await this.gotoSessions.click()
await expect(this.page.getByTestId('session-card')).not.toBeVisible()
}

async recievedSign({ chainName = 'Ethereum' }) {
async expectRecievedSign({ chainName = 'Ethereum' }) {
await expect(this.page.getByText('Sign Message')).toBeVisible()
await expect(this.page.getByTestId('request-details-chain')).toHaveText(chainName)
}

async recievedSignTyped({ chainName = 'Ethereum' }) {
async expectRecievedSignTyped({ chainName = 'Ethereum' }) {
await expect(this.page.getByText('Sign Typed Data')).toBeVisible()
await expect(this.page.getByTestId('request-details-chain')).toHaveText(chainName)
}
Expand Down
36 changes: 18 additions & 18 deletions laboratory/tests/w3m-wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ testMW.describe('W3M using wallet web-example', () => {
await walletPage.connect()

await walletPage.handleSessionProposal(DEFAULT_SESSION_PARAMS)
await modalValidator.isConnected()
await walletValidator.isConnected()
await modalValidator.expectConnected()
await walletValidator.expectConnected()
})

testMW('Should be able to connect', ({ modalPage, walletPage }) => {
Expand All @@ -20,16 +20,16 @@ testMW.describe('W3M using wallet web-example', () => {
'Should send disconnect to wallet',
async ({ modalPage, modalValidator, walletValidator }) => {
await modalPage.disconnect()
await modalValidator.isDisconnected()
await walletValidator.isDisconnected()
await modalValidator.expectDisconnected()
await walletValidator.expectDisconnected()
}
)
testMW(
'Should recieve disconnect from a wallet',
async ({ walletPage, modalValidator, walletValidator }) => {
await walletPage.disconnect()
await walletValidator.isDisconnected()
await modalValidator.isDisconnected()
await walletValidator.expectDisconnected()
await modalValidator.expectDisconnected()
}
)

Expand All @@ -38,10 +38,10 @@ testMW.describe('W3M using wallet web-example', () => {
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.sign()

await walletValidator.recievedSign({})
await walletValidator.expectRecievedSign({})
await walletPage.handleRequest({ accept: true })

await modalValidator.acceptedSign()
await modalValidator.expectAcceptedSign()
}
)

Expand All @@ -50,10 +50,10 @@ testMW.describe('W3M using wallet web-example', () => {
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.sign()

await walletValidator.recievedSign({})
await walletValidator.expectRecievedSign({})
await walletPage.handleRequest({ accept: false })

await modalValidator.rejectedSign()
await modalValidator.expectRejectedSign()
}
)

Expand All @@ -62,10 +62,10 @@ testMW.describe('W3M using wallet web-example', () => {
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.signTyped()

await walletValidator.recievedSignTyped({})
await walletValidator.expectRecievedSignTyped({})
await walletPage.handleRequest({ accept: true })

await modalValidator.acceptedSignTyped()
await modalValidator.expectAcceptedSignTyped()
}
)

Expand All @@ -74,10 +74,10 @@ testMW.describe('W3M using wallet web-example', () => {
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.signTyped()

await walletValidator.recievedSignTyped({})
await walletValidator.expectRecievedSignTyped({})
await walletPage.handleRequest({ accept: false })

await modalValidator.acceptedSignTyped()
await modalValidator.expectAcceptedSignTyped()
}
)

Expand All @@ -89,10 +89,10 @@ testMW.describe('W3M using wallet web-example', () => {

await modalPage.sign()

await walletValidator.recievedSign({ chainName: 'Polygon' })
await walletValidator.expectRecievedSign({ chainName: 'Polygon' })
await walletPage.handleRequest({ accept: true })

await modalValidator.acceptedSign()
await modalValidator.expectAcceptedSign()
}
)

Expand All @@ -104,10 +104,10 @@ testMW.describe('W3M using wallet web-example', () => {

await modalPage.signTyped()

await walletValidator.recievedSignTyped({ chainName: 'Polygon' })
await walletValidator.expectRecievedSignTyped({ chainName: 'Polygon' })
await walletPage.handleRequest({ accept: true })

await modalValidator.acceptedSignTyped()
await modalValidator.expectAcceptedSignTyped()
}
)
})

0 comments on commit 47d4834

Please sign in to comment.