Skip to content

Commit f769920

Browse files
committed
chore: add tests
1 parent 312b45a commit f769920

5 files changed

Lines changed: 241 additions & 1 deletion

File tree

packages/scaffold-ui/src/views/w3m-deposit-from-exchange-view/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import '@reown/appkit-ui/wui-text'
2121

2222
import styles from './styles.js'
2323

24-
const PRESET_AMOUNTS = [1, 10, 50, 100]
24+
const PRESET_AMOUNTS = [10, 50, 100]
2525

2626
@customElement('w3m-deposit-from-exchange-view')
2727
export class W3mDepositFromExchangeView extends LitElement {

packages/scaffold-ui/test/partials/w3m-account-default-widget.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,28 @@ describe('W3mAccountDefaultWidget', () => {
197197
expect(swapButton).not.toBeNull()
198198
expect(sendButton).toBeNull()
199199
})
200+
201+
it('should not show fund wallet if payWithExchange, onramp and receive are disabled', async () => {
202+
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
203+
...OptionsController.state,
204+
features: {
205+
swaps: true,
206+
receive: false
207+
},
208+
remoteFeatures: {
209+
payWithExchange: false,
210+
onramp: false
211+
}
212+
})
213+
214+
const element: W3mAccountDefaultWidget = await fixture(
215+
html`<w3m-account-default-widget></w3m-account-default-widget>`
216+
)
217+
218+
const fundWalletButton = HelpersUtil.getByTestId(element, FUND_WALLET_BUTTON_TEST_ID)
219+
220+
expect(fundWalletButton).toBeNull()
221+
})
200222
})
201223

202224
describe('solana wallet features', () => {
@@ -281,6 +303,28 @@ describe('W3mAccountDefaultWidget', () => {
281303
expect(swapButton).toBeNull()
282304
expect(sendButton).toBeNull()
283305
})
306+
307+
it('should not show fund wallet if payWithExchange, onramp and receive are disabled', async () => {
308+
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
309+
...OptionsController.state,
310+
features: {
311+
swaps: true,
312+
receive: false
313+
},
314+
remoteFeatures: {
315+
payWithExchange: false,
316+
onramp: false
317+
}
318+
})
319+
320+
const element: W3mAccountDefaultWidget = await fixture(
321+
html`<w3m-account-default-widget></w3m-account-default-widget>`
322+
)
323+
324+
const fundWalletButton = HelpersUtil.getByTestId(element, FUND_WALLET_BUTTON_TEST_ID)
325+
326+
expect(fundWalletButton).toBeNull()
327+
})
284328
})
285329

286330
describe('bitcoin wallet features', () => {

packages/scaffold-ui/test/partials/w3m-account-wallet-features-widget.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,31 @@ describe('wallet features visibility', () => {
294294
expect(HelpersUtil.getByTestId(element, 'wallet-features-swaps-button')).not.toBeNull()
295295
expect(HelpersUtil.getByTestId(element, 'wallet-features-send-button')).toBeNull()
296296
})
297+
298+
it('should not show fund wallet if payWithExchange, onramp and receive are disabled', async () => {
299+
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
300+
...OptionsController.state,
301+
features: {
302+
swaps: true,
303+
receive: false
304+
},
305+
remoteFeatures: {
306+
payWithExchange: false,
307+
onramp: false
308+
}
309+
})
310+
311+
const element: W3mAccountWalletFeaturesWidget = await fixture(
312+
html`<w3m-account-wallet-features-widget></w3m-account-wallet-features-widget>`
313+
)
314+
315+
const fundWalletButton = HelpersUtil.getByTestId(
316+
element,
317+
'wallet-features-fund-wallet-button'
318+
)
319+
320+
expect(fundWalletButton).toBeNull()
321+
})
297322
})
298323

299324
describe('solana wallet features', () => {
@@ -403,6 +428,31 @@ describe('wallet features visibility', () => {
403428
expect(HelpersUtil.getByTestId(element, 'wallet-features-swaps-button')).toBeNull()
404429
expect(HelpersUtil.getByTestId(element, 'wallet-features-send-button')).toBeNull()
405430
})
431+
432+
it('should not show fund wallet if payWithExchange, onramp and receive are disabled', async () => {
433+
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
434+
...OptionsController.state,
435+
features: {
436+
swaps: true,
437+
receive: false
438+
},
439+
remoteFeatures: {
440+
payWithExchange: false,
441+
onramp: false
442+
}
443+
})
444+
445+
const element: W3mAccountWalletFeaturesWidget = await fixture(
446+
html`<w3m-account-wallet-features-widget></w3m-account-wallet-features-widget>`
447+
)
448+
449+
const fundWalletButton = HelpersUtil.getByTestId(
450+
element,
451+
'wallet-features-fund-wallet-button'
452+
)
453+
454+
expect(fundWalletButton).toBeNull()
455+
})
406456
})
407457

