Skip to content

Commit 4e2d442

Browse files
committed
test: fix tests that dont expect a connected wallet
1 parent 7be3451 commit 4e2d442

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

packages/curve-ui-kit/src/features/connect-wallet/lib/wagmi/useWagmiConfig.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Chain } from 'viem'
33
import { generatePrivateKey } from 'viem/accounts'
44
import { mapRecord, recordValues } from '@curvefi/prices-api/objects.util'
55
import type { NetworkMapping } from '@ui/utils'
6-
import { Chain as ChainEnum, isCypress } from '@ui-kit/utils'
6+
import { Chain as ChainEnum, isCypress, noCypressTestConnector } from '@ui-kit/utils'
77
import { createChainFromNetwork } from './chains'
88
import { defaultGetRpcUrls } from './rpc'
99
import { createTransportFromNetwork } from './transports'
@@ -22,13 +22,14 @@ export const useWagmiConfig = <T extends NetworkMapping>(networks: T | undefined
2222
return createWagmiConfig({
2323
chains,
2424
transports: mapRecord(networks, (_, network) => createTransportFromNetwork(network, defaultGetRpcUrls)),
25-
...(isCypress && {
26-
connectors: [
27-
createTestConnector({
28-
privateKey: generatePrivateKey(),
29-
chain: chains.find((chain) => chain.id === ChainEnum.Ethereum)!,
30-
})!,
31-
],
32-
}),
25+
...(isCypress &&
26+
!noCypressTestConnector && {
27+
connectors: [
28+
createTestConnector({
29+
privateKey: generatePrivateKey(),
30+
chain: chains.find((chain) => chain.id === ChainEnum.Ethereum)!,
31+
})!,
32+
],
33+
}),
3334
})
3435
}, [networks])

packages/curve-ui-kit/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum ReleaseChannel {
1818
}
1919

2020
export const isCypress = Boolean((window as { Cypress?: unknown }).Cypress)
21+
export const noCypressTestConnector = Boolean((window as { CypressNoTestConnector?: unknown }).CypressNoTestConnector)
2122

2223
const isDefaultBeta =
2324
process.env.NODE_ENV === 'development' ||

tests/cypress/e2e/all/header.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Header', () => {
2727
viewport = oneDesktopViewport()
2828
cy.viewport(...viewport)
2929
route = oneAppRoute()
30-
cy.visit(`/${route}`)
30+
cy.visitWithoutTestConnector(route)
3131
waitIsLoaded(route)
3232
})
3333

@@ -89,7 +89,7 @@ describe('Header', () => {
8989
viewport = oneMobileOrTabletViewport()
9090
cy.viewport(...viewport)
9191
route = oneAppRoute()
92-
cy.visit(`/${route}`)
92+
cy.visitWithoutTestConnector(route)
9393
waitIsLoaded(route)
9494
})
9595

tests/cypress/e2e/main/basic.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Basic Access Test', () => {
3737
})
3838

3939
it('should load for lite networks', () => {
40-
cy.visit('/dex/corn/pools')
40+
cy.visitWithoutTestConnector('dex/corn/pools')
4141
cy.title(LOAD_TIMEOUT).should('equal', 'Pools - Curve')
4242
cy.url().should('include', '/dex/corn/pools')
4343
cy.contains(/LBTC\/wBTCN/i, LOAD_TIMEOUT).should('be.visible')

tests/cypress/e2e/main/dex-markets.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { setShowSmallPools } from '@cy/support/helpers/user-profile'
44
import { API_LOAD_TIMEOUT, type Breakpoint, LOAD_TIMEOUT, oneViewport } from '@cy/support/ui'
55
import { SMALL_POOL_TVL } from '@ui-kit/features/user-profile/store'
66

7-
const PATH = '/dex/arbitrum/pools/'
7+
const PATH = 'dex/arbitrum/pools/'
88

99
// Parse compact USD strings like "$1.2M", "$950K", "$0", "-"
1010
function parseCompactUsd(value: string): number {
@@ -30,7 +30,7 @@ function visitAndWait(
3030
) {
3131
cy.viewport(width, height)
3232
const { query } = options ?? {}
33-
cy.visit(`${PATH}${query ? `?${new URLSearchParams(query)}` : ''}`, options)
33+
cy.visitWithoutTestConnector(`${PATH}${query ? `?${new URLSearchParams(query)}` : ''}`, options)
3434
cy.get('[data-testid^="data-table-row-"]', API_LOAD_TIMEOUT).should('have.length.greaterThan', 0)
3535
if (query?.['page']) {
3636
cy.get('[data-testid="table-pagination"]').should('be.visible')

tests/cypress/e2e/main/pool-page.cy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { oneFloat, oneOf } from '@cy/support/generators'
2+
import type { AppRoute } from '@cy/support/routes'
23
import { LOAD_TIMEOUT } from '@cy/support/ui'
34

45
describe('Pool page', () => {
5-
const path = `/dex/${oneOf(
6+
const path: AppRoute = `dex/${oneOf(
67
'ethereum/pools/factory-tricrypto-0',
78
'ethereum/pools/factory-stable-ng-561',
89
'arbitrum/pools/2pool',
910
'corn/pools/factory-stable-ng-0',
1011
)}/deposit`
1112

1213
it('should update slippage settings', () => {
13-
cy.visit(path)
14+
cy.visitWithoutTestConnector(path)
1415
cy.get('[data-testid="tab-deposit"]', LOAD_TIMEOUT).should('have.class', 'Mui-selected')
1516
cy.get('[data-testid="borrow-slippage-value"]').contains(path.includes('crypto') ? '0.10%' : '0.03%')
1617
cy.get('[data-testid="slippage-settings-button"]').click()

tests/cypress/e2e/main/swap.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('DEX Swap', () => {
55
const TO_ETH = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
66

77
it('shows quotes via router API when disconnected', () => {
8-
cy.visit(`/dex/ethereum/swap?from=${FROM_USDT}&to=${TO_ETH}`)
8+
cy.visitWithoutTestConnector(`dex/ethereum/swap?from=${FROM_USDT}&to=${TO_ETH}`)
99
cy.get('[data-testid="btn-connect-wallet"]', LOAD_TIMEOUT).should('be.enabled')
1010
cy.get(`[data-testid="token-icon-${FROM_USDT}"]`, LOAD_TIMEOUT).should('be.visible')
1111

tests/cypress/support/e2e.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
// This file is imported automatically before e2e tests run. Try to keep it empty if possible
1+
import type { AppRoute } from './routes'
2+
3+
declare global {
4+
interface Window {
5+
CypressNoTestConnector?: string
6+
}
7+
8+
// eslint-disable-next-line @typescript-eslint/no-namespace
9+
namespace Cypress {
10+
interface Chainable<Subject = any> {
11+
visitWithoutTestConnector(route: AppRoute, options?: Partial<Cypress.VisitOptions>): Chainable<AUTWindow>
12+
}
13+
}
14+
}
15+
16+
/**
17+
* For most of our e2e tests we have a wagmi test connect that auto-connects, so there's a wallet available.
18+
* However, in some cases we want to test functionality without a wallet connected.
19+
*/
20+
Cypress.Commands.add('visitWithoutTestConnector', (route: AppRoute, options?: Partial<Cypress.VisitOptions>) =>
21+
cy.visit(`/${route}`, {
22+
...options,
23+
onBeforeLoad(win) {
24+
win.CypressNoTestConnector = 'true'
25+
options?.onBeforeLoad?.(win)
26+
},
27+
}),
28+
)

0 commit comments

Comments
 (0)