-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
072c620
commit a9d9d37
Showing
5 changed files
with
134 additions
and
17 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
apps/mobile/src/features/Assets/components/NFTs/NFTs.container.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react' | ||
import { render, screen } from '@/src/tests/test-utils' | ||
import { NFTsContainer } from './NFTs.container' | ||
import { server } from '@/src/tests/server' | ||
import { http, HttpResponse } from 'msw' | ||
import { GATEWAY_URL } from '@/src/config/constants' | ||
|
||
// Mock active safe selector with memoized object | ||
const mockActiveSafe = { chainId: '1', address: '0x123' } | ||
|
||
jest.mock('@/src/store/activeSafeSlice', () => ({ | ||
selectActiveSafe: () => mockActiveSafe, | ||
})) | ||
|
||
describe('NFTsContainer', () => { | ||
afterAll(() => { | ||
server.resetHandlers() | ||
}) | ||
it('renders loading state initially', () => { | ||
render(<NFTsContainer />) | ||
expect(screen.getByTestId('fallback')).toBeTruthy() | ||
}) | ||
|
||
it('renders error state when API fails', async () => { | ||
server.use( | ||
http.get(`${GATEWAY_URL}//v2/chains/:chainId/safes/:safeAddress/collectibles`, () => { | ||
return HttpResponse.error() | ||
}), | ||
) | ||
|
||
render(<NFTsContainer />) | ||
expect(await screen.findByTestId('fallback')).toBeTruthy() | ||
}) | ||
|
||
it('renders NFT list when data is available', async () => { | ||
render(<NFTsContainer />) | ||
|
||
// First verify we see the loading state | ||
expect(screen.getByTestId('fallback')).toBeTruthy() | ||
|
||
// Then check for NFT content | ||
const nft1 = await screen.findByText('NFT #1') | ||
const nft2 = await screen.findByText('NFT #2') | ||
|
||
expect(nft1).toBeTruthy() | ||
expect(nft2).toBeTruthy() | ||
}) | ||
|
||
it('renders fallback when data is empty', async () => { | ||
server.use( | ||
http.get(`${GATEWAY_URL}//v2/chains/:chainId/safes/:safeAddress/collectibles`, () => { | ||
return HttpResponse.json({ results: [] }) | ||
}), | ||
) | ||
|
||
render(<NFTsContainer />) | ||
expect(await screen.findByTestId('fallback')).toBeTruthy() | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
apps/mobile/src/features/Assets/components/NoFunds/NoFunds.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react' | ||
import { render, screen } from '@/src/tests/test-utils' | ||
import { NoFunds } from './NoFunds' | ||
|
||
describe('NoFunds', () => { | ||
it('renders the empty token component', () => { | ||
render(<NoFunds />) | ||
|
||
// Check for the main elements | ||
expect(screen.getByText('Add funds to get started')).toBeTruthy() | ||
expect( | ||
screen.getByText('Send funds to your Safe Account from another wallet by copying your address.'), | ||
).toBeTruthy() | ||
}) | ||
|
||
it('renders the EmptyToken component', () => { | ||
render(<NoFunds />) | ||
|
||
// Check if EmptyToken is rendered by looking for its container | ||
expect(screen.getByTestId('empty-token')).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,12 @@ | ||
import { http, HttpResponse } from 'msw' | ||
|
||
export const mockBalanceData = { | ||
items: [ | ||
{ | ||
tokenInfo: { | ||
name: 'Ethereum', | ||
symbol: 'ETH', | ||
decimals: 18, | ||
logoUri: 'https://safe-transaction-assets.safe.global/chains/1/chain_logo.png', | ||
}, | ||
balance: '1000000000000000000', | ||
fiatBalance: '2000', | ||
}, | ||
], | ||
} | ||
import { mockBalanceData, mockNFTData } from './mocks' | ||
import { GATEWAY_URL } from '../config/constants' | ||
|
||
export const handlers = [ | ||
http.get('https://safe-client.safe.global//v1/chains/1/safes/0x123/balances/USD', () => { | ||
http.get(`${GATEWAY_URL}//v1/chains/1/safes/0x123/balances/USD`, () => { | ||
return HttpResponse.json(mockBalanceData) | ||
}), | ||
http.get(`${GATEWAY_URL}//v2/chains/:chainId/safes/:safeAddress/collectibles`, () => { | ||
return HttpResponse.json(mockNFTData) | ||
}), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters