2023-05-08 14:47:19 +00:00
|
|
|
import { render, screen } from '@testing-library/react'
|
|
|
|
|
|
|
|
import AccountDetails from 'components/Account/AccountDetails'
|
2023-07-25 07:48:59 +00:00
|
|
|
import useCurrentAccount from 'hooks/useCurrentAccount'
|
|
|
|
import useStore from 'store'
|
2023-05-08 14:47:19 +00:00
|
|
|
|
2023-11-03 13:10:19 +00:00
|
|
|
jest.mock('react-router', () => ({
|
|
|
|
...(jest.requireActual('react-router') as {}),
|
|
|
|
useLocation: jest.fn().mockImplementation(() => {
|
|
|
|
return { pathname: '/testroute' }
|
|
|
|
}),
|
|
|
|
}))
|
2023-07-24 07:44:45 +00:00
|
|
|
jest.mock('hooks/useCurrentAccount', () => jest.fn(() => null))
|
2023-07-25 15:09:08 +00:00
|
|
|
jest.mock('hooks/useHealthComputer', () =>
|
|
|
|
jest.fn(() => ({
|
|
|
|
health: 0,
|
|
|
|
})),
|
|
|
|
)
|
2023-08-24 16:30:54 +00:00
|
|
|
// AccountBalancesTable component has wallet provider dependency, so we mock it
|
|
|
|
jest.mock('components/Account/AccountBalancesTable', () => jest.fn(() => null))
|
2023-05-08 14:47:19 +00:00
|
|
|
|
2023-07-24 07:44:45 +00:00
|
|
|
const mockedUseCurrentAccount = useCurrentAccount as jest.Mock
|
2023-10-30 11:47:52 +00:00
|
|
|
const mockedAccounts: Account[] = [
|
|
|
|
{ id: '1', deposits: [], lends: [], debts: [], vaults: [], kind: 'default' },
|
|
|
|
{ id: '2', deposits: [], lends: [], debts: [], vaults: [], kind: 'default' },
|
2023-10-13 11:49:38 +00:00
|
|
|
]
|
2023-09-25 18:17:43 +00:00
|
|
|
jest.mock('hooks/useAccountId', () => jest.fn(() => '1'))
|
2023-10-13 11:49:38 +00:00
|
|
|
jest.mock('hooks/useAccounts', () =>
|
|
|
|
jest.fn(() => ({
|
|
|
|
data: mockedAccounts,
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
jest.mock('hooks/useAccountIds', () =>
|
|
|
|
jest.fn(() => ({
|
|
|
|
data: ['1', '2'],
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
jest.mock('hooks/useCurrentAccount', () => jest.fn(() => mockedAccounts[0]))
|
2023-05-08 14:47:19 +00:00
|
|
|
|
2023-07-24 07:44:45 +00:00
|
|
|
describe('<AccountDetails />', () => {
|
2023-07-25 07:48:59 +00:00
|
|
|
beforeAll(() => {
|
|
|
|
useStore.setState({
|
|
|
|
address: 'walletAddress',
|
2023-10-13 11:49:38 +00:00
|
|
|
accounts: mockedAccounts,
|
2023-07-25 07:48:59 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
useStore.clearState()
|
|
|
|
})
|
|
|
|
|
2023-07-24 07:44:45 +00:00
|
|
|
it('renders account details WHEN account is selected', () => {
|
2023-10-13 11:49:38 +00:00
|
|
|
mockedUseCurrentAccount.mockReturnValue(mockedAccounts)
|
2023-05-08 14:47:19 +00:00
|
|
|
render(<AccountDetails />)
|
|
|
|
|
|
|
|
const container = screen.queryByTestId('account-details')
|
|
|
|
expect(container).toBeInTheDocument()
|
|
|
|
})
|
|
|
|
|
2023-07-24 07:44:45 +00:00
|
|
|
it('does not render WHEN account is NOT selected', () => {
|
|
|
|
mockedUseCurrentAccount.mockReturnValue(null)
|
2023-05-08 14:47:19 +00:00
|
|
|
render(<AccountDetails />)
|
|
|
|
|
|
|
|
const container = screen.queryByTestId('account-details')
|
|
|
|
expect(container).not.toBeInTheDocument()
|
|
|
|
})
|
2023-09-07 08:20:19 +00:00
|
|
|
})
|