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

feat(ui-test): cover switching networks #1678

Merged
merged 4 commits into from
Dec 28, 2023
Merged
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
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)
arein marked this conversation as resolved.
Show resolved Hide resolved
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
Loading