Skip to content

Commit

Permalink
feat(ui-test): cover switching networks (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
arein authored Dec 28, 2023
1 parent 0825fcf commit fd29e0f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ui_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
ui_tests:
name: 'Playwright Tests'
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 10
steps:
- name: checkout
uses: actions/checkout@v3
Expand Down
20 changes: 20 additions & 0 deletions apps/laboratory/tests/connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@ testMW(
await modalValidator.expectRejectedSign()
}
)

testMW(
'it should switch networks and sign',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
let targetChain = 'Polygon'
await modalPage.switchNetwork(targetChain)
await modalPage.sign()
await walletValidator.expectReceivedSign({ chainName: targetChain })
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSign()

// Switch to Ethereum
targetChain = 'Ethereum'
await modalPage.switchNetwork(targetChain)
await modalPage.sign()
await walletValidator.expectReceivedSign({ chainName: targetChain })
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSign()
}
)
7 changes: 7 additions & 0 deletions apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ export class ModalPage {
async sign() {
await this.page.getByTestId('sign-message-button').click()
}

async switchNetwork(network: string) {
await this.page.getByTestId('account-button').click()
await this.page.getByTestId('w3m-account-select-network').click()
await this.page.getByTestId(`w3m-network-switch-${network}`).click()
await this.page.getByTestId(`w3m-header-close`).click()
}
}
1 change: 1 addition & 0 deletions packages/scaffold/src/partials/w3m-header/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class W3mHeader extends LitElement {
?disabled=${this.buffering}
icon="close"
@click=${this.onClose.bind(this)}
data-testid="w3m-header-close"
></wui-icon-link>
</wui-flex>
${this.separatorTemplate()}
Expand Down
1 change: 1 addition & 0 deletions packages/scaffold/src/views/w3m-account-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class W3mAccountView extends LitElement {
imageSrc=${ifDefined(networkImage)}
?chevron=${this.isAllowedNetworkSwitch()}
@click=${this.onNetworks.bind(this)}
data-testid="w3m-account-select-network"
>
<wui-text variant="paragraph-500" color="fg-100">
${this.network?.name ?? 'Unknown'}
Expand Down
1 change: 1 addition & 0 deletions packages/scaffold/src/views/w3m-networks-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class W3mNetworksView extends LitElement {
name=${network.name ?? network.id}
@click=${() => this.onSwitchNetwork(network)}
.disabled=${!supportsAllNetworks && !approvedIds?.includes(network.id)}
data-testid=${`w3m-network-switch-${network.name ?? network.id}`}
></wui-card-select>
`
)
Expand Down

3 comments on commit fd29e0f

@vercel
Copy link

@vercel vercel bot commented on fd29e0f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on fd29e0f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on fd29e0f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.