1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00
commons/client/src/components/atoms/Account.test.tsx

62 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-04-30 19:19:28 +02:00
import React from 'react'
2019-07-15 16:14:55 +02:00
import { render, fireEvent } from '@testing-library/react'
2019-04-30 19:19:28 +02:00
import { toDataUrl } from 'ethereum-blockies'
import Account from './Account'
2019-07-12 00:24:29 +02:00
import { User } from '../../context'
import { userMockConnected } from '../../../__mocks__/user-mock'
2019-04-30 19:19:28 +02:00
describe('Account', () => {
it('renders without crashing', () => {
2019-07-12 00:24:29 +02:00
const { container } = render(
<User.Provider
value={{ ...userMockConnected, account: '0xxxxxxxxxxxxxxx' }}
>
<Account />
</User.Provider>
)
2019-04-30 19:19:28 +02:00
expect(container.firstChild).toBeInTheDocument()
})
it('outputs empty state without account', () => {
2019-07-15 16:14:55 +02:00
const { container, getByText } = render(
2019-07-12 00:24:29 +02:00
<User.Provider value={{ ...userMockConnected, account: '' }}>
<Account />
</User.Provider>
)
2019-04-30 19:19:28 +02:00
expect(container.firstChild).toHaveTextContent('No account selected')
2019-07-15 16:14:55 +02:00
fireEvent.click(getByText('Unlock Account'))
2019-04-30 19:19:28 +02:00
})
it('outputs blockie img', () => {
const account = '0xxxxxxxxxxxxxxx'
const blockies = toDataUrl(account)
2019-07-12 00:24:29 +02:00
const { container } = render(
<User.Provider value={{ ...userMockConnected, account }}>
<Account />
</User.Provider>
)
2019-04-30 19:19:28 +02:00
expect(container.querySelector('.blockies')).toBeInTheDocument()
expect(container.querySelector('.blockies')).toHaveAttribute(
'src',
blockies
)
})
2019-07-15 16:14:55 +02:00
it('Account info can be toggled', () => {
const { container, getByText } = render(
<User.Provider
value={{
...userMockConnected,
isBurner: true,
account: '0xxxxxxxxxxxxxxx'
}}
>
<Account />
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
fireEvent.click(getByText('Burner Wallet'))
})
2019-04-30 19:19:28 +02:00
})