Skip to content

Commit

Permalink
feat(ui-test): cover switching networks
Browse files Browse the repository at this point in the history
  • Loading branch information
arein committed Dec 28, 2023
1 parent 8d5737e commit f1338fa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/laboratory/tests/connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ testMW('it should sign', async ({ modalPage, walletPage, modalValidator, walletV
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSign()
})

testMW(
'it should switch networks and sign',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
const targetChain = 'Polygon'
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

0 comments on commit f1338fa

Please sign in to comment.