Skip to content

Commit 54f37b6

Browse files
chore: added tests
1 parent f3f4f37 commit 54f37b6

File tree

7 files changed

+96
-105
lines changed

7 files changed

+96
-105
lines changed

.maestro/w3m-connect-flow.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ appId: com.walletconnect.web3modal.rnclisdk
5757
id: 'account-button'
5858

5959
- tapOn:
60-
id: 'w3m-account-select-network'
60+
id: 'button-network'
6161

6262
- tapOn:
6363
text: 'Polygon'
@@ -68,7 +68,7 @@ appId: com.walletconnect.web3modal.rnclisdk
6868
text: 'Polygon'
6969

7070
- tapOn:
71-
id: 'disconnect-button'
71+
id: 'button-disconnect'
7272

7373
- assertVisible:
7474
id: 'connect-button'

apps/native/tests/shared/pages/ModalPage.ts

Lines changed: 15 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class ModalPage {
9292
await expect(accountBtn, 'Account button should be visible').toBeVisible();
9393
await expect(accountBtn, 'Account button should be enabled').toBeEnabled();
9494
await accountBtn.click();
95-
const disconnectBtn = this.page.getByTestId('disconnect-button');
95+
const disconnectBtn = this.page.getByTestId('button-disconnect');
9696
await expect(disconnectBtn, 'Disconnect button should be visible').toBeVisible();
9797
await expect(disconnectBtn, 'Disconnect button should be enabled').toBeEnabled();
9898
await disconnectBtn.click();
@@ -126,19 +126,11 @@ export class ModalPage {
126126
// }
127127

128128
async switchNetwork(network: string) {
129-
await this.openAccountModal();
130-
await this.page.getByTestId('w3m-account-select-network').click();
131129
await this.page.getByTestId(`w3m-network-switch-${network}`).click();
132130
// The state is chaing too fast and test runner doesn't wait the loading page. It's fastly checking the network selection button and detect that it's switched already.
133131
await this.page.waitForTimeout(300);
134132
}
135133

136-
// async clickWalletDeeplink() {
137-
// await this.connectButton.click();
138-
// await this.page.getByTestId('wallet-selector-react-wallet-v2').click();
139-
// await this.page.getByTestId('tab-desktop').click();
140-
// }
141-
142134
async openAccountModal() {
143135
await this.page.getByTestId('account-button').click();
144136
}
@@ -157,14 +149,6 @@ export class ModalPage {
157149
await this.page.waitForTimeout(300);
158150
}
159151

160-
// async switchNetworkWithNetworkButton(networkName: string) {
161-
// const networkButton = this.page.getByTestId('wui-network-button');
162-
// await networkButton.click();
163-
164-
// const networkToSwitchButton = this.page.getByTestId(`w3m-network-switch-${networkName}`);
165-
// await networkToSwitchButton.click();
166-
// }
167-
168152
async openAllWallets() {
169153
const allWallets = this.page.getByTestId('all-wallets');
170154
await expect(allWallets, 'All wallets should be visible').toBeVisible();
@@ -177,18 +161,6 @@ export class ModalPage {
177161
await qrCodeButton.click();
178162
}
179163

180-
// async clickAllWalletsListSearchItem(id: string) {
181-
// const allWalletsListSearchItem = this.page.getByTestId(`wallet-search-item-${id}`);
182-
// await expect(allWalletsListSearchItem).toBeVisible();
183-
// await allWalletsListSearchItem.click();
184-
// }
185-
186-
// async clickTabWebApp() {
187-
// const tabWebApp = this.page.getByTestId('tab-webapp');
188-
// await expect(tabWebApp).toBeVisible();
189-
// await tabWebApp.click();
190-
// }
191-
192164
async clickHookDisconnectButton() {
193165
const disconnectHookButton = this.page.getByTestId('disconnect-hook-button');
194166
await expect(disconnectHookButton).toBeVisible();
@@ -216,64 +188,31 @@ export class ModalPage {
216188
return this.page.evaluate(() => navigator.clipboard.readText());
217189
}
218190

219-
// async clickOpenWebApp() {
220-
// let url = '';
221-
222-
// const openButton = this.page.getByTestId('w3m-connecting-widget-secondary-button');
223-
// await expect(openButton).toBeVisible();
224-
// await expect(openButton).toHaveText('Open');
225-
226-
// while (!url) {
227-
// await openButton.click();
228-
// await this.page.waitForTimeout(500);
229-
230-
// const pages = this.page.context().pages();
231-
232-
// // Check if more than 1 tab is open
233-
// if (pages.length > 1) {
234-
// const lastTab = pages[pages.length - 1];
235-
236-
// if (lastTab) {
237-
// url = lastTab.url();
238-
// break;
239-
// }
240-
// }
241-
// }
242-
243-
// return url;
244-
// }
245-
246191
async search(value: string) {
247192
const searchInput = this.page.getByTestId('wui-input-text');
248193
await expect(searchInput, 'Search input should be visible').toBeVisible();
249194
await searchInput.click();
250195
await searchInput.fill(value);
251196
}
252197

253-
async openNetworks() {
254-
await this.page.getByTestId('w3m-account-select-network').click();
198+
async goToNetworks() {
199+
await this.page.getByTestId('button-network').click();
255200
await expect(this.page.getByText('Select network')).toBeVisible();
256201
}
257202

258-
// async openProfileView() {
259-
// await this.page.getByTestId('wui-profile-button').click();
260-
// }
261-
262-
// async getAddress(): Promise<`0x${string}`> {
263-
// const address = await this.page.getByTestId('w3m-address').textContent();
264-
// expect(address, 'Address should be present').toBeTruthy();
265-
266-
// return address as `0x${string}`;
267-
// }
203+
async goToActivity() {
204+
await this.page.getByTestId('button-activity').click();
205+
}
268206

269-
// async getChainId(): Promise<number> {
270-
// const chainId = await this.page.getByTestId('w3m-chain-id').textContent();
271-
// expect(chainId, 'Chain ID should be present').toBeTruthy();
207+
async goBack() {
208+
await this.page.getByTestId('button-back').click();
209+
}
272210

273-
// return Number(chainId);
274-
// }
211+
async expectLoaderVisible() {
212+
await expect(this.page.getByTestId('loading-spinner')).toBeVisible();
213+
}
275214

276-
// async switchNetworkWithHook() {
277-
// await this.page.getByTestId('switch-network-hook-button').click();
278-
// }
215+
async expectLoaderHidden() {
216+
await expect(this.page.getByTestId('loading-spinner')).toBeHidden();
217+
}
279218
}

apps/native/tests/shared/pages/WalletPage.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,23 @@ export class WalletPage {
117117
await this.page.waitForLoadState();
118118
const sessionsButton = this.page.getByTestId('sessions');
119119
await sessionsButton.click();
120-
const sessionCard = this.page.getByTestId(`session-card`);
121-
await sessionCard.click();
122-
const disconnectButton = this.page.getByText('Delete');
123-
await disconnectButton.click();
120+
121+
// Try to disconnect all visible session cards
122+
while (true) {
123+
const sessionCards = this.page.getByTestId('session-card');
124+
const count = await sessionCards.count();
125+
126+
if (count === 0) {
127+
break;
128+
}
129+
130+
// Click the first card and disconnect it
131+
await sessionCards.first().click();
132+
const disconnectButton = this.page.getByText('Delete');
133+
await disconnectButton.click();
134+
135+
// Wait a bit for the disconnection to complete
136+
await this.page.waitForTimeout(500);
137+
}
124138
}
125139
}

apps/native/tests/shared/validators/ModalValidator.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ export class ModalValidator {
8282
await expect(address, 'Correct address should be present').toHaveText(expectedAddress);
8383
}
8484

85-
// async expectNetwork(network: string) {
86-
// const networkButton = this.page.getByTestId('w3m-account-select-network');
87-
// await expect(networkButton, `Network button should contain text ${network}`).toHaveText(
88-
// network,
89-
// {
90-
// timeout: 5000
91-
// }
92-
// );
93-
// }
94-
9585
async expectAcceptedSign() {
9686
await expect(this.page.getByText('Signature successful')).toBeVisible({
9787
timeout: 30 * 1000
@@ -103,7 +93,7 @@ export class ModalValidator {
10393
}
10494

10595
async expectSwitchedNetwork(network: string) {
106-
const switchNetworkButton = this.page.getByTestId(`w3m-account-select-network-text`);
96+
const switchNetworkButton = this.page.getByTestId(`account-select-network-text`);
10797
await expect(switchNetworkButton).toContainText(network);
10898
}
10999

@@ -132,11 +122,6 @@ export class ModalValidator {
132122
await expect(getAWalletView).toBeVisible();
133123
}
134124

135-
// async expectHeaderText(text: string) {
136-
// const headerText = this.page.getByTestId('header-text');
137-
// await expect(headerText).toHaveText(text);
138-
// }
139-
140125
async expectNetworksDisabled(name: string) {
141126
const disabledNetworkButton = this.page.getByTestId(`w3m-network-switch-${name}`);
142127
disabledNetworkButton.click();

apps/native/tests/wallet.spec.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sampleWalletTest('it should be connected instantly after page refresh', async ()
4545
sampleWalletTest('it should show disabled networks', async () => {
4646
const disabledNetworks = 'Gnosis';
4747
await modalPage.openAccountModal();
48-
await modalPage.openNetworks();
48+
await modalPage.goToNetworks();
4949
await modalValidator.expectNetworksDisabled(disabledNetworks);
5050
await modalPage.closeModal();
5151
});
@@ -62,6 +62,8 @@ sampleWalletTest('it should switch networks and sign', async () => {
6262

6363
// -- Switch network --------------------------------------------------------
6464
const chainNameOnWalletPage = chainName;
65+
await modalPage.openAccountModal();
66+
await modalPage.goToNetworks();
6567
await modalPage.switchNetwork(chainName);
6668
await modalValidator.expectSwitchedNetwork(chainName);
6769
await modalPage.closeModal();
@@ -82,6 +84,8 @@ sampleWalletTest('it should switch networks and sign', async () => {
8284
sampleWalletTest('it should show last connected network after refreshing', async () => {
8385
const chainName = 'Polygon';
8486

87+
await modalPage.openAccountModal();
88+
await modalPage.goToNetworks();
8589
await modalPage.switchNetwork(chainName);
8690
await modalValidator.expectSwitchedNetwork(chainName);
8791
await modalPage.closeModal();
@@ -124,3 +128,46 @@ sampleWalletTest('it should disconnect as expected', async () => {
124128
await modalPage.disconnect();
125129
await modalValidator.expectDisconnected();
126130
});
131+
132+
sampleWalletTest('shows loader behavior on first visit to Activity screen', async () => {
133+
// Connect to wallet
134+
await modalPage.qrCodeFlow(modalPage, walletPage);
135+
await modalValidator.expectConnected();
136+
137+
// First visit to Activity screen
138+
await modalPage.openAccountModal();
139+
await modalPage.goToActivity();
140+
await modalPage.expectLoaderVisible();
141+
await modalPage.expectLoaderHidden();
142+
143+
// Second visit to Activity screen
144+
await modalPage.goBack();
145+
await modalPage.goToActivity();
146+
await modalPage.expectLoaderHidden();
147+
148+
// Third visit after closing the modal
149+
await modalPage.closeModal();
150+
await modalPage.openAccountModal();
151+
await modalPage.goToActivity();
152+
await modalPage.expectLoaderHidden();
153+
await modalPage.closeModal();
154+
});
155+
156+
sampleWalletTest('shows loader behavior after network change in Activity screen', async () => {
157+
await modalPage.openAccountModal();
158+
159+
// Change network
160+
await modalPage.goToNetworks();
161+
await modalPage.switchNetwork('Polygon');
162+
await modalValidator.expectSwitchedNetwork('Polygon');
163+
164+
// Visit Activity screen after network change
165+
await modalPage.goToActivity();
166+
await modalPage.expectLoaderVisible();
167+
await modalPage.expectLoaderHidden();
168+
169+
// Second visit after network change
170+
await modalPage.goBack();
171+
await modalPage.goToActivity();
172+
await modalPage.expectLoaderHidden();
173+
});

packages/scaffold/src/views/w3m-account-default-view/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ export function AccountDefaultView() {
244244
imageSrc={networkImage}
245245
imageHeaders={ApiController._getApiHeaders()}
246246
onPress={onNetworkPress}
247-
testID="w3m-account-select-network"
247+
testID="button-network"
248248
style={styles.actionButton}
249249
>
250-
<Text numberOfLines={1} color="fg-100" testID="w3m-account-select-network-text">
250+
<Text numberOfLines={1} color="fg-100" testID="account-select-network-text">
251251
{caipNetwork?.name}
252252
</Text>
253253
</ListItem>
@@ -259,7 +259,7 @@ export function AccountDefaultView() {
259259
iconColor="accent-100"
260260
iconBackgroundColor="accent-glass-015"
261261
onPress={onSwapPress}
262-
testID="button-activity"
262+
testID="button-swap"
263263
style={styles.actionButton}
264264
>
265265
<Text color="fg-100">Swap</Text>
@@ -299,7 +299,7 @@ export function AccountDefaultView() {
299299
onPress={onDisconnect}
300300
loading={disconnecting}
301301
iconBackgroundColor="gray-glass-010"
302-
testID="disconnect-button"
302+
testID="button-disconnect"
303303
>
304304
<Text color="fg-200">Disconnect</Text>
305305
</ListItem>

packages/ui/src/components/wui-loading-spinner/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ export interface LoadingSpinnerProps {
1212
size?: Exclude<SizeType, 'xs' | 'xxs'>;
1313
color?: Exclude<ColorType, 'error-100' | 'fg-300' | 'success-100'>;
1414
style?: StyleProp<ViewStyle>;
15+
testID?: string;
1516
}
1617

17-
export function LoadingSpinner({ color, style, size = 'lg' }: LoadingSpinnerProps) {
18+
export function LoadingSpinner({
19+
color,
20+
style,
21+
size = 'lg',
22+
testID = 'loading-spinner'
23+
}: LoadingSpinnerProps) {
1824
const Theme = useTheme();
1925
const spinValue = useRef(new Animated.Value(0));
2026
const stroke = color ? Theme[color] : Theme['accent-100'];
@@ -41,7 +47,7 @@ export function LoadingSpinner({ color, style, size = 'lg' }: LoadingSpinnerProp
4147
});
4248

4349
return (
44-
<View style={[styles.container, style]}>
50+
<View style={[styles.container, style]} testID={testID}>
4551
<AnimatedSvg
4652
width={SpinnerSize[size]}
4753
height={SpinnerSize[size]}

0 commit comments

Comments
 (0)