408458
describe('bitcoin wallet features', () => {

packages/scaffold-ui/test/views/w3m-deposit-from-exchange-view.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,36 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
33

44
import { html } from 'lit'
55

6+
import type { CaipNetwork } from '@reown/appkit-common'
67
import { ChainController, ExchangeController } from '@reown/appkit-controllers'
78

89
import { W3mDepositFromExchangeView } from '../../src/views/w3m-deposit-from-exchange-view'
910
import { HelpersUtil } from '../utils/HelpersUtil'
1011

12+
const mockMainnet = {
13+
id: '1',
14+
name: 'Mainnet',
15+
chainNamespace: 'eip155',
16+
nativeCurrency: { symbol: 'ETH', name: 'Ethereum', decimals: 18 },
17+
rpcUrls: {
18+
default: {
19+
http: ['https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY']
20+
}
21+
}
22+
}
23+
24+
const mockSolanaMainnet = {
25+
id: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
26+
name: 'Solana Mainnet',
27+
chainNamespace: 'solana',
28+
nativeCurrency: { symbol: 'SOL', name: 'Solana', decimals: 9 },
29+
rpcUrls: {
30+
default: {
31+
http: ['https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY']
32+
}
33+
}
34+
}
35+
1136
describe('W3mDepositFromExchangeView', () => {
1237
beforeEach(() => {
1338
vi.restoreAllMocks()
@@ -17,6 +42,47 @@ describe('W3mDepositFromExchangeView', () => {
1742
vi.clearAllMocks()
1843
})
1944

45+
it('should set network native currency as payment asset', async () => {
46+
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({
47+
...ChainController.state,
48+
activeCaipNetwork: mockSolanaMainnet as unknown as CaipNetwork
49+
})
50+
51+
const setPaymentAssetSpy = vi.spyOn(ExchangeController, 'setPaymentAsset')
52+
53+
await fixture(html`<w3m-deposit-from-exchange-view></w3m-deposit-from-exchange-view>`)
54+
55+
expect(setPaymentAssetSpy).toHaveBeenCalledWith({
56+
network: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
57+
asset: 'native',
58+
metadata: {
59+
name: 'Solana',
60+
symbol: 'SOL',
61+
decimals: 9
62+
}
63+
})
64+
expect(setPaymentAssetSpy).toHaveBeenCalledTimes(1)
65+
66+
// Test mainnet
67+
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({
68+
...ChainController.state,
69+
activeCaipNetwork: mockMainnet as unknown as CaipNetwork
70+
})
71+
72+
await fixture(html`<w3m-deposit-from-exchange-view></w3m-deposit-from-exchange-view>`)
73+
74+
expect(setPaymentAssetSpy).toHaveBeenCalledWith({
75+
network: 'eip155:1',
76+
asset: 'native',
77+
metadata: {
78+
name: 'Ethereum',
79+
symbol: 'ETH',
80+
decimals: 18
81+
}
82+
})
83+
expect(setPaymentAssetSpy).toHaveBeenCalledTimes(2)
84+
})
85+
2086
it('renders exchanges and asset chip, and calls controller on interactions', async () => {
2187
// Mock active network symbol for the asset chip
2288
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({

packages/scaffold-ui/test/views/w3m-fund-wallet-view.test.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { ChainController, OptionsController, RouterController } from '@reown/app
99
import { W3mFundWalletView } from '../../src/views/w3m-fund-wallet-view'
1010
import { HelpersUtil } from '../utils/HelpersUtil'
1111

12+
// -- Constants ----------------------------------------- //
13+
const DEPOSIT_FROM_EXCHANGE_BUTTON_TEST_ID = 'wallet-features-deposit-from-exchange-button'
14+
1215
describe('W3mFundWalletView', () => {
1316
beforeEach(() => {
1417
vi.restoreAllMocks()
@@ -219,4 +222,81 @@ describe('W3mFundWalletView', () => {
219222
)
220223
expect(receiveFundsButton).toBeFalsy()
221224
})
225+
226+
it('should not show deposit from exchange option when payWithExchange is disabled', async () => {
227+
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({
228+
...ChainController.state,
229+
activeChain: CommonConstantsUtil.CHAIN.EVM
230+
})
231+
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
232+
...OptionsController.state,
233+
remoteFeatures: {
234+
payWithExchange: false
235+
}
236+
})
237+
238+
const element: W3mFundWalletView = await fixture(
239+
html`<w3m-fund-wallet-view></w3m-fund-wallet-view>`
240+
)
241+
242+
await elementUpdated(element)
243+
244+
const depositFromExchangeButton = HelpersUtil.getByTestId(
245+
element,
246+
DEPOSIT_FROM_EXCHANGE_BUTTON_TEST_ID
247+
)
248+
expect(depositFromExchangeButton).toBeFalsy()
249+
})
250+
251+
it('should show deposit from exchange option when payWithExchange is enabled', async () => {
252+
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({
253+
...ChainController.state,
254+
activeChain: CommonConstantsUtil.CHAIN.EVM
255+
})
256+
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
257+
...OptionsController.state,
258+
remoteFeatures: {
259+
payWithExchange: true
260+
}
261+
})
262+
263+
const element: W3mFundWalletView = await fixture(
264+
html`<w3m-fund-wallet-view></w3m-fund-wallet-view>`
265+
)
266+
267+
await elementUpdated(element)
268+
269+
const depositFromExchangeButton = HelpersUtil.getByTestId(
270+
element,
271+
DEPOSIT_FROM_EXCHANGE_BUTTON_TEST_ID
272+
)
273+
274+
expect(depositFromExchangeButton).toBeTruthy()
275+
})
276+
277+
it('should not show deposit from exchange option when payWithExchange if chain is not supported and payWithExchange is enabled', async () => {
278+
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({
279+
...ChainController.state,
280+
activeChain: CommonConstantsUtil.CHAIN.BITCOIN
281+
})
282+
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
283+
...OptionsController.state,
284+
remoteFeatures: {
285+
payWithExchange: true
286+
}
287+
})
288+
289+
const element: W3mFundWalletView = await fixture(
290+
html`<w3m-fund-wallet-view></w3m-fund-wallet-view>`
291+
)
292+
293+
await elementUpdated(element)
294+
295+
const depositFromExchangeButton = HelpersUtil.getByTestId(
296+
element,
297+
DEPOSIT_FROM_EXCHANGE_BUTTON_TEST_ID
298+
)
299+
300+
expect(depositFromExchangeButton).toBeNull()
301+
})
222302
})

0 commit comments

Comments
 (0)